Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,10 @@ import requests
|
|
3 |
import os
|
4 |
import json
|
5 |
import pandas as pd
|
6 |
-
import folium # For
|
7 |
from folium.plugins import MarkerCluster
|
8 |
|
9 |
-
# Function to call the Together
|
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
|
40 |
-
st.write("
|
41 |
|
42 |
-
#
|
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
|
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"
|
72 |
-
f"
|
73 |
-
f"
|
74 |
-
f"
|
75 |
-
f"
|
76 |
)
|
77 |
|
78 |
try:
|
@@ -96,26 +92,30 @@ if st.button("Generate Prediction"):
|
|
96 |
|
97 |
st.success("Response generated!")
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
-
|
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 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
#
|
113 |
map_center = [latitude, longitude]
|
114 |
sport_map = folium.Map(location=map_center, zoom_start=12)
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
st.
|
|
|
|
|
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}")
|