Update app.py
Browse files6 unmodified lines78910111213141516171819202122232425262728293031323334353637383940414214 unmodified lines57585960616263646566676869707172737475767778798081828384858687888990916 unmodified lines# 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 (replace with your actual API key)openai.api_key = 'your_openai.api_key_here'# Function to get solar radiation and tariff based on user input locationdef get_state_data(state_name):state_data = df[df['State'].str.contains(state_name, case=False)]if state_data.empty:return Nonereturn state_data.iloc[0]# Function to estimate solar system size (in kW)def estimate_system_size(roof_size, ghi):# Simple formula: 1 kW system needs about 10-12 sq meters of roof spacesystem_size = roof_size / 10 # in kW (assuming 10 sq meters = 1 kW)estimated_output = ghi * system_size # kWh per dayreturn system_size, estimated_output# Function to calculate cost, savings, and payback perioddef estimate_cost_and_savings(system_size, state_data, electricity_bill):# Cost per kW (₹)solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']# Total solar system costsystem_cost = system_size * solar_cost_per_kw# Savings per month assuming 100% replacement of electricity billsavings_per_month = electricity_bill# Payback period in monthspayback_period = system_cost / (savings_per_month * 12)return system_cost, savings_per_month, payback_period# Streamlit UIst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")st.title("AI-based Solar Project Estimation Tool")14 unmodified linesif submitted and location and roof_size > 0 and electricity_bill >= 0:# Fetch state data from the datasetstate_data = get_state_data(location)if state_data is not None:ghi = state_data['Avg_GHI (kWh/m²/day)']# Estimate solar system size and outputsystem_size, estimated_output = estimate_system_size(roof_size, ghi)# Estimate cost, savings, and payback periodsystem_cost, savings_per_month, payback_period = estimate_cost_and_savings(system_size, state_data, electricity_bill)# Display resultsst.subheader("Estimated Solar System Details:")st.write(f"**Location**: {location}")st.write(f"**System Size**: {system_size:.2f} kW")st.write(f"**Estimated Daily Output**: {estimated_output:.2f} kWh/day")st.write(f"**Total System Cost**: ₹{system_cost:,.2f}")st.write(f"**Monthly Savings**: ₹{savings_per_month:,.2f}")st.write(f"**Payback Period**: {payback_period:.2f} years")# Plot savings and payback periodfig, ax = plt.subplots()ax.bar(['Total System Cost', 'Monthly Savings', 'Payback Period (months)'],[system_cost, savings_per_month, payback_period*12], color=['blue', 'green', 'orange'])ax.set_ylabel("Amount (₹) / Time (Months)")ax.set_title("Solar System Estimation Breakdown")st.pyplot(fig)else:st.error("Sorry, the location entered does not match any available data.")else:st.warning("Please fill out all fields to see your solar project estimate.")6 unmodified lines78910111213141514 unmodified lines303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374756 unmodified lines# 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 = 'your_openai.api_key_here'# Streamlit UIst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")st.title("AI-based Solar Project Estimation Tool")14 unmodified linesif submitted and location and roof_size > 0 and electricity_bill >= 0:# Fetch state data from the datasetstate_data = df[df['State'].str.contains(location, case=False)].iloc[0] # Get the first matchif state_data is not None: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)prompt = f"""Estimate the solar system for the location '{location}' based on the following details:Roof size: {roof_size} sq metersMonthly electricity bill: ₹{electricity_bill}Average GHI (solar radiation) for {location}: {ghi} kWh/m²/daySolar system cost per kW in {location}: ₹{solar_cost_per_kw}Provide:1. Estimated solar system size in kW2. Estimated daily solar output in kWh3. Total system cost in ₹4. Monthly savings in ₹5. 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.")else:st.warning("Please fill out all fields to see your solar project estimate.")
app.py+33-49