DEV Community

Codes Me
Codes Me

Posted on

Join the Gemma 4 Challenge: Build a Heatwave Alert Bot with Gemma 4 — $3,000 Prize Pool for TEN Winners!

Gemma 4 Challenge: Write about Gemma 4 Submission

Introduction

It's getting hot out there — literally. With heatwaves hitting record temperatures across the globe, I thought: why not build something useful with Gemma 4? This is my submission concept for the Gemma 4 Challenge: a heatwave alert system that uses the OpenWeatherMap API to fetch real-time temperatures and Gemma 4 to generate natural-language heat safety advice — then emails it to you automatically.

The Problem

Most weather apps just show you numbers. But what if you could get a personalized, AI-generated safety message when temperatures go dangerously high? And what if it ran silently in the background, checking every hour and alerting you only when needed? That's exactly what we're building today — and it's a great showcase for Gemma 4's text generation power in a real-world automation context.

The Solution

Here's the plan:

  1. Fetch real-time temperature data from OpenWeatherMap API
  2. If temp exceeds a threshold (e.g. 38°C), call Gemma 4 via the Google AI SDK to generate a heat safety message
  3. Send the message by email using Python's built-in smtplib

This runs on a scheduler (APScheduler) so it checks automatically every hour. Clean, practical, and genuinely useful during summer.

import requests
import smtplib
import schedule
import time
from email.mime.text import MIMEText
from google import genai

# --- CONFIG ---
OWM_API_KEY = "your_openweathermap_api_key"
CITY = "Paris"
HEAT_THRESHOLD = 38  # Celsius
GEMINI_API_KEY = "your_google_ai_api_key"
EMAIL_SENDER = "your_email@gmail.com"
EMAIL_PASSWORD = "your_app_password"
EMAIL_RECEIVER = "recipient@example.com"

# --- FETCH TEMPERATURE ---
def get_temperature(city: str) -> float:
    url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={OWM_API_KEY}&units=metric"
    response = requests.get(url)
    response.raise_for_status()
    data = response.json()
    temp = data["main"]["temp"]
    print(f"[Weather] {city}: {temp}°C")
    return temp

# --- GENERATE SAFETY ADVICE WITH GEMMA 4 ---
def generate_heat_advice(city: str
Enter fullscreen mode Exit fullscreen mode

Result

When the temperature in your chosen city crosses 38°C, you get an email like this:

🔴 Heatwave Alert in Paris — 41.2°C

⚠️ HEATWAVE ALERT ⚠️

Current temperature in Paris: 41.2°C

--- AI Safety Advice (powered by Gemma 4) ---
It's dangerously hot outside today! Make sure to drink at least 2 liters of water
throughout the day, avoid direct sun between 11am and 4pm, and wear light-colored,
loose clothing. Don't forget to check on elderly neighbors or family members who may
need help staying cool. Your health comes first! 💧

Stay safe,
Your Weather Bot 🤖
Enter fullscreen mode Exit fullscreen mode

The bot runs silently in the background, checks every hour, and only fires when it truly matters. Gemma 4 adds real value here — the advice isn't generic, it's contextual and readable.


This is just the starting point. You could extend this to:

  • Monitor multiple cities at once
  • Add SMS alerts via Twilio
  • Store temperature history in a SQLite database
  • Deploy it on a Raspberry Pi or a free cloud VM

If you're entering the Gemma 4 Challenge, this project shows real-world utility, clean Python automation, and meaningful AI integration — exactly what the judges are looking for.

👉 Want more Python automation projects like this? Check out codes-me.com — I post tutorials, scripts, and challenges every week.

Drop your questions or ideas in the comments — I read everything! 🔥


Enjoyed this article? Feel free to check out my profile for more Python tutorials, automation tips, and open-source projects.

Top comments (0)