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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -60
app.py CHANGED
@@ -2,8 +2,6 @@ import streamlit as st
2
  import requests
3
  import os
4
  import json
5
- import pandas as pd
6
- import matplotlib.pyplot as plt
7
 
8
  # Function to call the Together AI model
9
  def call_ai_model(all_message):
@@ -34,33 +32,6 @@ def call_ai_model(all_message):
34
 
35
  return response
36
 
37
- # Function to get performance data from AI
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 = ""
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
-
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.")
@@ -69,54 +40,37 @@ st.write("Analyze and visualize the impact of climate conditions on sports perfo
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
 
96
  # Display qualitative analysis
97
  st.subheader("Qualitative Analysis")
98
  st.write(qualitative_result)
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
-
120
  except ValueError as ve:
121
  st.error(f"Configuration error: {ve}")
122
  except requests.exceptions.RequestException as re:
 
2
  import requests
3
  import os
4
  import json
 
 
5
 
6
  # Function to call the Together AI model
7
  def call_ai_model(all_message):
 
32
 
33
  return response
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # Streamlit app layout
36
  st.title("Climate Impact on Sports Performance")
37
  st.write("Analyze and visualize the impact of climate conditions on sports performance.")
 
40
  temperature = st.number_input("Temperature (°C):", min_value=-50, max_value=50, value=25)
41
  humidity = st.number_input("Humidity (%):", min_value=0, max_value=100, value=50)
42
  wind_speed = st.number_input("Wind Speed (km/h):", min_value=0.0, max_value=200.0, value=15.0)
43
+ uv_index = st.number_input("UV Index:", min_value=0, max_value=11, value=5)
44
+ air_quality_index = st.number_input("Air Quality Index:", min_value=0, max_value=500, value=100)
45
+ precipitation = st.number_input("Precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
46
+ atmospheric_pressure = st.number_input("Atmospheric Pressure (hPa):", min_value=900, max_value=1100, value=1013)
47
 
48
  # Button to generate predictions
49
  if st.button("Generate Prediction"):
50
+ all_message = (
51
+ f"Assess the impact on sports performance based on climate conditions: "
52
+ f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, "
53
+ f"UV Index {uv_index}, Air Quality Index {air_quality_index}, "
54
+ f"Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa."
55
+ )
56
 
57
  try:
58
  with st.spinner("Generating predictions..."):
59
  # Call AI model to get qualitative analysis
60
  qualitative_analysis = (
61
+ f"Analyze the impact on sports performance under the following conditions: "
62
+ f"Temperature {temperature}°C, Humidity {humidity}%, Wind Speed {wind_speed} km/h, "
63
+ f"UV Index {uv_index}, Air Quality Index {air_quality_index}, "
64
+ f"Precipitation {precipitation} mm, Atmospheric Pressure {atmospheric_pressure} hPa."
65
  )
66
  qualitative_result = call_ai_model(qualitative_analysis)
67
 
 
 
 
68
  st.success("Predictions generated.")
69
 
70
  # Display qualitative analysis
71
  st.subheader("Qualitative Analysis")
72
  st.write(qualitative_result)
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  except ValueError as ve:
75
  st.error(f"Configuration error: {ve}")
76
  except requests.exceptions.RequestException as re: