SelmaNajih001 commited on
Commit
34412b4
·
verified ·
1 Parent(s): 98229e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -26
app.py CHANGED
@@ -5,7 +5,8 @@ import os
5
  from huggingface_hub import login
6
  from datasets import load_dataset
7
 
8
- token = os.getenv("HF_TOKEN") # Legge il token da una variabile d'ambiente
 
9
  login(token=token)
10
 
11
  df = pd.DataFrame(load_dataset("SelmaNajih001/MapsData")["train"])
@@ -14,8 +15,8 @@ df = pd.DataFrame(load_dataset("SelmaNajih001/MapsData")["train"])
14
  def update_map(metric):
15
  fig = px.scatter_mapbox(
16
  df,
17
- lat="Latitude",
18
- lon="Longitude",
19
  size=metric,
20
  color=metric,
21
  hover_name="Name",
@@ -29,32 +30,38 @@ def update_map(metric):
29
  "VariazionePercentuale"
30
  ],
31
  zoom=10,
32
- height=600
 
33
  )
34
  fig.update_layout(mapbox_style="open-street-map")
35
  fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
36
  return fig
37
 
38
- # Dropdown delle metriche
39
- dropdown = gr.Dropdown(
40
- choices=[
41
- "busy_aprile",
42
- "Variazione",
43
- "VariazionePercentuale",
44
- "StarsAprile_numeric",
45
- "StarsMaggio_numeric",
46
- "VariazioneStelle"
47
- ],
48
- value="busy_aprile",
49
- label="Seleziona metrica"
50
- )
51
-
52
- # Interfaccia Gradio
53
- interface = gr.Interface(
54
- fn=update_map,
55
- inputs=dropdown,
56
- outputs=gr.Plot()
57
- )
58
-
59
- interface.launch()
 
 
 
 
 
60
 
 
5
  from huggingface_hub import login
6
  from datasets import load_dataset
7
 
8
+ # Login Hugging Face
9
+ token = os.getenv("HF_TOKEN")
10
  login(token=token)
11
 
12
  df = pd.DataFrame(load_dataset("SelmaNajih001/MapsData")["train"])
 
15
  def update_map(metric):
16
  fig = px.scatter_mapbox(
17
  df,
18
+ lat="Lat",
19
+ lon="Lon",
20
  size=metric,
21
  color=metric,
22
  hover_name="Name",
 
30
  "VariazionePercentuale"
31
  ],
32
  zoom=10,
33
+ height=800, # Mappa più grande
34
+ color_continuous_scale=px.colors.cyclical.IceFire
35
  )
36
  fig.update_layout(mapbox_style="open-street-map")
37
  fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
38
  return fig
39
 
40
+ # Interfaccia Gradio con grande mappa
41
+ with gr.Blocks() as demo:
42
+ gr.Markdown("<h1 style='text-align:center;color:#4B8BBE;'>Mappa Interattiva dei Dati</h1>")
43
+ gr.Markdown("<p style='text-align:center;'>Seleziona la metrica dal dropdown per aggiornare la mappa</p>")
44
+
45
+ with gr.Row():
46
+ with gr.Column(scale=1):
47
+ dropdown = gr.Dropdown(
48
+ choices=[
49
+ "busy_aprile",
50
+ "Variazione",
51
+ "VariazionePercentuale",
52
+ "StarsAprile_numeric",
53
+ "StarsMaggio_numeric",
54
+ "VariazioneStelle"
55
+ ],
56
+ value="busy_aprile",
57
+ label="Seleziona metrica"
58
+ )
59
+ with gr.Column(scale=4):
60
+ plot = gr.Plot()
61
+
62
+ # Aggiorna mappa quando il dropdown cambia
63
+ dropdown.change(update_map, inputs=dropdown, outputs=plot)
64
+
65
+ demo.launch()
66
+
67