Spaces:
Sleeping
Sleeping
import streamlit as st | |
import google.generativeai as genai | |
import pandas as pd | |
import os | |
from dotenv import load_dotenv | |
from datetime import datetime | |
# Load environment variables | |
load_dotenv() | |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY')) | |
# Load weather data | |
future_precipitation_df = pd.read_csv('monthly_prcp.csv') | |
future_weather_df = pd.read_csv('punjab_temperature_2027.csv') | |
# Set up the Gemini model | |
model = genai.GenerativeModel('gemini-1.5-pro-latest') | |
chat = model.start_chat(history=[]) | |
# Title and description | |
st.title('Welcome to viGro! 👋🏻') | |
st.write("viGro is your weather assistant for your farm! Ask questions about future weather predictions for the next three years in Punjab, Pakistan. 🌤️") | |
# Text input for user question | |
question = st.text_input("Ask Here",value="What will weather be like in 3 months, will it rain? What will be the coldest temperature?") | |
# Button to submit the question | |
if st.button('Get Weather Forecast'): | |
# Get the current date | |
today_date = datetime.now().strftime("%d %B %Y") | |
# Convert DataFrames to string | |
precipitation_data_str = future_precipitation_df.to_string(index=False) | |
temperature_data_str = future_weather_df.to_string(index=False) | |
prompt = f"I'm a farmer. Today is {today_date}. Answer the following weather-related question of a farmers based on the provided weather data for Punjab, Pakistan:" | |
prompt += "Keep your response to the point and short. If asked about the future weather, only give temperature and precipitation info from the provided data for the desired time. if question is not related to weather from these data, kindly tell the farmer, Please ask a weather related quesiton." | |
prompt += "For example if, asked what will weather be like in 3 months, you should find the temperature info closest to the desired time from the data. Always find a time to give, never complain. You can calculate sums or mean values from the data if the question asks so like, how much rain will the year 2025 get. or will it rain 3 months from now. use precipitation data for it." | |
prompt += f"Question: {question}" | |
prompt += f"The 3 years future temperature data in months is:\{precipitation_data_str}" | |
prompt += f"The 3 years of future precipitation data in weeks:\{temperature_data_str}" | |
response = chat.send_message(prompt) | |
st.write(response.text) | |
st.image("https://images.nightcafe.studio/jobs/ckKcoiwT0lw1ifNtHnUX/ckKcoiwT0lw1ifNtHnUX--1--wqiwm.jpg?tr=w-1600,c-at_max") | |