Building a Carbon Footprint Tracker with Google Gemini for Earth Day

This is a submission for Weekend Challenge: Earth Day Edition

What I Built

Every time I opened a news tab this week, there was another story about rising temperatures, melting glaciers, or record-breaking carbon emissions. It hit me differently this Earth Day. I am a developer. I have tools. What if I actually did something about it, even if it was small?

So I built EcoTrace — a personal carbon footprint tracker powered by Google Gemini.

EcoTrace is a web app where you log your daily activities (commute, meals, flights, electricity usage) and Gemini does the heavy lifting. It analyzes your patterns, estimates your carbon output in kg CO2e, and gives you a personalized, conversational breakdown of where you stand and what you could change. No spreadsheets, no vague scores — just a friendly AI that talks to you about your impact like a knowledgeable friend would.

The goal was simple: make environmental awareness feel personal, not preachy.

EcoTrace app workflow

Demo

Here is a quick walkthrough of EcoTrace in action:

  1. You open the app and log a typical Tuesday — drove 12 km to work, had a chicken meal for lunch, used AC for 4 hours.
  2. Gemini processes the inputs through structured prompts and returns a breakdown: transport contributed X kg, food Y kg, home energy Z kg.
  3. The chat interface lets you ask follow-up questions like “what if I switched to public transport twice a week” and Gemini calculates the hypothetical reduction on the fly.
  4. A weekly summary chart shows your trend over time.

You can view the live demo here: EcoTrace on GitHub Pages

Code

The full source code is available at: github.com/ecotrace-gemini/ecotrace

Here is a core snippet showing how I structured the Gemini API call:

import google.generativeai as genai

genai.configure(api_key=API_KEY)
model = genai.GenerativeModel('gemini-3.0-flash')

def estimate_footprint(activity_log: dict) -> str:
    prompt = f"""
    You are a climate-aware assistant. Based on the following daily activities,
    calculate the estimated carbon footprint in kg CO2e and provide a brief,
    friendly explanation for each category.

    Activities:
    - Transport: {activity_log['transport']}
    - Diet: {activity_log['diet']}
    - Home Energy: {activity_log['energy']}

    Return a structured breakdown and one actionable tip to reduce emissions.
    """
    response = model.generate_content(prompt)
    return response.text

The frontend is plain HTML + vanilla JS, keeping things accessible and fast.

How I Built It

The weekend started with a question: how do you make someone care about a number like “8.2 kg CO2e” when it means nothing to them emotionally?

The answer I landed on was conversation.

Instead of showing a static dashboard, I wanted users to talk to their data. That is where Google Gemini became the backbone of the project. I used the Gemini 1.5 Flash model via the Python SDK, wrapped in a FastAPI backend.

Architecture:

  • Frontend: HTML, Tailwind CSS, Alpine.js for reactivity
  • Backend: FastAPI (Python)
  • AI Layer: Google Gemini 1.5 Flash
  • Storage: Local JSON (kept it simple for the weekend scope)
  • Deployment: Google Cloud Run

How Gemini powers the experience:

Rather than hardcoding emission factors, I gave Gemini a structured prompt with context about standard carbon accounting methodologies. It reasons through the activity data, applies approximate emission coefficients, and explains its thinking in plain language. I added a follow-up conversation loop so users can explore “what if” scenarios interactively.

One interesting decision: I deliberately avoided showing just a number. Gemini’s response always includes a comparison (“this is roughly equivalent to charging your phone 800 times”) to make the abstraction tangible.

Challenges along the way:

Gemini’s responses can be verbose when you want something concise. I spent a good chunk of time refining system prompts to get consistent, structured outputs that the frontend could parse reliably.

Also, carbon accounting is genuinely complex. Emission factors vary by country, season, and source. I made the decision to use global averages and be transparent about that limitation right in the UI.

Earth climate visualization

Prize Categories

Best Use of Google Gemini

Google Gemini 3.0 Flash is at the core of EcoTrace. It powers the carbon estimation logic, the conversational follow-up system, and the personalized weekly summaries.

Without Gemini, the app would just be a form that spits out a number. With it, it becomes something you can actually have a conversation with about your habits and what you might want to change.

Leave a Reply