ogegadavis254 commited on
Commit
bd2a651
·
verified ·
1 Parent(s): 01a19eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -58
app.py CHANGED
@@ -58,7 +58,7 @@ def get_performance_data(temperature):
58
  try:
59
  return float(generated_text.strip())
60
  except ValueError:
61
- return generated_text.strip()
62
 
63
  # Streamlit app layout
64
  st.title("Climate Impact on Sports Performance and Infrastructure")
@@ -88,70 +88,20 @@ facility_age = st.number_input("Facility Age (years):", min_value=0, max_value=1
88
  materials_used = st.text_input("Materials Used in Construction:")
89
 
90
  if st.button("Generate Prediction"):
91
- all_message = (
92
- f"Assess the impact on sports performance and infrastructure based on climate conditions: "
93
- f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
94
- f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
95
- f"Location: Latitude {latitude}, Longitude {longitude}. "
96
- f"Athlete (Age: {age}, Sport: {sport}), Facility (Type: {facility_type}, Age: {facility_age}, Materials: {materials_used})."
97
- )
98
-
99
  try:
100
  with st.spinner("Analyzing climate conditions..."):
101
- response = call_ai_model(all_message)
102
-
103
- st.success("Initial analysis complete. Generating detailed predictions...")
104
-
105
- generated_text = ""
106
- for line in response.iter_lines():
107
- if line:
108
- line_content = line.decode('utf-8')
109
- if line_content.startswith("data: "):
110
- line_content = line_content[6:] # Strip "data: " prefix
111
- try:
112
- json_data = json.loads(line_content)
113
- if "choices" in json_data:
114
- delta = json_data["choices"][0]["delta"]
115
- if "content" in delta:
116
- generated_text += delta["content"]
117
- except json.JSONDecodeError:
118
- continue
119
-
120
- st.success("Detailed predictions generated. Preparing visualizations...")
121
-
122
- # Prepare data for visualization
123
- results_data = {
124
- "Condition": ["Temperature", "Humidity", "Wind Speed", "UV Index", "Air Quality Index", "Precipitation", "Atmospheric Pressure"],
125
- "Value": [temperature, humidity, wind_speed, uv_index, air_quality_index, precipitation, atmospheric_pressure]
126
- }
127
- results_df = pd.DataFrame(results_data)
128
-
129
- # Display results in a table
130
- st.subheader("Results Summary")
131
- st.table(results_df)
132
-
133
- # Display prediction
134
- st.markdown("**Predicted Impact on Performance and Infrastructure:**")
135
- st.markdown(generated_text.strip())
136
-
137
- st.success("Visualizations ready. Generating performance data...")
138
 
139
- # Generate performance data for different temperatures
140
- temperatures = range(-10, 41, 5) # Temperatures from -10°C to 40°C in 5°C increments
141
- performance_values = []
142
- for temp in temperatures:
143
- st.spinner(f"Fetching performance data for {temp}°C...")
144
- performance_value = get_performance_data(temp)
145
- if isinstance(performance_value, float):
146
- performance_values.append(performance_value)
147
- else:
148
- st.warning(performance_value)
149
- time.sleep(1)
150
 
151
  if performance_values:
152
  # Generate line graph
153
  fig, ax = plt.subplots()
154
- ax.plot(temperatures, performance_values, marker='o')
155
  ax.set_xlabel('Temperature (°C)')
156
  ax.set_ylabel('Performance Score')
157
  ax.set_title('Temperature vs. Sports Performance')
 
58
  try:
59
  return float(generated_text.strip())
60
  except ValueError:
61
+ return None
62
 
63
  # Streamlit app layout
64
  st.title("Climate Impact on Sports Performance and Infrastructure")
 
88
  materials_used = st.text_input("Materials Used in Construction:")
89
 
90
  if st.button("Generate Prediction"):
 
 
 
 
 
 
 
 
91
  try:
92
  with st.spinner("Analyzing climate conditions..."):
93
+ performance_values = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
+ for temp in range(-10, 41, 5): # Temperatures from -10°C to 40°C in 5°C increments
96
+ performance_value = get_performance_data(temp)
97
+ if performance_value is not None:
98
+ performance_values.append(performance_value)
99
+ time.sleep(1)
 
 
 
 
 
 
100
 
101
  if performance_values:
102
  # Generate line graph
103
  fig, ax = plt.subplots()
104
+ ax.plot(range(-10, 41, 5), performance_values, marker='o')
105
  ax.set_xlabel('Temperature (°C)')
106
  ax.set_ylabel('Performance Score')
107
  ax.set_title('Temperature vs. Sports Performance')