Spaces:
Runtime error
Runtime error
ogegadavis254
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -77,7 +77,7 @@ precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=
|
|
77 |
atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
|
78 |
|
79 |
# Kenya-specific inputs
|
80 |
-
region = st.
|
81 |
elevation = st.number_input("Elevation (m):", min_value=0, max_value=5000, value=1000)
|
82 |
|
83 |
# Sports and athlete inputs
|
@@ -102,30 +102,47 @@ if st.button("Generate Prediction and Analysis"):
|
|
102 |
f"Assess the socio-economic implications of these climate impacts on sports in Kenya, including equitable access to sports facilities. "
|
103 |
f"Organize the information in tables with the following columns: Climate Conditions, Impact on Sports Performance, "
|
104 |
f"Impact on Athletes' Health, Impact on Infrastructure, Mitigation Strategies, Socio-Economic Implications. "
|
105 |
-
f"Be as accurate and specific to Kenya as possible in your analysis."
|
106 |
)
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
|
|
129 |
# Display prediction
|
130 |
st.subheader("Climate Impact Analysis for Sports in Kenya")
|
131 |
st.markdown(initial_text.strip())
|
@@ -193,7 +210,7 @@ if st.button("Generate Prediction and Analysis"):
|
|
193 |
f"Based on the climate conditions and sports analysis for {region}, Kenya, "
|
194 |
f"provide a brief assessment of the socio-economic implications, including impacts on: "
|
195 |
f"1) Local economy, 2) Community health, 3) Sports tourism, 4) Equitable access to sports facilities. "
|
196 |
-
f"Consider the specific context of Kenya and the selected region."
|
197 |
)
|
198 |
|
199 |
with st.spinner("Analyzing socio-economic impacts..."):
|
@@ -222,7 +239,7 @@ if st.button("Generate Prediction and Analysis"):
|
|
222 |
f"suggest specific mitigation strategies for: "
|
223 |
f"1) Improving athlete performance and health, 2) Enhancing infrastructure resilience, "
|
224 |
f"3) Ensuring equitable access to sports facilities. "
|
225 |
-
f"Consider the specific context of Kenya and the selected region."
|
226 |
)
|
227 |
|
228 |
with st.spinner("Generating mitigation strategies..."):
|
|
|
77 |
atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
|
78 |
|
79 |
# Kenya-specific inputs
|
80 |
+
region = st.text_input("Enter region in Kenya:")
|
81 |
elevation = st.number_input("Elevation (m):", min_value=0, max_value=5000, value=1000)
|
82 |
|
83 |
# Sports and athlete inputs
|
|
|
102 |
f"Assess the socio-economic implications of these climate impacts on sports in Kenya, including equitable access to sports facilities. "
|
103 |
f"Organize the information in tables with the following columns: Climate Conditions, Impact on Sports Performance, "
|
104 |
f"Impact on Athletes' Health, Impact on Infrastructure, Mitigation Strategies, Socio-Economic Implications. "
|
105 |
+
f"Be as accurate and specific to Kenya as possible in your analysis. And please do not generate long texts, make it as short and precise as possible, i am stressing on this please, generate something short."
|
106 |
)
|
107 |
|
108 |
+
try:
|
109 |
+
stages = [
|
110 |
+
"Analyzing climate conditions...",
|
111 |
+
"Checking location data...",
|
112 |
+
"Fetching historical data...",
|
113 |
+
"Running simulations...",
|
114 |
+
"Processing current weather...",
|
115 |
+
"Assessing environmental factors...",
|
116 |
+
"Calculating predictions...",
|
117 |
+
"Compiling results...",
|
118 |
+
"Finalizing analysis...",
|
119 |
+
"Preparing output..."
|
120 |
+
]
|
121 |
+
|
122 |
+
with st.spinner("Analyzing climate conditions and generating predictions..."):
|
123 |
+
# Loop through each stage, updating the spinner text and waiting for 2 seconds
|
124 |
+
for stage in stages:
|
125 |
+
st.spinner(stage)
|
126 |
+
time.sleep(2)
|
127 |
+
|
128 |
+
initial_response = call_ai_model_initial(all_message)
|
129 |
|
130 |
+
initial_text = ""
|
131 |
+
for line in initial_response.iter_lines():
|
132 |
+
if line:
|
133 |
+
line_content = line.decode('utf-8')
|
134 |
+
if line_content.startswith("data: "):
|
135 |
+
line_content = line_content[6:] # Strip "data: " prefix
|
136 |
+
try:
|
137 |
+
json_data = json.loads(line_content)
|
138 |
+
if "choices" in json_data:
|
139 |
+
delta = json_data["choices"][0]["delta"]
|
140 |
+
if "content" in delta:
|
141 |
+
initial_text += delta["content"]
|
142 |
+
except json.JSONDecodeError:
|
143 |
+
continue
|
144 |
|
145 |
+
st.success("Analysis completed!")
|
146 |
# Display prediction
|
147 |
st.subheader("Climate Impact Analysis for Sports in Kenya")
|
148 |
st.markdown(initial_text.strip())
|
|
|
210 |
f"Based on the climate conditions and sports analysis for {region}, Kenya, "
|
211 |
f"provide a brief assessment of the socio-economic implications, including impacts on: "
|
212 |
f"1) Local economy, 2) Community health, 3) Sports tourism, 4) Equitable access to sports facilities. "
|
213 |
+
f"Consider the specific context of Kenya and the selected region. and make the response very precise and short, do not yap"
|
214 |
)
|
215 |
|
216 |
with st.spinner("Analyzing socio-economic impacts..."):
|
|
|
239 |
f"suggest specific mitigation strategies for: "
|
240 |
f"1) Improving athlete performance and health, 2) Enhancing infrastructure resilience, "
|
241 |
f"3) Ensuring equitable access to sports facilities. "
|
242 |
+
f"Consider the specific context of Kenya and the selected region. And make the response very precise and short, do not yap"
|
243 |
)
|
244 |
|
245 |
with st.spinner("Generating mitigation strategies..."):
|