ogegadavis254 commited on
Commit
fa025b1
·
verified ·
1 Parent(s): bf0b824

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -39
app.py CHANGED
@@ -34,8 +34,9 @@ def call_ai_model(all_message):
34
 
35
  return response
36
 
37
- # Function to request 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,11 +60,7 @@ def get_performance_data(conditions):
59
  except json.JSONDecodeError:
60
  continue
61
 
62
- try:
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
- response = call_ai_model(f"Assess the impact on sports performance at conditions: "
97
- f"Temperature {temperature}°C, Humidity {humidity}%, "
98
- f"Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
99
- f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, "
100
- f"Atmospheric Pressure {atmospheric_pressure} hPa.")
 
 
 
 
 
 
101
 
102
- st.success("Initial analysis complete.")
103
 
104
- # Get performance score for specified conditions
105
- performance_score = get_performance_data(conditions)
106
- if performance_score is not None:
107
- st.success("Performance data fetched successfully.")
108
- else:
109
- st.warning("Failed to fetch performance data.")
 
110
 
111
  # Plotting the data
112
- if performance_score is not None:
113
- # Prepare data for plotting
114
- climate_conditions = list(conditions.keys())
115
- climate_values = list(conditions.values())
116
-
117
- fig, ax1 = plt.subplots()
118
-
119
- # Plot climate conditions on the primary y-axis
120
- ax1.plot(climate_conditions, climate_values, marker='o', color='b', label='Climate Conditions')
121
- ax1.set_xlabel('Climate Conditions')
122
- ax1.set_ylabel('Values', color='b')
123
- ax1.tick_params(axis='y', labelcolor='b')
124
-
125
- # Create a secondary y-axis for performance score
126
- ax2 = ax1.twinx()
127
- ax2.plot(['Performance Score'], [performance_score], marker='s', color='r', label='Performance Score')
128
- ax2.set_ylabel('Performance Score', color='r')
129
- ax2.tick_params(axis='y', labelcolor='r')
130
-
131
- fig.tight_layout()
132
- st.pyplot(fig)
 
 
 
 
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}")