ogegadavis254 commited on
Commit
f689a87
·
verified ·
1 Parent(s): 9dd5aae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -3,10 +3,10 @@ import requests
3
  import os
4
  import json
5
  import pandas as pd
6
- import folium # For creating the map visualizations
7
  from folium.plugins import MarkerCluster
8
 
9
- # Function to call the Together API with the provided model
10
  def call_ai_model(all_message):
11
  url = "https://api.together.xyz/v1/chat/completions"
12
  payload = {
@@ -36,10 +36,10 @@ def call_ai_model(all_message):
36
  return response
37
 
38
  # Streamlit app layout
39
- st.title("Impact of Climate on Sports Using AI")
40
- st.write("Predict and mitigate the impacts of climate change on sports performance and infrastructure.")
41
 
42
- # Climate data inputs
43
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
44
  humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
45
  wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
@@ -52,7 +52,7 @@ atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=
52
  latitude = st.number_input("Latitude:", min_value=-90.0, max_value=90.0, value=0.0)
53
  longitude = st.number_input("Longitude:", min_value=-180.0, max_value=180.0, value=0.0)
54
 
55
- # Athlete-specific inputs
56
  age = st.number_input("Athlete Age:", min_value=0, max_value=100, value=25)
57
  sport = st.selectbox("Select Sport:", ["Running", "Cycling", "Swimming", "Football", "Basketball"])
58
  performance_history = st.text_area("Athlete Performance History:")
@@ -62,17 +62,13 @@ facility_type = st.selectbox("Facility Type:", ["Stadium", "Gymnasium", "Outdoor
62
  facility_age = st.number_input("Facility Age (years):", min_value=0, max_value=100, value=10)
63
  materials_used = st.text_input("Materials Used in Construction:")
64
 
65
- # Socio-economic data
66
- community_size = st.number_input("Community Size:", min_value=0, value=1000)
67
- economic_impact_estimate = st.text_area("Estimate Economic Impact (Event cancellations, Facility damage costs):")
68
-
69
  if st.button("Generate Prediction"):
70
  all_message = (
71
- f"Given the climate conditions: Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, "
72
- f"UV Index {uv_index}, Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, "
73
- f"Atmospheric Pressure {atmospheric_pressure} hPa. Location: Latitude {latitude}, Longitude {longitude}. "
74
- f"For athlete (Age: {age}, Sport: {sport}), Facility (Type: {facility_type}, Age: {facility_age}, Materials: {materials_used}). "
75
- f"Assess the impact on sports performance, infrastructure, and socio-economic aspects."
76
  )
77
 
78
  try:
@@ -96,26 +92,30 @@ if st.button("Generate Prediction"):
96
 
97
  st.success("Response generated!")
98
 
99
- # Display the impact summary and conclusions
100
- st.markdown(f"**Impact Summary:** {generated_text.strip()}")
101
- st.markdown("**Conclusion:** Tailoring strategies based on these climate conditions can significantly enhance performance and infrastructure resilience.")
102
-
103
- # Displaying a table of input data
104
- data = {
105
- 'Condition': ['Temperature', 'Humidity', 'Wind Speed', 'UV Index', 'Air Quality Index', 'Precipitation', 'Atmospheric Pressure', 'Latitude', 'Longitude'],
106
- 'Value': [temperature, humidity, wind_speed, uv_index, air_quality_index, precipitation, atmospheric_pressure, latitude, longitude]
107
  }
108
- df = pd.DataFrame(data)
109
- st.subheader("Input Data Overview")
110
- st.table(df)
 
 
 
 
 
 
111
 
112
- # Creating a map with the provided location
113
  map_center = [latitude, longitude]
114
  sport_map = folium.Map(location=map_center, zoom_start=12)
115
- marker_cluster = MarkerCluster().add_to(sport_map)
116
- folium.Marker(location=map_center, popup="User Location").add_to(marker_cluster)
117
- map_html = sport_map._repr_html_()
118
- st.components.v1.html(map_html, height=600)
 
 
119
 
120
  except ValueError as ve:
121
  st.error(f"Configuration error: {ve}")
 
3
  import os
4
  import json
5
  import pandas as pd
6
+ import folium # For map visualizations
7
  from folium.plugins import MarkerCluster
8
 
9
+ # Function to call the Together AI model
10
  def call_ai_model(all_message):
11
  url = "https://api.together.xyz/v1/chat/completions"
12
  payload = {
 
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.")
41
 
42
+ # Inputs for climate conditions
43
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
44
  humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
45
  wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
 
52
  latitude = st.number_input("Latitude:", min_value=-90.0, max_value=90.0, value=0.0)
53
  longitude = st.number_input("Longitude:", min_value=-180.0, max_value=180.0, value=0.0)
54
 
55
+ # Athlete-specific data
56
  age = st.number_input("Athlete Age:", min_value=0, max_value=100, value=25)
57
  sport = st.selectbox("Select Sport:", ["Running", "Cycling", "Swimming", "Football", "Basketball"])
58
  performance_history = st.text_area("Athlete Performance History:")
 
62
  facility_age = st.number_input("Facility Age (years):", min_value=0, max_value=100, value=10)
63
  materials_used = st.text_input("Materials Used in Construction:")
64
 
 
 
 
 
65
  if st.button("Generate Prediction"):
66
  all_message = (
67
+ f"Assess the impact on sports performance and infrastructure based on climate conditions: "
68
+ f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}, "
69
+ f"Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa. "
70
+ f"Location: Latitude {latitude}, Longitude {longitude}. "
71
+ f"Athlete (Age: {age}, Sport: {sport}), Facility (Type: {facility_type}, Age: {facility_age}, Materials: {materials_used})."
72
  )
73
 
74
  try:
 
92
 
93
  st.success("Response generated!")
94
 
95
+ # Prepare data for visualization
96
+ results_data = {
97
+ "Condition": ["Temperature", "Humidity", "Wind Speed", "UV Index", "Air Quality Index", "Precipitation", "Atmospheric Pressure"],
98
+ "Value": [temperature, humidity, wind_speed, uv_index, air_quality_index, precipitation, atmospheric_pressure]
 
 
 
 
99
  }
100
+ results_df = pd.DataFrame(results_data)
101
+
102
+ # Display results in a table
103
+ st.subheader("Results Summary")
104
+ st.table(results_df)
105
+
106
+ # Display prediction
107
+ st.markdown("**Predicted Impact on Performance and Infrastructure:**")
108
+ st.markdown(generated_text.strip())
109
 
110
+ # Create a map with the user's location
111
  map_center = [latitude, longitude]
112
  sport_map = folium.Map(location=map_center, zoom_start=12)
113
+ MarkerCluster().add_to(sport_map).add_child(
114
+ folium.Marker(location=map_center, popup="User Location")
115
+ )
116
+ st.subheader("Geographical Visualization")
117
+ st.write("Map showing the location's impact on sports performance and infrastructure.")
118
+ st.components.v1.html(sport_map._repr_html_(), height=600)
119
 
120
  except ValueError as ve:
121
  st.error(f"Configuration error: {ve}")