Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import plotly.express as px | |
| import gradio as gr | |
| import os | |
| from huggingface_hub import login | |
| from datasets import load_dataset | |
| token = os.getenv("HF_TOKEN") # Legge il token da una variabile d'ambiente | |
| login(token=token) | |
| df_multi = pd.DataFrame(load_dataset("SelmaNajih001/MapsData")["train"]) | |
| # Funzione per aggiornare la mappa | |
| def update_map(metric): | |
| fig = px.scatter_mapbox( | |
| df, | |
| lat="Latitude", | |
| lon="Longitude", | |
| size=metric, | |
| color=metric, | |
| hover_name="Name", | |
| hover_data=[ | |
| "busy_aprile", | |
| "busy_maggio", | |
| "Variazione", | |
| "StarsAprile_numeric", | |
| "StarsMaggio_numeric", | |
| "VariazioneStelle", | |
| "VariazionePercentuale" | |
| ], | |
| zoom=10, | |
| height=600 | |
| ) | |
| fig.update_layout(mapbox_style="open-street-map") | |
| fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) | |
| return fig | |
| # Dropdown delle metriche | |
| dropdown = gr.Dropdown( | |
| choices=[ | |
| "busy_aprile", | |
| "Variazione", | |
| "VariazionePercentuale", | |
| "StarsAprile_numeric", | |
| "StarsMaggio_numeric", | |
| "VariazioneStelle" | |
| ], | |
| value="busy_aprile", | |
| label="Seleziona metrica" | |
| ) | |
| # Interfaccia Gradio | |
| interface = gr.Interface( | |
| fn=update_map, | |
| inputs=dropdown, | |
| outputs=gr.Plot() | |
| ) | |
| interface.launch() | |