Spaces:
Runtime error
Runtime error
ogegadavis254
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import os
|
4 |
import json
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
# Function to call the Together AI model for the initial analysis
|
8 |
def call_ai_model_initial(all_message):
|
@@ -75,17 +76,23 @@ air_quality_index = st.number_input("Air Quality Index:", min_value=0, max_value
|
|
75 |
precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
|
76 |
atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
|
77 |
|
78 |
-
#
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
81 |
|
82 |
if st.button("Generate Prediction"):
|
83 |
all_message = (
|
84 |
-
f"Assess the impact on sports performance and infrastructure based on climate conditions: "
|
85 |
f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
|
86 |
f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
|
87 |
-
f"
|
88 |
-
f"
|
|
|
|
|
|
|
89 |
)
|
90 |
|
91 |
try:
|
@@ -111,8 +118,9 @@ if st.button("Generate Prediction"):
|
|
111 |
|
112 |
with st.spinner("Generating predictions..."):
|
113 |
analysis_text = (
|
114 |
-
f"
|
115 |
-
f"
|
|
|
116 |
)
|
117 |
analysis_response = call_ai_model_analysis(analysis_text)
|
118 |
|
@@ -133,12 +141,14 @@ if st.button("Generate Prediction"):
|
|
133 |
|
134 |
st.success("Predictions generated!")
|
135 |
|
136 |
-
# Extract performance
|
137 |
performance_score = "N/A"
|
|
|
138 |
for line in analysis_result.split('\n'):
|
139 |
-
if "performance
|
140 |
performance_score = line.split(":")[-1].strip()
|
141 |
-
|
|
|
142 |
|
143 |
# Prepare data for visualization
|
144 |
results_data = {
|
@@ -148,19 +158,53 @@ if st.button("Generate Prediction"):
|
|
148 |
results_df = pd.DataFrame(results_data)
|
149 |
|
150 |
# Display results in a table
|
151 |
-
st.subheader("
|
152 |
st.table(results_df)
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
# Display prediction
|
155 |
-
st.
|
156 |
st.markdown(initial_text.strip())
|
157 |
|
158 |
-
# Display performance
|
159 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
# Display raw analysis result for debugging
|
162 |
-
st.
|
163 |
-
|
164 |
|
165 |
except ValueError as ve:
|
166 |
st.error(f"Configuration error: {ve}")
|
|
|
3 |
import os
|
4 |
import json
|
5 |
import pandas as pd
|
6 |
+
import plotly.graph_objects as go
|
7 |
|
8 |
# Function to call the Together AI model for the initial analysis
|
9 |
def call_ai_model_initial(all_message):
|
|
|
76 |
precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
|
77 |
atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
|
78 |
|
79 |
+
# Sports and athlete inputs
|
80 |
+
sports = st.multiselect("Select sports:", ["Football", "Tennis", "Athletics", "Swimming", "Basketball", "Golf"])
|
81 |
+
athlete_types = st.multiselect("Select athlete types:", ["Professional", "Amateur", "Youth", "Senior"])
|
82 |
+
|
83 |
+
# Infrastructure inputs
|
84 |
+
infrastructure_types = st.multiselect("Select infrastructure types:", ["Outdoor Stadium", "Indoor Arena", "Swimming Pool", "Tennis Court", "Golf Course"])
|
85 |
|
86 |
if st.button("Generate Prediction"):
|
87 |
all_message = (
|
88 |
+
f"Assess the impact on sports performance, athletes, and infrastructure based on climate conditions: "
|
89 |
f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
|
90 |
f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
|
91 |
+
f"Sports: {', '.join(sports)}. Athlete types: {', '.join(athlete_types)}. "
|
92 |
+
f"Infrastructure types: {', '.join(infrastructure_types)}. "
|
93 |
+
f"Provide a detailed analysis of how these conditions affect performance, health, and infrastructure. "
|
94 |
+
f"Include specific impacts for each sport, athlete type, and infrastructure type. "
|
95 |
+
f"Also, provide an overall performance score and an infrastructure impact score, both as percentages."
|
96 |
)
|
97 |
|
98 |
try:
|
|
|
118 |
|
119 |
with st.spinner("Generating predictions..."):
|
120 |
analysis_text = (
|
121 |
+
f"Based on the following analysis, provide a performance score and an infrastructure impact score, "
|
122 |
+
f"both as percentages. Include lines that say 'Performance Score: XX%' and 'Infrastructure Impact Score: YY%' "
|
123 |
+
f"in your response. Here's the text to analyze: {initial_text}"
|
124 |
)
|
125 |
analysis_response = call_ai_model_analysis(analysis_text)
|
126 |
|
|
|
141 |
|
142 |
st.success("Predictions generated!")
|
143 |
|
144 |
+
# Extract performance and infrastructure scores from the analysis result
|
145 |
performance_score = "N/A"
|
146 |
+
infrastructure_score = "N/A"
|
147 |
for line in analysis_result.split('\n'):
|
148 |
+
if "performance score:" in line.lower():
|
149 |
performance_score = line.split(":")[-1].strip()
|
150 |
+
elif "infrastructure impact score:" in line.lower():
|
151 |
+
infrastructure_score = line.split(":")[-1].strip()
|
152 |
|
153 |
# Prepare data for visualization
|
154 |
results_data = {
|
|
|
158 |
results_df = pd.DataFrame(results_data)
|
159 |
|
160 |
# Display results in a table
|
161 |
+
st.subheader("Climate Conditions Summary")
|
162 |
st.table(results_df)
|
163 |
|
164 |
+
# Create a radar chart for climate conditions
|
165 |
+
fig = go.Figure(data=go.Scatterpolar(
|
166 |
+
r=[temperature/50*100, humidity, wind_speed/2, uv_index/11*100, air_quality_index/5, precipitation/5, (atmospheric_pressure-900)/2],
|
167 |
+
theta=results_df['Condition'],
|
168 |
+
fill='toself'
|
169 |
+
))
|
170 |
+
fig.update_layout(
|
171 |
+
polar=dict(
|
172 |
+
radialaxis=dict(visible=True, range=[0, 100])
|
173 |
+
),
|
174 |
+
showlegend=False
|
175 |
+
)
|
176 |
+
st.plotly_chart(fig)
|
177 |
+
|
178 |
# Display prediction
|
179 |
+
st.subheader("Predicted Impact on Performance and Infrastructure")
|
180 |
st.markdown(initial_text.strip())
|
181 |
|
182 |
+
# Display performance and infrastructure scores
|
183 |
+
col1, col2 = st.columns(2)
|
184 |
+
with col1:
|
185 |
+
st.metric("Performance Score", performance_score)
|
186 |
+
with col2:
|
187 |
+
st.metric("Infrastructure Impact Score", infrastructure_score)
|
188 |
+
|
189 |
+
# Display analyzed sports and infrastructure
|
190 |
+
st.subheader("Analyzed Components")
|
191 |
+
col1, col2, col3 = st.columns(3)
|
192 |
+
with col1:
|
193 |
+
st.write("**Sports:**")
|
194 |
+
for sport in sports:
|
195 |
+
st.write(f"- {sport}")
|
196 |
+
with col2:
|
197 |
+
st.write("**Athlete Types:**")
|
198 |
+
for athlete_type in athlete_types:
|
199 |
+
st.write(f"- {athlete_type}")
|
200 |
+
with col3:
|
201 |
+
st.write("**Infrastructure Types:**")
|
202 |
+
for infra_type in infrastructure_types:
|
203 |
+
st.write(f"- {infra_type}")
|
204 |
|
205 |
# Display raw analysis result for debugging
|
206 |
+
with st.expander("Show Raw Analysis"):
|
207 |
+
st.text(analysis_result)
|
208 |
|
209 |
except ValueError as ve:
|
210 |
st.error(f"Configuration error: {ve}")
|