MLDeveloper commited on
Commit
cf0cd4b
·
verified ·
1 Parent(s): 0c4f7e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -28
app.py CHANGED
@@ -10,7 +10,7 @@ from dotenv import load_dotenv
10
  # Load environment variables from .env file
11
  load_dotenv()
12
 
13
- # Set page configuration
14
  st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
15
 
16
  # Initialize Gemini with the API key loaded from the .env file
@@ -74,40 +74,22 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
74
  with st.spinner("Generating solar estimate with Gemini..."):
75
  response = model.generate_content(prompt_text)
76
 
77
- # Debug: Print the raw response to see the structure
78
- st.write("Raw Response:", response.text)
79
-
80
  # Display structured output with only the requested points
81
  st.subheader("Solar Project Estimate")
82
 
83
  # Break down the response into structured points
84
  estimated_data = response.text.strip().split("\n")
85
 
86
- # Initialize values for each field
87
- system_size = None
88
- total_cost = None
89
- monthly_savings = None
90
- payback_period = None
91
-
92
- # Parse the response to find and assign the correct values
93
  for point in estimated_data:
94
- if "solar system size" in point.lower():
95
- system_size = point.split(":")[1].strip()
96
- elif "total system cost" in point.lower():
97
- total_cost = point.split(":")[1].strip()
98
- elif "monthly savings" in point.lower():
99
- monthly_savings = point.split(":")[1].strip()
100
- elif "payback period" in point.lower():
101
- payback_period = point.split(":")[1].strip()
102
-
103
- # Ensure that we only display numeric values for the fields
104
- if system_size and total_cost and monthly_savings and payback_period:
105
- st.write(f"1. Estimated solar system size in kW: {system_size}")
106
- st.write(f"2. Total system cost in ₹: {total_cost}")
107
- st.write(f"3. Monthly savings in ₹: {monthly_savings}")
108
- st.write(f"4. Payback period in years: {payback_period}")
109
- else:
110
- st.error("Unable to extract valid data from the response.")
111
  else:
112
  st.error("Sorry, the location entered does not match any available data.")
113
  else:
 
10
  # Load environment variables from .env file
11
  load_dotenv()
12
 
13
+ # Set page configuration first
14
  st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
15
 
16
  # Initialize Gemini with the API key loaded from the .env file
 
74
  with st.spinner("Generating solar estimate with Gemini..."):
75
  response = model.generate_content(prompt_text)
76
 
 
 
 
77
  # Display structured output with only the requested points
78
  st.subheader("Solar Project Estimate")
79
 
80
  # Break down the response into structured points
81
  estimated_data = response.text.strip().split("\n")
82
 
83
+ # Display only the required points: system size, cost, savings, and payback period
 
 
 
 
 
 
84
  for point in estimated_data:
85
+ if ":" in point: # Only process lines with a colon
86
+ try:
87
+ # Extract the value after the colon
88
+ key, value = point.split(":")
89
+ st.write(f"{key.strip()}: {value.strip()}")
90
+ except IndexError:
91
+ # Handle cases where the split does not give two parts
92
+ st.warning("There was an issue processing the response.")
 
 
 
 
 
 
 
 
 
93
  else:
94
  st.error("Sorry, the location entered does not match any available data.")
95
  else: