Building a Carbon Footprint Tracker with Google Gemini for Earth Day
Source: Dev.to
Introduction
This is a submission for Weekend Challenge: Earth Day Edition.
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 with tools—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 CO₂e, 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.
The goal was simple: make environmental awareness feel personal, not preachy.
Walkthrough
- Log a day – e.g., “drove 12 km to work, had a chicken meal for lunch, used AC for 4 hours.”
- Gemini processes the inputs through structured prompts and returns a breakdown: transport contributed X kg, food Y kg, home energy Z kg.
- Chat interface – ask follow‑up questions like “what if I switched to public transport twice a week?” and Gemini calculates the hypothetical reduction on the fly.
- Weekly summary chart – shows your trend over time.
- Live demo: EcoTrace on GitHub Pages
- Source code: (link not provided in original)
Core 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.
Architecture
- Frontend: HTML, Tailwind CSS, Alpine.js for reactivity
- Backend: FastAPI (Python)
- AI Layer: Google Gemini 1.5 Flash
- Storage: Local JSON (simple for the weekend scope)
- Deployment: Google Cloud Run
How Gemini Powers the Experience
Instead of hard‑coding emission factors, I give Gemini a structured prompt with context about standard carbon‑accounting methodologies. Gemini reasons through the activity data, applies approximate emission coefficients, and explains its thinking in plain language. A follow‑up conversation loop lets users explore “what‑if” scenarios interactively.
A key design decision was to avoid showing just a number. Gemini’s response always includes a comparison (e.g., “this is roughly equivalent to charging your phone 800 times”) to make the abstraction tangible.
Challenges
- Verbosity: Gemini can produce overly long responses. I spent time refining system prompts to obtain concise, structured outputs that the frontend can reliably parse.
- Complexity of carbon accounting: Emission factors vary by country, season, and source. I opted for global averages and made the limitation transparent in the UI.
Best Use of Google Gemini
Google Gemini 3.0 Flash is at the core of EcoTrace. It powers:
- Carbon estimation logic
- Conversational follow‑up system
- Personalized weekly summaries
Without Gemini, the app would be a simple form that spits out a number. With Gemini, it becomes a conversational partner that helps users understand and improve their habits.