Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,28 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
params = {"q": city, "appid": api_key, "units": "metric"}
|
| 8 |
-
response = requests.get(base_url, params=params)
|
| 9 |
-
if response.status_code == 200:
|
| 10 |
-
return response.json()
|
| 11 |
-
else:
|
| 12 |
-
return None
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
if st.button("Get Weather"):
|
| 24 |
-
if city:
|
| 25 |
-
weather_data = fetch_weather(city, api_key)
|
| 26 |
-
if weather_data:
|
| 27 |
-
st.subheader(f"Weather in {city.capitalize()}")
|
| 28 |
-
st.write(f"**Temperature:** {weather_data['main']['temp']} °C")
|
| 29 |
-
st.write(f"**Feels Like:** {weather_data['main']['feels_like']} °C")
|
| 30 |
-
st.write(f"**Humidity:** {weather_data['main']['humidity']}%")
|
| 31 |
-
st.write(f"**Pressure:** {weather_data['main']['pressure']} hPa")
|
| 32 |
-
st.write(f"**Conditions:** {weather_data['weather'][0]['description'].capitalize()}")
|
| 33 |
-
st.write(f"**Wind Speed:** {weather_data['wind']['speed']} m/s")
|
| 34 |
-
st.write(f"**Wind Direction:** {weather_data['wind'].get('deg', 'N/A')}°")
|
| 35 |
-
else:
|
| 36 |
-
st.error("Could not fetch weather data. Please check the city name or try again later.")
|
| 37 |
-
else:
|
| 38 |
-
st.error("Please enter a city name.")
|
| 39 |
-
|
| 40 |
-
st.markdown("""
|
| 41 |
-
### About
|
| 42 |
-
This Weather Dashboard fetches real-time weather data using the OpenWeatherMap API. Enter a city name to get the current weather conditions, including temperature, humidity, and more.
|
| 43 |
-
""")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
+
# Title and Description
|
| 4 |
+
st.title("Weather by Month")
|
| 5 |
+
st.write("This app shows the typical weather you might experience in each month.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Data for weather
|
| 8 |
+
weather_data = {
|
| 9 |
+
"January": "Cold and Snowy",
|
| 10 |
+
"February": "Cold and Rainy",
|
| 11 |
+
"March": "Cool and Windy",
|
| 12 |
+
"April": "Rainy and Mild",
|
| 13 |
+
"May": "Warm and Pleasant",
|
| 14 |
+
"June": "Hot and Sunny",
|
| 15 |
+
"July": "Hot and Humid",
|
| 16 |
+
"August": "Hot and Dry",
|
| 17 |
+
"September": "Warm and Breezy",
|
| 18 |
+
"October": "Cool and Clear",
|
| 19 |
+
"November": "Cold and Foggy",
|
| 20 |
+
"December": "Cold and Snowy",
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
# Select month
|
| 24 |
+
selected_month = st.selectbox("Select a month:", list(weather_data.keys()))
|
| 25 |
|
| 26 |
+
# Display weather
|
| 27 |
+
st.subheader(f"Weather in {selected_month}:")
|
| 28 |
+
st.write(weather_data[selected_month])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|