Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,6 @@ def call_ai_model(all_message):
|
|
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,7 +59,9 @@ def get_performance_data(conditions):
|
|
60 |
except json.JSONDecodeError:
|
61 |
continue
|
62 |
|
63 |
-
|
|
|
|
|
64 |
|
65 |
# Streamlit app layout
|
66 |
st.title("Climate Impact on Sports Performance")
|
@@ -89,7 +90,7 @@ if st.button("Generate Prediction"):
|
|
89 |
|
90 |
try:
|
91 |
with st.spinner("Generating predictions..."):
|
92 |
-
# Call AI model to get
|
93 |
qualitative_analysis = (
|
94 |
f"Assess the impact on sports performance at conditions: "
|
95 |
f"Temperature {temperature}°C, Humidity {humidity}%, "
|
@@ -100,7 +101,7 @@ if st.button("Generate Prediction"):
|
|
100 |
qualitative_result = call_ai_model(qualitative_analysis)
|
101 |
|
102 |
# Get performance score for specified conditions
|
103 |
-
|
104 |
|
105 |
st.success("Predictions generated.")
|
106 |
|
@@ -110,33 +111,22 @@ if st.button("Generate Prediction"):
|
|
110 |
|
111 |
# Display performance score
|
112 |
st.subheader("Performance Score")
|
113 |
-
st.write(f"Predicted Performance
|
114 |
|
115 |
# Plotting the data
|
116 |
st.subheader("Performance Score vs Climate Conditions")
|
117 |
|
118 |
-
# Define
|
119 |
climate_conditions = list(conditions.keys())
|
120 |
climate_values = list(conditions.values())
|
121 |
|
122 |
-
#
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
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:
|
|
|
36 |
|
37 |
# Function to get performance data from AI
|
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 |
except json.JSONDecodeError:
|
60 |
continue
|
61 |
|
62 |
+
# Example: Replace with actual data from API
|
63 |
+
performance_scores = [75, 80, 70, 85, 78, 72, 82] # Replace with actual data from API
|
64 |
+
return performance_scores
|
65 |
|
66 |
# Streamlit app layout
|
67 |
st.title("Climate Impact on Sports Performance")
|
|
|
90 |
|
91 |
try:
|
92 |
with st.spinner("Generating predictions..."):
|
93 |
+
# Call AI model to get qualitative analysis
|
94 |
qualitative_analysis = (
|
95 |
f"Assess the impact on sports performance at conditions: "
|
96 |
f"Temperature {temperature}°C, Humidity {humidity}%, "
|
|
|
101 |
qualitative_result = call_ai_model(qualitative_analysis)
|
102 |
|
103 |
# Get performance score for specified conditions
|
104 |
+
performance_scores = get_performance_data(conditions)
|
105 |
|
106 |
st.success("Predictions generated.")
|
107 |
|
|
|
111 |
|
112 |
# Display performance score
|
113 |
st.subheader("Performance Score")
|
114 |
+
st.write(f"Predicted Performance Scores: {performance_scores}")
|
115 |
|
116 |
# Plotting the data
|
117 |
st.subheader("Performance Score vs Climate Conditions")
|
118 |
|
119 |
+
# Define climate conditions for plotting
|
120 |
climate_conditions = list(conditions.keys())
|
121 |
climate_values = list(conditions.values())
|
122 |
|
123 |
+
# Plotting performance score against climate conditions
|
124 |
+
fig, ax = plt.subplots()
|
125 |
+
ax.plot(climate_conditions, performance_scores, marker='o', linestyle='-', color='b')
|
126 |
+
ax.set_xlabel('Climate Conditions')
|
127 |
+
ax.set_ylabel('Performance Score')
|
128 |
+
ax.set_title('Performance Score vs Climate Conditions')
|
129 |
+
ax.grid(True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
st.pyplot(fig)
|
131 |
|
132 |
except ValueError as ve:
|