Spaces:
Sleeping
Sleeping
updated app.py code
Browse files
app.py
CHANGED
@@ -1,17 +1,73 @@
|
|
1 |
-
# Install necessary packages
|
2 |
-
# !pip install datasets pandas
|
3 |
-
|
4 |
from datasets import load_dataset
|
|
|
5 |
import pandas as pd
|
|
|
|
|
6 |
|
7 |
# Load the dataset from Hugging Face
|
8 |
ds = load_dataset("egecandrsn/weatherdata")
|
9 |
|
10 |
# Access the 'train' split
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from datasets import load_dataset
|
2 |
+
import gradio as gr
|
3 |
import pandas as pd
|
4 |
+
import plotly.express as px
|
5 |
+
|
6 |
|
7 |
# Load the dataset from Hugging Face
|
8 |
ds = load_dataset("egecandrsn/weatherdata")
|
9 |
|
10 |
# Access the 'train' split
|
11 |
+
df = ds['train']
|
12 |
+
|
13 |
+
# Convert datetime to datetime format
|
14 |
+
df['datetime'] = pd.to_datetime(df['datetime'])
|
15 |
+
|
16 |
+
# Function for generating temperature trends
|
17 |
+
def generate_temperature_trends():
|
18 |
+
df['year'] = df['datetime'].dt.year
|
19 |
+
fig = px.line(df.groupby('year')['temp'].mean(), title='Average Temperature Over the Years')
|
20 |
+
return fig
|
21 |
+
|
22 |
+
# Function for generating precipitation trends
|
23 |
+
def generate_precipitation_trends():
|
24 |
+
df['year'] = df['datetime'].dt.year
|
25 |
+
fig = px.bar(df.groupby('year')['precip'].sum(), title='Total Precipitation Over the Years')
|
26 |
+
return fig
|
27 |
+
|
28 |
+
# Function for generating wind speed trends
|
29 |
+
def generate_wind_speed_trends():
|
30 |
+
df['year'] = df['datetime'].dt.year
|
31 |
+
fig = px.line(df.groupby('year')['windspeed'].mean(), title='Average Wind Speed Over the Years')
|
32 |
+
return fig
|
33 |
+
|
34 |
+
# Calculate Heat Index
|
35 |
+
def calculate_heat_index():
|
36 |
+
df['heat_index'] = df['temp'] + (0.55 - 0.55 * df['humidity'] / 100) * (df['temp'] - 58)
|
37 |
+
fig = px.line(df.groupby('year')['heat_index'].mean(), title='Heat Index Over the Years')
|
38 |
+
return fig
|
39 |
+
|
40 |
+
# Gradio interface
|
41 |
+
interface = gr.Interface(
|
42 |
+
fn=generate_temperature_trends,
|
43 |
+
inputs=[],
|
44 |
+
outputs=gr.Plot(),
|
45 |
+
title="Weather Analysis - Temperature Trends"
|
46 |
+
)
|
47 |
+
|
48 |
+
interface2 = gr.Interface(
|
49 |
+
fn=generate_precipitation_trends,
|
50 |
+
inputs=[],
|
51 |
+
outputs=gr.Plot(),
|
52 |
+
title="Weather Analysis - Precipitation Trends"
|
53 |
+
)
|
54 |
+
|
55 |
+
interface3 = gr.Interface(
|
56 |
+
fn=generate_wind_speed_trends,
|
57 |
+
inputs=[],
|
58 |
+
outputs=gr.Plot(),
|
59 |
+
title="Weather Analysis - Wind Speed Trends"
|
60 |
+
)
|
61 |
|
62 |
+
interface4 = gr.Interface(
|
63 |
+
fn=calculate_heat_index,
|
64 |
+
inputs=[],
|
65 |
+
outputs=gr.Plot(),
|
66 |
+
title="Weather Analysis - Heat Index Trends"
|
67 |
+
)
|
68 |
|
69 |
+
# Launch the interface
|
70 |
+
interface.launch(share=True)
|
71 |
+
interface2.launch(share=True)
|
72 |
+
interface3.launch(share=True)
|
73 |
+
interface4.launch(share=True)
|