Update app.py
Browse files3 unmodified lines456789101112131421 unmodified lines363738394041429 unmodified lines525354555657585960616263646566676869707172733 unmodified linesimport matplotlib.pyplot as pltimport openai# Load the solar data CSV filedf = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')# Set up the openai API key (replace with your actual OpenAI API key)openai.api_key = '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'# Streamlit UIst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")21 unmodified linesghi = state_data['Avg_GHI (kWh/m²/day)']solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']# Use LLM to generate solar project estimate (cost, savings, payback period)prompt = f"""Estimate the solar system for the location '{location}' based on the following details:Roof size: {roof_size} sq meters9 unmodified lines5. Payback period in years"""# Get response from OpenAI APIresponse = openai.Completion.create(engine="gpt-4", # You can change this to another GPT model if neededprompt=prompt,max_tokens=250,n=1,stop=None,temperature=0.7,)# Extract the resultresult = response.choices[0].text.strip()# Display the response from the modelst.subheader("Estimated Solar System Details:")st.write(result)else:st.error("Sorry, the location entered does not match any available data.")3 unmodified lines45678910111213141516171819202121 unmodified lines434445464748499 unmodified lines596061626364656667686970717273747576777879808182838485868788893 unmodified linesimport matplotlib.pyplot as pltimport openaiimport streamlit as stimport pandas as pdimport requests# Load the solar data CSV filedf = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')# Set up the Gemini API key (replace with your actual Gemini API key)GEMINI_API_KEY = 'AIzaSyAGGP8I7c0YmA8xKZsEdAF9AF3ElaPoEn4'# Set the API endpoint for GeminiGEMINI_API_URL = "https://gemini.googleapis.com/v1/completions" # Example URL, please check the actual URL# Streamlit UIst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")21 unmodified linesghi = state_data['Avg_GHI (kWh/m²/day)']solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']# Use Gemini API to generate solar project estimate (cost, savings, payback period)prompt = f"""Estimate the solar system for the location '{location}' based on the following details:Roof size: {roof_size} sq meters9 unmodified lines5. Payback period in years"""# Request to Gemini API (Adjust headers and body according to Gemini API documentation)response = requests.post(GEMINI_API_URL,headers={"Authorization": f"Bearer {GEMINI_API_KEY}","Content-Type": "application/json"},json={"model": "gemini-model-xyz", # Use the actual Gemini model name"prompt": prompt,"max_tokens": 250,"temperature": 0.7,"top_p": 1.0,"n": 1})# Check for successful responseif response.status_code == 200:result = response.json().get("choices", [])[0].get("text", "").strip()# Display the response from the Gemini modelst.subheader("Estimated Solar System Details:")st.write(result)else:st.error(f"Error: {response.status_code}. Unable to get response from Gemini API.")else:st.error("Sorry, the location entered does not match any available data.")
app.py+33-17