Update app.py
Browse files
app.py
CHANGED
@@ -34,8 +34,9 @@ def call_ai_model(all_message):
|
|
34 |
|
35 |
return response
|
36 |
|
37 |
-
# Function to
|
38 |
def get_performance_data(conditions):
|
|
|
39 |
all_message = (
|
40 |
f"Provide the expected sports performance score at conditions: "
|
41 |
f"Temperature {conditions['temperature']}°C, Humidity {conditions['humidity']}%, "
|
@@ -59,11 +60,7 @@ def get_performance_data(conditions):
|
|
59 |
except json.JSONDecodeError:
|
60 |
continue
|
61 |
|
62 |
-
|
63 |
-
return float(generated_text.strip())
|
64 |
-
except ValueError:
|
65 |
-
st.warning(f"Could not convert the response to a float: {generated_text}")
|
66 |
-
return None
|
67 |
|
68 |
# Streamlit app layout
|
69 |
st.title("Climate Impact on Sports Performance")
|
@@ -93,43 +90,54 @@ if st.button("Generate Prediction"):
|
|
93 |
try:
|
94 |
with st.spinner("Generating predictions..."):
|
95 |
# Call AI model to get initial prediction and qualitative assessment
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
st.success("
|
103 |
|
104 |
-
#
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
110 |
|
111 |
# Plotting the data
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
|
134 |
except ValueError as ve:
|
135 |
st.error(f"Configuration error: {ve}")
|
|
|
34 |
|
35 |
return response
|
36 |
|
37 |
+
# Function to get performance data from AI
|
38 |
def get_performance_data(conditions):
|
39 |
+
url = "https://api.together.xyz/v1/chat/completions"
|
40 |
all_message = (
|
41 |
f"Provide the expected sports performance score at conditions: "
|
42 |
f"Temperature {conditions['temperature']}°C, Humidity {conditions['humidity']}%, "
|
|
|
60 |
except json.JSONDecodeError:
|
61 |
continue
|
62 |
|
63 |
+
return generated_text.strip()
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Streamlit app layout
|
66 |
st.title("Climate Impact on Sports Performance")
|
|
|
90 |
try:
|
91 |
with st.spinner("Generating predictions..."):
|
92 |
# Call AI model to get initial prediction and qualitative assessment
|
93 |
+
qualitative_analysis = (
|
94 |
+
f"Assess the impact on sports performance at conditions: "
|
95 |
+
f"Temperature {temperature}°C, Humidity {humidity}%, "
|
96 |
+
f"Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
|
97 |
+
f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, "
|
98 |
+
f"Atmospheric Pressure {atmospheric_pressure} hPa."
|
99 |
+
)
|
100 |
+
qualitative_result = call_ai_model(qualitative_analysis)
|
101 |
+
|
102 |
+
# Get performance score for specified conditions
|
103 |
+
performance_score_text = get_performance_data(conditions)
|
104 |
|
105 |
+
st.success("Predictions generated.")
|
106 |
|
107 |
+
# Display qualitative analysis
|
108 |
+
st.subheader("Qualitative Analysis")
|
109 |
+
st.write(qualitative_result)
|
110 |
+
|
111 |
+
# Display performance score
|
112 |
+
st.subheader("Performance Score")
|
113 |
+
st.write(f"Predicted Performance Score: {performance_score_text}")
|
114 |
|
115 |
# Plotting the data
|
116 |
+
st.subheader("Performance Score vs Climate Conditions")
|
117 |
+
|
118 |
+
# Define some dummy data for the climate conditions
|
119 |
+
climate_conditions = list(conditions.keys())
|
120 |
+
climate_values = list(conditions.values())
|
121 |
+
|
122 |
+
# Prepare data for plotting (replace with actual performance scores from API)
|
123 |
+
performance_scores = [80, 75, 85, 70, 78, 82, 72] # Replace with actual data from API
|
124 |
+
|
125 |
+
fig, ax1 = plt.subplots()
|
126 |
+
|
127 |
+
# Plot climate conditions on the primary y-axis
|
128 |
+
ax1.plot(climate_conditions, climate_values, marker='o', color='b', label='Climate Conditions')
|
129 |
+
ax1.set_xlabel('Climate Conditions')
|
130 |
+
ax1.set_ylabel('Values', color='b')
|
131 |
+
ax1.tick_params(axis='y', labelcolor='b')
|
132 |
+
|
133 |
+
# Create a secondary y-axis for performance score
|
134 |
+
ax2 = ax1.twinx()
|
135 |
+
ax2.plot(['Performance Score'], performance_scores, marker='s', color='r', label='Performance Score')
|
136 |
+
ax2.set_ylabel('Performance Score', color='r')
|
137 |
+
ax2.tick_params(axis='y', labelcolor='r')
|
138 |
+
|
139 |
+
fig.tight_layout()
|
140 |
+
st.pyplot(fig)
|
141 |
|
142 |
except ValueError as ve:
|
143 |
st.error(f"Configuration error: {ve}")
|