Update app.py
Browse files
app.py
CHANGED
@@ -7,36 +7,9 @@ import openai
|
|
7 |
# Load the solar data CSV file
|
8 |
df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
|
9 |
|
10 |
-
# Set up the
|
11 |
openai.api_key = 'your_openai.api_key_here'
|
12 |
|
13 |
-
# Function to get solar radiation and tariff based on user input location
|
14 |
-
def get_state_data(state_name):
|
15 |
-
state_data = df[df['State'].str.contains(state_name, case=False)]
|
16 |
-
if state_data.empty:
|
17 |
-
return None
|
18 |
-
return state_data.iloc[0]
|
19 |
-
|
20 |
-
# Function to estimate solar system size (in kW)
|
21 |
-
def estimate_system_size(roof_size, ghi):
|
22 |
-
# Simple formula: 1 kW system needs about 10-12 sq meters of roof space
|
23 |
-
system_size = roof_size / 10 # in kW (assuming 10 sq meters = 1 kW)
|
24 |
-
estimated_output = ghi * system_size # kWh per day
|
25 |
-
return system_size, estimated_output
|
26 |
-
|
27 |
-
# Function to calculate cost, savings, and payback period
|
28 |
-
def estimate_cost_and_savings(system_size, state_data, electricity_bill):
|
29 |
-
# Cost per kW (₹)
|
30 |
-
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
|
31 |
-
# Total solar system cost
|
32 |
-
system_cost = system_size * solar_cost_per_kw
|
33 |
-
# Savings per month assuming 100% replacement of electricity bill
|
34 |
-
savings_per_month = electricity_bill
|
35 |
-
# Payback period in months
|
36 |
-
payback_period = system_cost / (savings_per_month * 12)
|
37 |
-
|
38 |
-
return system_cost, savings_per_month, payback_period
|
39 |
-
|
40 |
# Streamlit UI
|
41 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
42 |
st.title("AI-based Solar Project Estimation Tool")
|
@@ -57,35 +30,46 @@ with st.form("solar_form"):
|
|
57 |
|
58 |
if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
59 |
# Fetch state data from the dataset
|
60 |
-
state_data =
|
|
|
61 |
if state_data is not None:
|
62 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
|
|
63 |
|
64 |
-
#
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
st.write(f"**Location**: {location}")
|
73 |
-
st.write(f"**System Size**: {system_size:.2f} kW")
|
74 |
-
st.write(f"**Estimated Daily Output**: {estimated_output:.2f} kWh/day")
|
75 |
-
st.write(f"**Total System Cost**: ₹{system_cost:,.2f}")
|
76 |
-
st.write(f"**Monthly Savings**: ₹{savings_per_month:,.2f}")
|
77 |
-
st.write(f"**Payback Period**: {payback_period:.2f} years")
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
|
82 |
-
[system_cost, savings_per_month, payback_period*12], color=['blue', 'green', 'orange'])
|
83 |
-
ax.set_ylabel("Amount (₹) / Time (Months)")
|
84 |
-
ax.set_title("Solar System Estimation Breakdown")
|
85 |
-
st.pyplot(fig)
|
86 |
|
87 |
else:
|
88 |
st.error("Sorry, the location entered does not match any available data.")
|
89 |
else:
|
90 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
91 |
-
|
|
|
7 |
# Load the solar data CSV file
|
8 |
df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
|
9 |
|
10 |
+
# Set up the openai API key (replace with your actual OpenAI API key)
|
11 |
openai.api_key = 'your_openai.api_key_here'
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Streamlit UI
|
14 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
15 |
st.title("AI-based Solar Project Estimation Tool")
|
|
|
30 |
|
31 |
if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
32 |
# Fetch state data from the dataset
|
33 |
+
state_data = df[df['State'].str.contains(location, case=False)].iloc[0] # Get the first match
|
34 |
+
|
35 |
if state_data is not None:
|
36 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
37 |
+
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
|
38 |
|
39 |
+
# Use LLM to generate solar project estimate (cost, savings, payback period)
|
40 |
+
prompt = f"""
|
41 |
+
Estimate the solar system for the location '{location}' based on the following details:
|
42 |
+
Roof size: {roof_size} sq meters
|
43 |
+
Monthly electricity bill: ₹{electricity_bill}
|
44 |
+
Average GHI (solar radiation) for {location}: {ghi} kWh/m²/day
|
45 |
+
Solar system cost per kW in {location}: ₹{solar_cost_per_kw}
|
46 |
|
47 |
+
Provide:
|
48 |
+
1. Estimated solar system size in kW
|
49 |
+
2. Estimated daily solar output in kWh
|
50 |
+
3. Total system cost in ₹
|
51 |
+
4. Monthly savings in ₹
|
52 |
+
5. Payback period in years
|
53 |
+
"""
|
54 |
+
|
55 |
+
# Get response from OpenAI API
|
56 |
+
response = openai.Completion.create(
|
57 |
+
engine="gpt-4", # You can change this to another GPT model if needed
|
58 |
+
prompt=prompt,
|
59 |
+
max_tokens=250,
|
60 |
+
n=1,
|
61 |
+
stop=None,
|
62 |
+
temperature=0.7,
|
63 |
+
)
|
64 |
|
65 |
+
# Extract the result
|
66 |
+
result = response.choices[0].text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
# Display the response from the model
|
69 |
+
st.subheader("Estimated Solar System Details:")
|
70 |
+
st.write(result)
|
|
|
|
|
|
|
|
|
71 |
|
72 |
else:
|
73 |
st.error("Sorry, the location entered does not match any available data.")
|
74 |
else:
|
75 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
|