File size: 2,376 Bytes
4560f00
 
 
d240213
4560f00
595fa2d
4560f00
cc33eb5
34412b4
d240213
4560f00
cc33eb5
98229e4
4560f00
cc33eb5
 
 
 
 
 
 
 
 
 
63a9734
 
 
cc33eb5
 
 
 
 
 
 
4560f00
 
34412b4
3958a7b
4560f00
 
 
 
 
 
 
 
 
 
 
 
3793282
cc33eb5
34412b4
4560f00
 
 
 
 
cc33eb5
34412b4
cc33eb5
63a9734
34412b4
bf8dd3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc33eb5
34412b4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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

# --- Hugging Face login ---
token = os.getenv("HF_TOKEN")
login(token=token)

# --- Load dataset ---
df = pd.DataFrame(load_dataset("SelmaNajih001/MapsData")["train"])

# --- Metric choices with friendly labels ---
metric_choices = {
    "busy_aprile": "April Busy",
    "busy_maggio": "May Busy",
    "StarsAprile_numeric": "April Stars",
    "StarsMaggio_numeric": "May Stars"
}

# --- Description from your thesis in English ---
description_text = """
This map was created using data collected from Google Maps.
The main objective was to monitor all the stores of a specific company in order to track customer traffic and gain some real-time insights into sales trends.
This approach can be easily replicated for any other company.
"""

# --- Function to update the map ---
def update_map(selected_label):
    # Map friendly label back to dataset column
    metric = {v: k for k, v in metric_choices.items()}[selected_label]

    fig = px.scatter_mapbox(
        df,
        lat="Lat",
        lon="Long",
        size=metric,
        color=metric,
        hover_name="Name",
        hover_data=[
            "busy_aprile",
            "busy_maggio",
            "Variazione",
            "StarsAprile_numeric",
            "StarsMaggio_numeric",
            "VariazioneStelle",
            "VariazionePercentuale"
        ],
        zoom=2,
        height=800,
        color_continuous_scale=px.colors.cyclical.IceFire
    )
    fig.update_layout(mapbox_style="open-street-map")
    fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
    return fig

# --- Gradio interface ---
with gr.Blocks() as demo:
    # Title
    gr.Markdown("<h1 style='text-align:center;color:#4B8BBE;'>Interactive Map</h1>")
    
    # Description at the top
    gr.Markdown(f"<p style='text-align:center;'>{description_text}</p>")

    # Dropdown centered below the description
    dropdown = gr.Dropdown(
        choices=list(metric_choices.values()),
        value="April Busy",
        label="Select Metric"
    )

    # Submit button
    submit_btn = gr.Button("Submit")

    # Map below the dropdown
    plot = gr.Plot()

    # Update map when button is clicked
    submit_btn.click(update_map, inputs=dropdown, outputs=plot)

demo.launch()