Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import numpy as np
|
|
| 11 |
def load_sample_data():
|
| 12 |
data = {
|
| 13 |
"Date": pd.date_range(start="2023-01-01", periods=100, freq="D"),
|
|
|
|
| 14 |
"AQI": np.random.randint(50, 200, size=100), # Random AQI values
|
| 15 |
"Temperature": np.random.uniform(20, 35, size=100),
|
| 16 |
"Humidity": np.random.uniform(30, 80, size=100),
|
|
@@ -36,12 +37,13 @@ def predict_aqi(model, temperature, humidity):
|
|
| 36 |
return round(prediction[0], 2)
|
| 37 |
|
| 38 |
# Visualization of historical trends
|
| 39 |
-
def plot_trends(data):
|
|
|
|
| 40 |
plt.figure(figsize=(10, 6))
|
| 41 |
-
sns.lineplot(data=
|
| 42 |
-
sns.lineplot(data=
|
| 43 |
-
sns.lineplot(data=
|
| 44 |
-
plt.title("Historical Data Trends")
|
| 45 |
plt.xlabel("Date")
|
| 46 |
plt.ylabel("Values")
|
| 47 |
plt.legend()
|
|
@@ -65,17 +67,18 @@ st.markdown(
|
|
| 65 |
|
| 66 |
# Sidebar inputs
|
| 67 |
st.sidebar.header("Input Parameters")
|
|
|
|
| 68 |
temperature = st.sidebar.slider("Temperature (°C)", 20, 40, 25)
|
| 69 |
humidity = st.sidebar.slider("Humidity (%)", 30, 90, 50)
|
| 70 |
|
| 71 |
# Prediction
|
| 72 |
st.subheader("Predicted AQI")
|
| 73 |
prediction = predict_aqi(model, temperature, humidity)
|
| 74 |
-
st.write(f"The predicted AQI is: {prediction}")
|
| 75 |
|
| 76 |
# Historical trends visualization
|
| 77 |
st.subheader("Historical Data Trends")
|
| 78 |
-
trends_image = plot_trends(data)
|
| 79 |
st.image(trends_image)
|
| 80 |
|
| 81 |
# Model performance
|
|
|
|
| 11 |
def load_sample_data():
|
| 12 |
data = {
|
| 13 |
"Date": pd.date_range(start="2023-01-01", periods=100, freq="D"),
|
| 14 |
+
"Location": np.random.choice(["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"], size=100),
|
| 15 |
"AQI": np.random.randint(50, 200, size=100), # Random AQI values
|
| 16 |
"Temperature": np.random.uniform(20, 35, size=100),
|
| 17 |
"Humidity": np.random.uniform(30, 80, size=100),
|
|
|
|
| 37 |
return round(prediction[0], 2)
|
| 38 |
|
| 39 |
# Visualization of historical trends
|
| 40 |
+
def plot_trends(data, location):
|
| 41 |
+
filtered_data = data[data["Location"] == location]
|
| 42 |
plt.figure(figsize=(10, 6))
|
| 43 |
+
sns.lineplot(data=filtered_data, x="Date", y="AQI", label="AQI")
|
| 44 |
+
sns.lineplot(data=filtered_data, x="Date", y="Temperature", label="Temperature")
|
| 45 |
+
sns.lineplot(data=filtered_data, x="Date", y="Humidity", label="Humidity")
|
| 46 |
+
plt.title(f"Historical Data Trends for {location}")
|
| 47 |
plt.xlabel("Date")
|
| 48 |
plt.ylabel("Values")
|
| 49 |
plt.legend()
|
|
|
|
| 67 |
|
| 68 |
# Sidebar inputs
|
| 69 |
st.sidebar.header("Input Parameters")
|
| 70 |
+
location = st.sidebar.selectbox("Select Location", data["Location"].unique())
|
| 71 |
temperature = st.sidebar.slider("Temperature (°C)", 20, 40, 25)
|
| 72 |
humidity = st.sidebar.slider("Humidity (%)", 30, 90, 50)
|
| 73 |
|
| 74 |
# Prediction
|
| 75 |
st.subheader("Predicted AQI")
|
| 76 |
prediction = predict_aqi(model, temperature, humidity)
|
| 77 |
+
st.write(f"The predicted AQI for {location} is: {prediction}")
|
| 78 |
|
| 79 |
# Historical trends visualization
|
| 80 |
st.subheader("Historical Data Trends")
|
| 81 |
+
trends_image = plot_trends(data, location)
|
| 82 |
st.image(trends_image)
|
| 83 |
|
| 84 |
# Model performance
|