Memoona648 commited on
Commit
0debb06
·
verified ·
1 Parent(s): 14773ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py CHANGED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ from huggingface_hub import InferenceClient
4
+ import plotly.express as px
5
+ from datetime import datetime
6
+
7
+ # ------------------- CONFIG -------------------
8
+ API_KEY = "YOUR_HUGGINGFACE_API_KEY" # Replace with your Hugging Face token
9
+ MODEL_ID = "duongtruongbinh/smolagents-weather-agent"
10
+
11
+ client = InferenceClient(API_KEY)
12
+
13
+ st.set_page_config(page_title="Weather Forecast App", page_icon="⛅", layout="wide")
14
+
15
+ # ------------------- UI -------------------
16
+ mode = st.sidebar.radio("Choose Theme", ["Light", "Dark"])
17
+ if mode == "Dark":
18
+ st.markdown('<style>body {background-color: #0e1117; color: white;}</style>', unsafe_allow_html=True)
19
+
20
+ st.title("⛅ Professional Weather Forecasting App")
21
+ st.markdown("Enter a city name to get current weather and a 5-day forecast")
22
+
23
+ city = st.text_input("🌍 Enter city name", "London")
24
+
25
+ if city:
26
+ try:
27
+ response = client.model(MODEL_ID)({"location": city})
28
+ except Exception as e:
29
+ st.error(f"API Error: {e}")
30
+ else:
31
+ if "error" in response:
32
+ st.error("City not found or API issue. Try again!")
33
+ else:
34
+ st.subheader(f"Current Weather in {city.title()}")
35
+ col1, col2, col3, col4 = st.columns(4)
36
+ with col1:
37
+ st.metric("🌡 Temperature", f"{response['temperature']} °C")
38
+ with col2:
39
+ st.metric("💧 Humidity", f"{response['humidity']} %")
40
+ with col3:
41
+ st.metric("🌬 Wind Speed", f"{response['wind_speed']} m/s")
42
+ with col4:
43
+ st.image(response['icon_url'])
44
+
45
+ st.write(f"**Condition:** {response['condition']}")
46
+
47
+ forecast = response['forecast']
48
+ dates = [datetime.fromisoformat(f['datetime']).strftime("%d %b") for f in forecast]
49
+ temps = [f['temp'] for f in forecast]
50
+
51
+ fig = px.line(x=dates, y=temps, labels={"x": "Date", "y": "Temperature (°C)"},
52
+ title=f"5-Day Temperature Forecast for {city.title()}")
53
+ fig.update_layout(plot_bgcolor='rgba(0,0,0,0)',
54
+ paper_bgcolor='rgba(0,0,0,0)' if mode=='Dark' else 'white',
55
+ font_color='white' if mode=='Dark' else 'black')
56
+ st.plotly_chart(fig, use_container_width=True)