Update app.py
Browse files
app.py
CHANGED
|
@@ -40,25 +40,27 @@ def get_performance_data(temperature):
|
|
| 40 |
all_message = (
|
| 41 |
f"Provide the expected sports performance value (as a numerical score) at a temperature of {temperature}°C."
|
| 42 |
)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Streamlit app layout
|
| 64 |
st.title("Climate Impact on Sports Performance and Infrastructure")
|
|
@@ -66,42 +68,23 @@ st.write("Analyze and visualize the impact of climate conditions on sports perfo
|
|
| 66 |
|
| 67 |
# Inputs for climate conditions
|
| 68 |
temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
|
| 69 |
-
humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
|
| 70 |
-
wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
|
| 71 |
-
uv_index = st.number_input("UV Index:", min_value=0, max_value=11, value=5)
|
| 72 |
-
air_quality_index = st.number_input("Air Quality Index:", min_value=0, max_value=500, value=100)
|
| 73 |
-
precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
|
| 74 |
-
atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
|
| 75 |
-
|
| 76 |
-
# Geographical location input
|
| 77 |
-
latitude = st.number_input("Latitude:", min_value=-90.0, max_value=90.0, value=0.0)
|
| 78 |
-
longitude = st.number_input("Longitude:", min_value=-180.0, max_value=180.0, value=0.0)
|
| 79 |
-
|
| 80 |
-
# Athlete-specific data
|
| 81 |
-
age = st.number_input("Athlete Age:", min_value=0, max_value=100, value=25)
|
| 82 |
-
sport = st.selectbox("Select Sport:", ["Running", "Cycling", "Swimming", "Football", "Basketball"])
|
| 83 |
-
performance_history = st.text_area("Athlete Performance History:")
|
| 84 |
-
|
| 85 |
-
# Infrastructure characteristics
|
| 86 |
-
facility_type = st.selectbox("Facility Type:", ["Stadium", "Gymnasium", "Outdoor Field"])
|
| 87 |
-
facility_age = st.number_input("Facility Age (years):", min_value=0, max_value=100, value=10)
|
| 88 |
-
materials_used = st.text_input("Materials Used in Construction:")
|
| 89 |
|
| 90 |
if st.button("Generate Prediction"):
|
| 91 |
try:
|
| 92 |
-
with st.spinner("
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
performance_value = get_performance_data(temp)
|
| 97 |
-
|
| 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(
|
| 105 |
ax.set_xlabel('Temperature (°C)')
|
| 106 |
ax.set_ylabel('Performance Score')
|
| 107 |
ax.set_title('Temperature vs. Sports Performance')
|
|
|
|
| 40 |
all_message = (
|
| 41 |
f"Provide the expected sports performance value (as a numerical score) at a temperature of {temperature}°C."
|
| 42 |
)
|
| 43 |
+
while True:
|
| 44 |
+
response = call_ai_model(all_message)
|
| 45 |
+
generated_text = ""
|
| 46 |
+
for line in response.iter_lines():
|
| 47 |
+
if line:
|
| 48 |
+
line_content = line.decode('utf-8')
|
| 49 |
+
if line_content.startswith("data: "):
|
| 50 |
+
line_content = line_content[6:] # Strip "data: " prefix
|
| 51 |
+
try:
|
| 52 |
+
json_data = json.loads(line_content)
|
| 53 |
+
if "choices" in json_data:
|
| 54 |
+
delta = json_data["choices"][0]["delta"]
|
| 55 |
+
if "content" in delta:
|
| 56 |
+
generated_text += delta["content"]
|
| 57 |
+
except json.JSONDecodeError:
|
| 58 |
+
continue
|
| 59 |
+
try:
|
| 60 |
+
performance_value = float(generated_text.strip())
|
| 61 |
+
return performance_value
|
| 62 |
+
except ValueError:
|
| 63 |
+
continue
|
| 64 |
|
| 65 |
# Streamlit app layout
|
| 66 |
st.title("Climate Impact on Sports Performance and Infrastructure")
|
|
|
|
| 68 |
|
| 69 |
# Inputs for climate conditions
|
| 70 |
temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
if st.button("Generate Prediction"):
|
| 73 |
try:
|
| 74 |
+
with st.spinner("Generating predictions..."):
|
| 75 |
+
st.success("Predictions generated. Generating performance data...")
|
| 76 |
|
| 77 |
+
# Generate performance data for different temperatures
|
| 78 |
+
temperatures = range(-10, 41, 5) # Temperatures from -10°C to 40°C in 5°C increments
|
| 79 |
+
performance_values = []
|
| 80 |
+
for temp in temperatures:
|
| 81 |
performance_value = get_performance_data(temp)
|
| 82 |
+
performance_values.append(performance_value)
|
|
|
|
| 83 |
time.sleep(1)
|
| 84 |
|
|
|
|
| 85 |
# Generate line graph
|
| 86 |
fig, ax = plt.subplots()
|
| 87 |
+
ax.plot(temperatures, performance_values, marker='o')
|
| 88 |
ax.set_xlabel('Temperature (°C)')
|
| 89 |
ax.set_ylabel('Performance Score')
|
| 90 |
ax.set_title('Temperature vs. Sports Performance')
|