ogegadavis254 commited on
Commit
c438b94
1 Parent(s): c1cf6d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -38,7 +38,8 @@ def call_ai_model(all_message):
38
  def get_performance_data(conditions):
39
  all_message = (
40
  f"Provide the expected sports performance score at conditions: "
41
- f"Temperature {conditions['temperature']}°C."
 
42
  )
43
  response = call_ai_model(all_message)
44
  generated_text = ""
@@ -57,33 +58,38 @@ def get_performance_data(conditions):
57
  continue
58
 
59
  # Example: Replace with actual data from API
60
- performance_scores = [75, 80, 70, 85, 78, 72, 82] # Replace with actual data from API
61
- return performance_scores
62
 
63
  # Streamlit app layout
64
  st.title("Climate Impact on Sports Performance")
65
- st.write("Analyze and visualize the impact of temperature on sports performance.")
66
 
67
- # Input for temperature
68
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
 
 
69
 
70
  # Button to generate predictions
71
  if st.button("Generate Prediction"):
72
  conditions = {
73
- "temperature": temperature
 
 
74
  }
75
 
76
  try:
77
  with st.spinner("Generating predictions..."):
78
  # Call AI model to get qualitative analysis
79
  qualitative_analysis = (
80
- f"Assess the impact on sports performance at temperature: "
81
- f"{temperature}°C."
 
82
  )
83
  qualitative_result = call_ai_model(qualitative_analysis)
84
 
85
  # Get performance score for specified conditions
86
- performance_scores = get_performance_data(conditions)
87
 
88
  st.success("Predictions generated.")
89
 
@@ -93,17 +99,21 @@ if st.button("Generate Prediction"):
93
 
94
  # Display performance score
95
  st.subheader("Performance Score")
96
- st.write(f"Predicted Performance Scores: {performance_scores}")
97
 
98
  # Plotting the data
99
- st.subheader("Performance Score vs Temperature")
100
 
101
- # Plot performance score against temperature
 
 
 
 
102
  fig, ax = plt.subplots()
103
- ax.plot(conditions['temperature'], performance_scores, marker='o', linestyle='-', color='b')
104
- ax.set_xlabel('Temperature (°C)')
105
- ax.set_ylabel('Performance Score')
106
- ax.set_title('Performance Score vs Temperature')
107
  ax.grid(True)
108
  st.pyplot(fig)
109
 
 
38
  def get_performance_data(conditions):
39
  all_message = (
40
  f"Provide the expected sports performance score at conditions: "
41
+ f"Temperature {conditions['temperature']}°C, Humidity {conditions['humidity']}%, "
42
+ f"Wind Speed {conditions['wind_speed']} km/h."
43
  )
44
  response = call_ai_model(all_message)
45
  generated_text = ""
 
58
  continue
59
 
60
  # Example: Replace with actual data from API
61
+ performance_score = 80 # Replace with actual data from API
62
+ return performance_score
63
 
64
  # Streamlit app layout
65
  st.title("Climate Impact on Sports Performance")
66
+ st.write("Analyze and visualize the impact of climate conditions on sports performance.")
67
 
68
+ # Inputs for climate conditions
69
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
70
+ humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
71
+ wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
72
 
73
  # Button to generate predictions
74
  if st.button("Generate Prediction"):
75
  conditions = {
76
+ "temperature": temperature,
77
+ "humidity": humidity,
78
+ "wind_speed": wind_speed
79
  }
80
 
81
  try:
82
  with st.spinner("Generating predictions..."):
83
  # Call AI model to get qualitative analysis
84
  qualitative_analysis = (
85
+ f"Assess the impact on sports performance at conditions: "
86
+ f"Temperature {temperature}°C, Humidity {humidity}%, "
87
+ f"Wind Speed {wind_speed} km/h."
88
  )
89
  qualitative_result = call_ai_model(qualitative_analysis)
90
 
91
  # Get performance score for specified conditions
92
+ performance_score = get_performance_data(conditions)
93
 
94
  st.success("Predictions generated.")
95
 
 
99
 
100
  # Display performance score
101
  st.subheader("Performance Score")
102
+ st.write(f"Predicted Performance Score: {performance_score}")
103
 
104
  # Plotting the data
105
+ st.subheader("Performance Score vs Climate Conditions")
106
 
107
+ # Define climate conditions for plotting
108
+ climate_conditions = list(conditions.keys())
109
+ climate_values = list(conditions.values())
110
+
111
+ # Plotting performance score against climate conditions
112
  fig, ax = plt.subplots()
113
+ ax.plot(climate_conditions, climate_values, marker='o', linestyle='-', color='b')
114
+ ax.set_xlabel('Climate Conditions')
115
+ ax.set_ylabel('Value')
116
+ ax.set_title('Performance Score vs Climate Conditions')
117
  ax.grid(True)
118
  st.pyplot(fig)
119