Update app.py
Browse files3 unmodified lines456789101112131011141516171819202121 unmodified lines43444539464748499 unmodified lines5960615556575859606162626364656667686970717273747576777865666768697079808182838485868788893 unmodified linesimport matplotlib.pyplot as pltimport openai
import 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 openai API key (replace with your actual OpenAI API key)openai.api_key = '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'# 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 lines ghi = 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) # 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 lines 5. Payback period in years """
# Get response from OpenAI API response = openai.Completion.create( engine="gpt-4", # You can change this to another GPT model if needed prompt=prompt, max_tokens=250, n=1, stop=None, temperature=0.7, # 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 } ) # Extract the result result = response.choices[0].text.strip() # Display the response from the model st.subheader("Estimated Solar System Details:") st.write(result) # Check for successful response if response.status_code == 200: result = response.json().get("choices", [])[0].get("text", "").strip() # Display the response from the Gemini model st.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