ogegadavis254 commited on
Commit
5531c71
1 Parent(s): e003f26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -9
app.py CHANGED
@@ -35,6 +35,35 @@ def call_ai_model(all_message):
35
 
36
  return response
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # Streamlit app layout
39
  st.title("Climate Impact on Sports Performance and Infrastructure")
40
  st.write("Analyze and visualize the impact of climate conditions on sports performance and infrastructure.")
@@ -58,7 +87,7 @@ if st.button("Generate Prediction"):
58
  f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
59
  f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
60
  f"Location: Latitude {latitude}, Longitude {longitude}."
61
- f"After analyzing that I want you to visualize the data in the best way possible, might be in a table, using a chart or any other way so that it could be easy to understand"
62
  )
63
 
64
  try:
@@ -139,16 +168,22 @@ if st.button("Generate Prediction"):
139
  st.markdown("**Predicted Impact on Performance and Infrastructure:**")
140
  st.markdown(generated_text.strip())
141
 
142
- # Select conditions to visualize
143
- conditions = ["Humidity", "Wind Speed", "UV Index", "Air Quality Index", "Precipitation", "Atmospheric Pressure"]
144
- selected_conditions = st.multiselect("Select conditions to visualize against Temperature:", conditions, default=conditions)
 
 
 
 
 
 
145
 
146
- # Generate a line chart to show the relationship between temperature and selected conditions
147
  fig, ax = plt.subplots()
148
- for condition in selected_conditions:
149
- ax.plot(["Temperature", condition], [temperature, results_data["Value"][results_data["Condition"].index(condition)]], marker='o', label=condition)
150
- ax.set_ylabel('Values')
151
- ax.set_title('Relationship Between Temperature and Selected Conditions')
152
  ax.legend()
153
  st.pyplot(fig)
154
 
 
35
 
36
  return response
37
 
38
+ # Function to generate performance data
39
+ def generate_performance_data(temperature_range):
40
+ performance_data = []
41
+ for temp in temperature_range:
42
+ message = (
43
+ f"Generate performance data for a sport under the following condition: "
44
+ f"Temperature {temp}°C. Provide a single value for performance."
45
+ )
46
+ response = call_ai_model(message)
47
+
48
+ performance_value = ""
49
+ for line in response.iter_lines():
50
+ if line:
51
+ line_content = line.decode('utf-8')
52
+ if line_content.startswith("data: "):
53
+ line_content = line_content[6:] # Strip "data: " prefix
54
+ try:
55
+ json_data = json.loads(line_content)
56
+ if "choices" in json_data:
57
+ delta = json_data["choices"][0]["delta"]
58
+ if "content" in delta:
59
+ performance_value += delta["content"]
60
+ except json.JSONDecodeError:
61
+ continue
62
+
63
+ performance_data.append(float(performance_value.strip()))
64
+
65
+ return performance_data
66
+
67
  # Streamlit app layout
68
  st.title("Climate Impact on Sports Performance and Infrastructure")
69
  st.write("Analyze and visualize the impact of climate conditions on sports performance and infrastructure.")
 
87
  f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
88
  f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
89
  f"Location: Latitude {latitude}, Longitude {longitude}."
90
+ f"After analyzing that, visualize the data in the best way possible, might be in a table, using a chart or any other way so that it could be easy to understand"
91
  )
92
 
93
  try:
 
168
  st.markdown("**Predicted Impact on Performance and Infrastructure:**")
169
  st.markdown(generated_text.strip())
170
 
171
+ # Generate performance data for different temperatures
172
+ temp_range = [temperature - 5, temperature, temperature + 5]
173
+ performance_values = generate_performance_data(temp_range)
174
+
175
+ # Create a dataframe for performance values
176
+ performance_df = pd.DataFrame({
177
+ "Temperature": temp_range,
178
+ "Performance": performance_values
179
+ })
180
 
181
+ # Generate a line chart to show the relationship between temperature and performance
182
  fig, ax = plt.subplots()
183
+ ax.plot(performance_df["Temperature"], performance_df["Performance"], marker='o', label="Performance")
184
+ ax.set_xlabel('Temperature (°C)')
185
+ ax.set_ylabel('Performance')
186
+ ax.set_title('Relationship Between Temperature and Sports Performance')
187
  ax.legend()
188
  st.pyplot(fig)
189