Spaces:
Sleeping
Sleeping
Commit ·
2b3cbf3
1
Parent(s): d20ce7e
feat(local): add native folder picker for segments path selection
Browse files- src/ui/upload_app_factory.py +31 -0
src/ui/upload_app_factory.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import json
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import zipfile
|
| 4 |
from pathlib import Path
|
|
@@ -38,6 +39,29 @@ def _resolve_segments_root(
|
|
| 38 |
return None, None
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def build_upload_app() -> gr.Blocks:
|
| 42 |
with gr.Blocks(title="BirdNET Segments Uploader") as demo:
|
| 43 |
gr.Markdown("# BirdNET Segments Uploader")
|
|
@@ -55,6 +79,7 @@ def build_upload_app() -> gr.Blocks:
|
|
| 55 |
label="Pasta raiz de segmentos",
|
| 56 |
placeholder=r"ex: C:\dados\BirdNET Segments",
|
| 57 |
)
|
|
|
|
| 58 |
segments_zip = gr.File(
|
| 59 |
label="ZIP da pasta de segmentos (use no Space)",
|
| 60 |
file_types=[".zip"],
|
|
@@ -195,6 +220,12 @@ def build_upload_app() -> gr.Blocks:
|
|
| 195 |
outputs=[status, result_json],
|
| 196 |
)
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
upload_button.click(
|
| 199 |
fn=run_upload,
|
| 200 |
inputs=[
|
|
|
|
| 1 |
import json
|
| 2 |
+
import os
|
| 3 |
import tempfile
|
| 4 |
import zipfile
|
| 5 |
from pathlib import Path
|
|
|
|
| 39 |
return None, None
|
| 40 |
|
| 41 |
|
| 42 |
+
def _pick_local_folder(current_value: str) -> tuple[str, str]:
|
| 43 |
+
if os.getenv("SPACE_ID"):
|
| 44 |
+
return current_value or "", "Selecao de pasta local indisponivel no Space. Use execucao local."
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
import tkinter as tk
|
| 48 |
+
from tkinter import filedialog
|
| 49 |
+
except Exception as exc:
|
| 50 |
+
return current_value or "", f"Nao foi possivel abrir seletor local: {exc}"
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
root = tk.Tk()
|
| 54 |
+
root.withdraw()
|
| 55 |
+
root.attributes("-topmost", True)
|
| 56 |
+
selected = filedialog.askdirectory(title="Selecione a pasta raiz de segmentos")
|
| 57 |
+
root.destroy()
|
| 58 |
+
if selected:
|
| 59 |
+
return selected, "Pasta local selecionada."
|
| 60 |
+
return current_value or "", "Selecao de pasta cancelada."
|
| 61 |
+
except Exception as exc:
|
| 62 |
+
return current_value or "", f"Erro ao selecionar pasta local: {exc}"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
def build_upload_app() -> gr.Blocks:
|
| 66 |
with gr.Blocks(title="BirdNET Segments Uploader") as demo:
|
| 67 |
gr.Markdown("# BirdNET Segments Uploader")
|
|
|
|
| 79 |
label="Pasta raiz de segmentos",
|
| 80 |
placeholder=r"ex: C:\dados\BirdNET Segments",
|
| 81 |
)
|
| 82 |
+
pick_segments_button = gr.Button("Selecionar pasta local", variant="secondary")
|
| 83 |
segments_zip = gr.File(
|
| 84 |
label="ZIP da pasta de segmentos (use no Space)",
|
| 85 |
file_types=[".zip"],
|
|
|
|
| 220 |
outputs=[status, result_json],
|
| 221 |
)
|
| 222 |
|
| 223 |
+
pick_segments_button.click(
|
| 224 |
+
fn=_pick_local_folder,
|
| 225 |
+
inputs=[segments_root],
|
| 226 |
+
outputs=[segments_root, status],
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
upload_button.click(
|
| 230 |
fn=run_upload,
|
| 231 |
inputs=[
|