Spaces:
Sleeping
Sleeping
Commit ·
b52be84
1
Parent(s): f5d6b69
feat(ui): add Gradio pagination demo and update status docs
Browse files- README.md +4 -0
- src/ui/app_factory.py +119 -1
README.md
CHANGED
|
@@ -45,3 +45,7 @@ Estrutura base criada por projeto/dataset:
|
|
| 45 |
- src/cache: cache efemero local
|
| 46 |
- cli: comandos de ingestao/publicacao
|
| 47 |
- tests: testes unitarios e integracao
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
- src/cache: cache efemero local
|
| 46 |
- cli: comandos de ingestao/publicacao
|
| 47 |
- tests: testes unitarios e integracao
|
| 48 |
+
|
| 49 |
+
## Estado atual de implementacao
|
| 50 |
+
- Sprint 1: CLI create-project, sync-audio, build-index, verify-project
|
| 51 |
+
- Sprint 2 (inicial): fila paginada de deteccoes com filtros basicos em demo local Gradio
|
src/ui/app_factory.py
CHANGED
|
@@ -1,9 +1,127 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def create_app() -> gr.Blocks:
|
|
|
|
|
|
|
| 5 |
with gr.Blocks(title="BirdNET Validator HF") as demo:
|
| 6 |
gr.Markdown("# BirdNET Validator HF")
|
| 7 |
-
gr.Markdown("Sprint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
return demo
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from src.domain.models import Detection
|
| 4 |
+
from src.repositories.in_memory_detection_repository import InMemoryDetectionRepository
|
| 5 |
+
from src.services.detection_queue_service import DetectionQueueService
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _seed_service() -> DetectionQueueService:
|
| 9 |
+
repo = InMemoryDetectionRepository()
|
| 10 |
+
demo_items = [
|
| 11 |
+
Detection(
|
| 12 |
+
detection_key="0000000000001001",
|
| 13 |
+
audio_id="audio_1001",
|
| 14 |
+
scientific_name="Cyanocorax cyanopogon",
|
| 15 |
+
confidence=0.93,
|
| 16 |
+
start_time=1.2,
|
| 17 |
+
end_time=2.5,
|
| 18 |
+
),
|
| 19 |
+
Detection(
|
| 20 |
+
detection_key="0000000000001002",
|
| 21 |
+
audio_id="audio_1002",
|
| 22 |
+
scientific_name="Ramphastos toco",
|
| 23 |
+
confidence=0.88,
|
| 24 |
+
start_time=0.8,
|
| 25 |
+
end_time=2.1,
|
| 26 |
+
),
|
| 27 |
+
Detection(
|
| 28 |
+
detection_key="0000000000001003",
|
| 29 |
+
audio_id="audio_1003",
|
| 30 |
+
scientific_name="Cyanocorax cyanopogon",
|
| 31 |
+
confidence=0.72,
|
| 32 |
+
start_time=3.1,
|
| 33 |
+
end_time=4.0,
|
| 34 |
+
),
|
| 35 |
+
Detection(
|
| 36 |
+
detection_key="0000000000001004",
|
| 37 |
+
audio_id="audio_1004",
|
| 38 |
+
scientific_name="Psarocolius decumanus",
|
| 39 |
+
confidence=0.67,
|
| 40 |
+
start_time=5.0,
|
| 41 |
+
end_time=6.3,
|
| 42 |
+
),
|
| 43 |
+
]
|
| 44 |
+
repo.seed("demo-project", demo_items)
|
| 45 |
+
return DetectionQueueService(repo)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _page_to_table(service: DetectionQueueService, page: int, scientific_name: str, min_confidence: float):
|
| 49 |
+
filter_name = scientific_name.strip() if scientific_name.strip() else None
|
| 50 |
+
page_obj = service.get_page(
|
| 51 |
+
project_slug="demo-project",
|
| 52 |
+
page=page,
|
| 53 |
+
page_size=2,
|
| 54 |
+
scientific_name=filter_name,
|
| 55 |
+
min_confidence=min_confidence,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
rows = [
|
| 59 |
+
[
|
| 60 |
+
item.detection_key,
|
| 61 |
+
item.audio_id,
|
| 62 |
+
item.scientific_name,
|
| 63 |
+
round(item.confidence, 3),
|
| 64 |
+
item.start_time,
|
| 65 |
+
item.end_time,
|
| 66 |
+
]
|
| 67 |
+
for item in page_obj.items
|
| 68 |
+
]
|
| 69 |
+
status = f"Pagina {page_obj.page}/{page_obj.total_pages} | Total filtrado: {page_obj.total_items}"
|
| 70 |
+
return rows, status, page_obj.page
|
| 71 |
+
|
| 72 |
|
| 73 |
def create_app() -> gr.Blocks:
|
| 74 |
+
service = _seed_service()
|
| 75 |
+
|
| 76 |
with gr.Blocks(title="BirdNET Validator HF") as demo:
|
| 77 |
gr.Markdown("# BirdNET Validator HF")
|
| 78 |
+
gr.Markdown("Sprint 2 kickoff: fila paginada de deteccoes (demo local).")
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
species_filter = gr.Textbox(label="Filtro especie", placeholder="Ex: Cyanocorax cyanopogon")
|
| 82 |
+
min_confidence = gr.Slider(label="Confianca minima", minimum=0.0, maximum=1.0, step=0.01, value=0.0)
|
| 83 |
+
|
| 84 |
+
with gr.Row():
|
| 85 |
+
prev_btn = gr.Button("Pagina anterior")
|
| 86 |
+
next_btn = gr.Button("Proxima pagina")
|
| 87 |
+
refresh_btn = gr.Button("Aplicar filtros")
|
| 88 |
+
|
| 89 |
+
page_state = gr.State(value=1)
|
| 90 |
+
table = gr.Dataframe(
|
| 91 |
+
headers=["detection_key", "audio_id", "scientific_name", "confidence", "start_time", "end_time"],
|
| 92 |
+
label="Deteccoes",
|
| 93 |
+
interactive=False,
|
| 94 |
+
)
|
| 95 |
+
status = gr.Textbox(label="Status", interactive=False)
|
| 96 |
+
|
| 97 |
+
def refresh(page: int, species: str, confidence: float):
|
| 98 |
+
return _page_to_table(service, page=page, scientific_name=species, min_confidence=confidence)
|
| 99 |
+
|
| 100 |
+
def go_next(page: int, species: str, confidence: float):
|
| 101 |
+
return refresh(page + 1, species, confidence)
|
| 102 |
+
|
| 103 |
+
def go_prev(page: int, species: str, confidence: float):
|
| 104 |
+
return refresh(max(1, page - 1), species, confidence)
|
| 105 |
+
|
| 106 |
+
demo.load(
|
| 107 |
+
fn=refresh,
|
| 108 |
+
inputs=[page_state, species_filter, min_confidence],
|
| 109 |
+
outputs=[table, status, page_state],
|
| 110 |
+
)
|
| 111 |
+
refresh_btn.click(
|
| 112 |
+
fn=lambda species, confidence: refresh(1, species, confidence),
|
| 113 |
+
inputs=[species_filter, min_confidence],
|
| 114 |
+
outputs=[table, status, page_state],
|
| 115 |
+
)
|
| 116 |
+
next_btn.click(
|
| 117 |
+
fn=go_next,
|
| 118 |
+
inputs=[page_state, species_filter, min_confidence],
|
| 119 |
+
outputs=[table, status, page_state],
|
| 120 |
+
)
|
| 121 |
+
prev_btn.click(
|
| 122 |
+
fn=go_prev,
|
| 123 |
+
inputs=[page_state, species_filter, min_confidence],
|
| 124 |
+
outputs=[table, status, page_state],
|
| 125 |
+
)
|
| 126 |
|
| 127 |
return demo
|