Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,36 +2,17 @@ import dash
|
|
| 2 |
from dash import dcc, html, Input, Output
|
| 3 |
import plotly.graph_objs as go
|
| 4 |
import requests
|
| 5 |
-
from datetime import datetime
|
| 6 |
-
from
|
| 7 |
-
from weather_model import get_weather_data
|
| 8 |
|
| 9 |
# Initialize Dash app
|
| 10 |
app = dash.Dash(__name__)
|
| 11 |
app.title = "Weather Forecast Dashboard"
|
| 12 |
|
| 13 |
-
#
|
| 14 |
API_KEY = "53d50455f91b6bc3c920959e2954576d"
|
| 15 |
|
| 16 |
-
|
| 17 |
-
def index():
|
| 18 |
-
return render_template('index.html')
|
| 19 |
-
|
| 20 |
-
@app.route('/weather', methods=['GET'])
|
| 21 |
-
def weather():
|
| 22 |
-
city = request.args.get('city')
|
| 23 |
-
days = int(request.args.get('days', 5))
|
| 24 |
-
|
| 25 |
-
if not city:
|
| 26 |
-
return jsonify({'error': 'Please provide a city name'}), 400
|
| 27 |
-
|
| 28 |
-
weather_data = get_weather_data(city, days, API_KEY)
|
| 29 |
-
if not weather_data:
|
| 30 |
-
return jsonify({'error': 'City not found or API error'}), 404
|
| 31 |
-
|
| 32 |
-
return jsonify(weather_data)
|
| 33 |
-
|
| 34 |
-
# Layout with advanced UI
|
| 35 |
app.layout = html.Div([
|
| 36 |
html.Div([
|
| 37 |
html.H1("Weather Forecast Dashboard", style={'textAlign': 'center', 'color': '#FFFFFF'}),
|
|
@@ -93,7 +74,7 @@ def update_dashboard(n_clicks, city, days):
|
|
| 93 |
yaxis={'title': 'Temperature (°C)'}, template='plotly_dark')
|
| 94 |
}
|
| 95 |
|
| 96 |
-
# Precipitation Graph
|
| 97 |
precip = [d['precipitation'] for d in weather_data['forecast']]
|
| 98 |
precip_fig = {
|
| 99 |
'data': [go.Bar(x=dates, y=precip, name='Precipitation')],
|
|
|
|
| 2 |
from dash import dcc, html, Input, Output
|
| 3 |
import plotly.graph_objs as go
|
| 4 |
import requests
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from weather_model import get_weather_data # Assuming this file exists
|
|
|
|
| 7 |
|
| 8 |
# Initialize Dash app
|
| 9 |
app = dash.Dash(__name__)
|
| 10 |
app.title = "Weather Forecast Dashboard"
|
| 11 |
|
| 12 |
+
# Replace with your OpenWeatherMap API key
|
| 13 |
API_KEY = "53d50455f91b6bc3c920959e2954576d"
|
| 14 |
|
| 15 |
+
# Layout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
app.layout = html.Div([
|
| 17 |
html.Div([
|
| 18 |
html.H1("Weather Forecast Dashboard", style={'textAlign': 'center', 'color': '#FFFFFF'}),
|
|
|
|
| 74 |
yaxis={'title': 'Temperature (°C)'}, template='plotly_dark')
|
| 75 |
}
|
| 76 |
|
| 77 |
+
# Precipitation Graph
|
| 78 |
precip = [d['precipitation'] for d in weather_data['forecast']]
|
| 79 |
precip_fig = {
|
| 80 |
'data': [go.Bar(x=dates, y=precip, name='Precipitation')],
|