ogegadavis254 commited on
Commit
8f7d62b
1 Parent(s): b4026e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -22
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import json
5
  import pandas as pd
6
  import matplotlib.pyplot as plt
 
7
 
8
  # Function to call the Together API with the provided model
9
  def call_ai_model(all_message):
@@ -38,22 +39,42 @@ def call_ai_model(all_message):
38
  st.title("Impact of Climate on Sports Using AI")
39
  st.write("Predict and mitigate the impacts of climate change on sports performance and infrastructure.")
40
 
41
- # Input fields for user to enter data
42
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
43
  humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
44
  wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
45
  uv_index = st.number_input("UV Index:", min_value=0, max_value=11, value=5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  if st.button("Generate Prediction"):
48
  all_message = (
49
- f"Predict the impact on sports performance and infrastructure given the following climate conditions: "
50
- f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, UV Index {uv_index}."
 
 
 
51
  )
52
-
53
  try:
54
  with st.spinner("Generating response..."):
55
  response = call_ai_model(all_message)
56
-
57
  generated_text = ""
58
  for line in response.iter_lines():
59
  if line:
@@ -68,34 +89,30 @@ if st.button("Generate Prediction"):
68
  generated_text += delta["content"]
69
  except json.JSONDecodeError:
70
  continue
71
-
72
- # Display concise response and conclusion
73
- st.success("Response generated!")
74
 
75
- # Constructing the summary and conclusion
76
- summary = f"**Impact Summary:** {generated_text.strip()}\n"
77
- conclusion = "**Conclusion:** Proper adaptation to these climate conditions is essential for maintaining sports performance and infrastructure resilience."
78
 
79
- # Display text
80
- st.markdown(summary)
81
- st.markdown(conclusion)
82
 
83
- # Example data for charts
 
 
84
  data = {
85
- 'Condition': ['Temperature', 'Humidity', 'Wind Speed', 'UV Index'],
86
- 'Value': [temperature, humidity, wind_speed, uv_index]
87
  }
88
  df = pd.DataFrame(data)
89
-
90
- # Displaying a table
91
  st.table(df)
92
 
93
- # Plotting a bar chart
94
  fig, ax = plt.subplots()
95
- ax.bar(data['Condition'], data['Value'], color=['blue', 'green', 'orange', 'red'])
96
  ax.set_ylabel('Value')
97
- ax.set_title('Climate Condition Impact Indicators')
98
  st.pyplot(fig)
 
99
  except ValueError as ve:
100
  st.error(f"Configuration error: {ve}")
101
  except requests.exceptions.RequestException as re:
 
4
  import json
5
  import pandas as pd
6
  import matplotlib.pyplot as plt
7
+ import numpy as np
8
 
9
  # Function to call the Together API with the provided model
10
  def call_ai_model(all_message):
 
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)
46
  uv_index = st.number_input("UV Index:", min_value=0, max_value=11, value=5)
47
+ air_quality_index = st.number_input("Air Quality Index:", min_value=0, max_value=500, value=100)
48
+ precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
49
+ atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
50
+
51
+ # Athlete-specific inputs
52
+ age = st.number_input("Athlete Age:", min_value=0, max_value=100, value=25)
53
+ sport = st.selectbox("Select Sport:", ["Running", "Cycling", "Swimming", "Football", "Basketball"])
54
+ performance_history = st.text_area("Athlete Performance History:")
55
+
56
+ # Infrastructure characteristics
57
+ facility_type = st.selectbox("Facility Type:", ["Stadium", "Gymnasium", "Outdoor Field"])
58
+ facility_age = st.number_input("Facility Age (years):", min_value=0, max_value=100, value=10)
59
+ materials_used = st.text_input("Materials Used in Construction:")
60
+
61
+ # Socio-economic data
62
+ community_size = st.number_input("Community Size:", min_value=0, value=1000)
63
+ economic_impact_estimate = st.text_area("Estimate Economic Impact (Event cancellations, Facility damage costs):")
64
 
65
  if st.button("Generate Prediction"):
66
  all_message = (
67
+ f"Given the climate conditions: Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, "
68
+ f"UV Index {uv_index}, Air Quality Index {air_quality_index}, Precipitation {precipitation} mm, "
69
+ f"Atmospheric Pressure {atmospheric_pressure} hPa. For athlete (Age: {age}, Sport: {sport}), "
70
+ f"Facility (Type: {facility_type}, Age: {facility_age}, Materials: {materials_used}). "
71
+ f"Assess the impact on sports performance, infrastructure, and socio-economic aspects."
72
  )
73
+
74
  try:
75
  with st.spinner("Generating response..."):
76
  response = call_ai_model(all_message)
77
+
78
  generated_text = ""
79
  for line in response.iter_lines():
80
  if line:
 
89
  generated_text += delta["content"]
90
  except json.JSONDecodeError:
91
  continue
 
 
 
92
 
93
+ st.success("Response generated!")
 
 
94
 
95
+ # Display the impact summary and conclusions
96
+ st.markdown(f"**Impact Summary:** {generated_text.strip()}")
97
+ st.markdown("**Conclusion:** Tailoring strategies based on these climate conditions can significantly enhance performance and infrastructure resilience.")
98
 
99
+ # Data Visualization
100
+ st.subheader("Climate Condition Impacts Visualization")
101
+ # Example: Displaying data in a table
102
  data = {
103
+ 'Condition': ['Temperature', 'Humidity', 'Wind Speed', 'UV Index', 'Air Quality Index', 'Precipitation', 'Atmospheric Pressure'],
104
+ 'Value': [temperature, humidity, wind_speed, uv_index, air_quality_index, precipitation, atmospheric_pressure]
105
  }
106
  df = pd.DataFrame(data)
 
 
107
  st.table(df)
108
 
109
+ # Plotting a bar chart for climate variables
110
  fig, ax = plt.subplots()
111
+ ax.bar(data['Condition'], data['Value'], color=['blue', 'green', 'orange', 'red', 'purple', 'gray', 'cyan'])
112
  ax.set_ylabel('Value')
113
+ ax.set_title('Climate Condition Impacts')
114
  st.pyplot(fig)
115
+
116
  except ValueError as ve:
117
  st.error(f"Configuration error: {ve}")
118
  except requests.exceptions.RequestException as re: