ogegadavis254 commited on
Commit
b4026e6
1 Parent(s): e13723a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -21
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import requests
3
  import os
4
  import json
 
 
5
 
6
  # Function to call the Together API with the provided model
7
  def call_ai_model(all_message):
@@ -33,23 +35,25 @@ def call_ai_model(all_message):
33
  return response
34
 
35
  # Streamlit app layout
36
- st.title("Climate Change Impact on Sports Using AI")
37
  st.write("Predict and mitigate the impacts of climate change on sports performance and infrastructure.")
38
 
39
  # Input fields for user to enter data
40
- temperature = st.number_input("Enter temperature (°C):", min_value=-50, max_value=50, value=25)
41
- humidity = st.number_input("Enter humidity (%):", min_value=0, max_value=100, value=50)
42
- air_quality = st.number_input("Enter air quality index (AQI):", min_value=0, max_value=500, value=100)
43
- precipitation = st.number_input("Enter precipitation (mm):", min_value=0.0, max_value=500.0, value=10.0)
44
 
45
  if st.button("Generate Prediction"):
46
- all_message = f"Predict the impact of the following climate conditions on sports performance and infrastructure: temperature {temperature}°C, humidity {humidity}%, air quality index {air_quality}, and precipitation {precipitation}mm."
 
 
 
47
 
48
  try:
49
  with st.spinner("Generating response..."):
50
  response = call_ai_model(all_message)
51
 
52
- # Handle the streaming response and concatenate chunks
53
  generated_text = ""
54
  for line in response.iter_lines():
55
  if line:
@@ -65,21 +69,33 @@ if st.button("Generate Prediction"):
65
  except json.JSONDecodeError:
66
  continue
67
 
68
- # Format the response for better readability
69
- formatted_response = (
70
- "<b>Impact of Climate Conditions on Sports Performance and Infrastructure:</b>\n"
71
- f"- **Temperature**: {temperature}°C\n"
72
- f"- **Humidity**: {humidity}%\n"
73
- f"- **Air Quality Index**: {air_quality}\n"
74
- f"- **Precipitation**: {precipitation}mm\n\n"
75
- "<b>Findings:</b>\n"
76
- f"{generated_text}\n\n"
77
- "<b>Conclusion:</b>\n"
78
- "Based on the predicted climate conditions, it's crucial to adapt sports performance strategies and infrastructure designs to ensure resilience and safety."
79
- )
80
 
81
- st.success("Response generated successfully!")
82
- st.markdown(formatted_response, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  except ValueError as ve:
84
  st.error(f"Configuration error: {ve}")
85
  except requests.exceptions.RequestException as re:
 
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 API with the provided model
9
  def call_ai_model(all_message):
 
35
  return response
36
 
37
  # Streamlit app layout
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:
 
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: