Spaces:
Runtime error
Runtime error
ogegadavis254
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -105,44 +105,44 @@ if st.button("Generate Prediction and Analysis"):
|
|
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
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 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
# Display prediction
|
147 |
st.subheader("Climate Impact Analysis for Sports in Kenya")
|
148 |
st.markdown(initial_text.strip())
|
|
|
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())
|