temperature / app.py
esssyjr's picture
Update app.py
ee1f54c verified
Raw
History Blame Contribute Delete
1.92 kB
import gradio as gr
from google import generativeai
import random
API_KEYS = [
"AIzaSyBvtwP2ulNHPQexfPhhR13U30pvF2OswrU",
"AIzaSyD0dLXPPrZmLbnHOj3f9twHmT_PZc15wMo",
]
api_key = random.choice(API_KEYS)
generativeai.configure(api_key=api_key)
# Initialize Gemini client
# Replace with your key
model = generativeai.GenerativeModel("gemini-2.0-flash")
def check_chicken_suitability(location):
prompt = f"Give me the average prdeicted temperature in Celsius for the next 7 days in {location}.Just make a prediction. Respond with only 7 comma-separated numbers."
try:
response = model.generate_content(prompt)
raw = response.text.strip()
# Extract temperatures
temps = [float(t.strip()) for t in raw.split(",") if t.strip().replace(".", "", 1).isdigit()]
if len(temps) != 7:
return f"❌ Couldn't get 7 temperatures. Gemini returned: {raw}"
avg_temp = sum(temps) / 7
result = f"📍 Location: {location}\n📊 Average Temperature of the next seven days: {avg_temp:.2f}°C\n"
if avg_temp > 30:
result += "\n⚠️ The average temperature expected to exeed 35 C over the next 7 days. It is NOT suitable to put young poultry chicks."
else:
result += "\n✅ The average temperature expected to NOT exeed 35 C over the next 7 days. It is suitable to put young chickens."
return result
except Exception as e:
return f"❌ Error occurred: {str(e)}"
# Gradio Interface
iface = gr.Interface(
fn=check_chicken_suitability,
inputs=gr.Textbox(label="Enter Location"),
outputs=gr.Textbox(label="Result"),
title="Chicken Suitability Checker 🌡️🐥",
description="Enter your location to check if the average temperature over the next 7 days is suitable for placing young chickens."
)
if __name__ == "__main__":
iface.launch()