Spaces:
Running
Running
feat(ui): add center mode toggle (city vs coordinates) to prepare lat/lon support
Browse files
app.py
CHANGED
|
@@ -43,11 +43,27 @@ def preset_to_distance(preset):
|
|
| 43 |
}.get(preset, None)
|
| 44 |
|
| 45 |
|
| 46 |
-
def generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
"""
|
| 48 |
Run the poster script and stream logs into the UI.
|
| 49 |
|
| 50 |
Note: tqdm progress can sit at 0% for a while, then jump to 33%/66%/100% (normal).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"""
|
| 52 |
POSTERS_DIR.mkdir(parents=True, exist_ok=True)
|
| 53 |
|
|
@@ -74,10 +90,17 @@ def generate(city, country, theme, preset, distance_m, fast_mode, map_format, or
|
|
| 74 |
"--orientation", orientation,
|
| 75 |
]
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
before = [str(p) for p in list_pngs()]
|
| 78 |
|
| 79 |
status_lines = []
|
| 80 |
status_lines.append("🚀 Starting… (OSM downloads can be slow on shared Spaces)")
|
|
|
|
| 81 |
status_lines.append(f"Command: {' '.join(cmd)}")
|
| 82 |
status_lines.append("Tip: if you see '0%|0/3' for a while, it may jump to 33% all at once.")
|
| 83 |
yield "\n".join(status_lines), None
|
|
@@ -127,12 +150,36 @@ def on_format_change(fmt):
|
|
| 127 |
return gr.update(interactive=True)
|
| 128 |
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
with gr.Blocks() as demo:
|
| 131 |
gr.Markdown("# MapToPoster – Hugging Face Demo")
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
with gr.Row():
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
with gr.Row():
|
| 138 |
theme = gr.Dropdown(
|
|
@@ -177,7 +224,7 @@ with gr.Blocks() as demo:
|
|
| 177 |
|
| 178 |
btn.click(
|
| 179 |
generate,
|
| 180 |
-
inputs=[city, country, theme, preset, distance, fast_mode, map_format, orientation],
|
| 181 |
outputs=[status, out],
|
| 182 |
)
|
| 183 |
|
|
|
|
| 43 |
}.get(preset, None)
|
| 44 |
|
| 45 |
|
| 46 |
+
def generate(
|
| 47 |
+
center_mode,
|
| 48 |
+
city,
|
| 49 |
+
country,
|
| 50 |
+
lat,
|
| 51 |
+
lon,
|
| 52 |
+
theme,
|
| 53 |
+
preset,
|
| 54 |
+
distance_m,
|
| 55 |
+
fast_mode,
|
| 56 |
+
map_format,
|
| 57 |
+
orientation,
|
| 58 |
+
):
|
| 59 |
"""
|
| 60 |
Run the poster script and stream logs into the UI.
|
| 61 |
|
| 62 |
Note: tqdm progress can sit at 0% for a while, then jump to 33%/66%/100% (normal).
|
| 63 |
+
|
| 64 |
+
IMPORTANT (for now):
|
| 65 |
+
- We still call the script using --city/--country.
|
| 66 |
+
- center_mode/lat/lon are UI-only for now (we'll wire them to --lat/--lon later).
|
| 67 |
"""
|
| 68 |
POSTERS_DIR.mkdir(parents=True, exist_ok=True)
|
| 69 |
|
|
|
|
| 90 |
"--orientation", orientation,
|
| 91 |
]
|
| 92 |
|
| 93 |
+
# UI-only note (until we wire lat/lon into the script)
|
| 94 |
+
if center_mode == "Coordinates":
|
| 95 |
+
cmd_note = f"Center: Coordinates (lat={lat}, lon={lon}) [UI-only for now]"
|
| 96 |
+
else:
|
| 97 |
+
cmd_note = f"Center: City ({city}, {country})"
|
| 98 |
+
|
| 99 |
before = [str(p) for p in list_pngs()]
|
| 100 |
|
| 101 |
status_lines = []
|
| 102 |
status_lines.append("🚀 Starting… (OSM downloads can be slow on shared Spaces)")
|
| 103 |
+
status_lines.append(cmd_note)
|
| 104 |
status_lines.append(f"Command: {' '.join(cmd)}")
|
| 105 |
status_lines.append("Tip: if you see '0%|0/3' for a while, it may jump to 33% all at once.")
|
| 106 |
yield "\n".join(status_lines), None
|
|
|
|
| 150 |
return gr.update(interactive=True)
|
| 151 |
|
| 152 |
|
| 153 |
+
def on_center_mode_change(mode):
|
| 154 |
+
"""Show lat/lon inputs only when Coordinates is selected."""
|
| 155 |
+
if mode == "Coordinates":
|
| 156 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|
| 157 |
+
# City mode
|
| 158 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
with gr.Blocks() as demo:
|
| 162 |
gr.Markdown("# MapToPoster – Hugging Face Demo")
|
| 163 |
|
| 164 |
+
center_mode = gr.Radio(
|
| 165 |
+
label="Center",
|
| 166 |
+
choices=["City", "Coordinates"],
|
| 167 |
+
value="City",
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
with gr.Row():
|
| 171 |
+
city = gr.Textbox(label="City", value="Paris", visible=True)
|
| 172 |
+
country = gr.Textbox(label="Country", value="France", visible=True)
|
| 173 |
+
|
| 174 |
with gr.Row():
|
| 175 |
+
lat = gr.Number(label="Latitude", value=48.8566, visible=False)
|
| 176 |
+
lon = gr.Number(label="Longitude", value=2.3522, visible=False)
|
| 177 |
+
|
| 178 |
+
center_mode.change(
|
| 179 |
+
on_center_mode_change,
|
| 180 |
+
inputs=[center_mode],
|
| 181 |
+
outputs=[city, country, lat, lon],
|
| 182 |
+
)
|
| 183 |
|
| 184 |
with gr.Row():
|
| 185 |
theme = gr.Dropdown(
|
|
|
|
| 224 |
|
| 225 |
btn.click(
|
| 226 |
generate,
|
| 227 |
+
inputs=[center_mode, city, country, lat, lon, theme, preset, distance, fast_mode, map_format, orientation],
|
| 228 |
outputs=[status, out],
|
| 229 |
)
|
| 230 |
|