xiddiqui commited on
Commit
bf0a0b6
·
1 Parent(s): bc608fe

updated app.py file, updated graphs

Browse files
Files changed (1) hide show
  1. app.py +19 -56
app.py CHANGED
@@ -3,70 +3,33 @@ import gradio as gr
3
  import pandas as pd
4
  import plotly.express as px
5
 
6
- # load the dataset
7
  ds = load_dataset("egecandrsn/weatherdata")
8
-
9
- # Convert the dataset into a pandas DataFrame
10
- df = pd.DataFrame(ds['train']) # Assuming the dataset has a 'train' split
11
-
12
- # Now you can modify the DataFrame
13
  df['datetime'] = pd.to_datetime(df['datetime'])
14
 
15
- # Function for generating temperature trends
16
- def generate_temperature_trends():
17
- df['year'] = df['datetime'].dt.year
18
- fig = px.line(df.groupby('year')['temp'].mean(), title='Average Temperature Over the Years')
19
- return fig
20
 
21
- # Function for generating precipitation trends
22
- def generate_precipitation_trends():
23
- df['year'] = df['datetime'].dt.year
24
- fig = px.bar(df.groupby('year')['precip'].sum(), title='Total Precipitation Over the Years')
25
- return fig
26
 
27
- # Function for generating wind speed trends
28
- def generate_wind_speed_trends():
29
- df['year'] = df['datetime'].dt.year
30
- fig = px.line(df.groupby('year')['windspeed'].mean(), title='Average Wind Speed Over the Years')
31
- return fig
32
 
33
- # Calculate Heat Index
34
- def calculate_heat_index():
35
- df['heat_index'] = df['temp'] + (0.55 - 0.55 * df['humidity'] / 100) * (df['temp'] - 58)
36
- fig = px.line(df.groupby('year')['heat_index'].mean(), title='Heat Index Over the Years')
37
- return fig
38
 
39
- # Gradio interface
40
  interface = gr.Interface(
41
- fn=generate_temperature_trends,
42
- inputs=[],
43
- outputs=gr.Plot(),
44
- title="Weather Analysis - Temperature Trends"
45
- )
46
-
47
- interface2 = gr.Interface(
48
- fn=generate_precipitation_trends,
49
- inputs=[],
50
- outputs=gr.Plot(),
51
- title="Weather Analysis - Precipitation Trends"
52
- )
53
-
54
- interface3 = gr.Interface(
55
- fn=generate_wind_speed_trends,
56
- inputs=[],
57
- outputs=gr.Plot(),
58
- title="Weather Analysis - Wind Speed Trends"
59
- )
60
-
61
- interface4 = gr.Interface(
62
- fn=calculate_heat_index,
63
- inputs=[],
64
- outputs=gr.Plot(),
65
- title="Weather Analysis - Heat Index Trends"
66
  )
67
 
68
  # Launch the interface
69
- interface.launch(share=True)
70
- interface2.launch(share=True)
71
- interface3.launch(share=True)
72
- interface4.launch(share=True)
 
3
  import pandas as pd
4
  import plotly.express as px
5
 
6
+ # Load dataset
7
  ds = load_dataset("egecandrsn/weatherdata")
8
+ df = pd.DataFrame(ds['train'])
 
 
 
 
9
  df['datetime'] = pd.to_datetime(df['datetime'])
10
 
11
+ # Create Graphs
12
+ def create_graphs():
13
+ # Temperature over Time
14
+ fig_temp = px.line(df, x='datetime', y='temp', title='Temperature Over Time')
 
15
 
16
+ # Precipitation over Time
17
+ fig_precip = px.line(df, x='datetime', y='precip', title='Precipitation Over Time')
 
 
 
18
 
19
+ # Wind Speed over Time
20
+ fig_wind = px.line(df, x='datetime', y='windspeed', title='Wind Speed Over Time')
 
 
 
21
 
22
+ # Return multiple graphs
23
+ return fig_temp, fig_precip, fig_wind
 
 
 
24
 
25
+ # Create Gradio interface
26
  interface = gr.Interface(
27
+ fn=create_graphs,
28
+ inputs=None, # No input required, as we are just displaying graphs
29
+ outputs=[gr.Plot(), gr.Plot(), gr.Plot()], # Multiple graph outputs
30
+ title="Weather Data Analysis",
31
+ description="This app shows multiple weather analysis graphs based on the dataset."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  )
33
 
34
  # Launch the interface
35
+ interface.launch()