Spaces:
Sleeping
Sleeping
Commit ·
b77c32b
1
Parent(s): 54ead58
Release 1.0.2: Critical fix for Windows exe entry point
Browse files## Critical Bug Fix
- Fixed: app.py now executes correctly in PyInstaller exe
- Issue: 'if __name__ == __main__:' block never runs in exe
- Solution: Removed guard, code runs on import
## Improvements
- Better error handling for 404 (dataset not found)
- Clear instructions when dataset doesn't exist
- Added test_imports.py for troubleshooting
- Windows exe shows status messages
## Changes
- app.py: Removed if __name__ guard, added logging
- web_ui.py: Better 404 error handling with instructions
- Added test_imports.py and debug.bat for debugging
- Updated .gitignore to exclude build artifacts
- .gitignore +1 -0
- app.py +29 -21
- debug.bat +36 -0
- src/uploader/web_ui.py +37 -16
- test_imports.py +96 -0
.gitignore
CHANGED
|
@@ -9,3 +9,4 @@ __pycache__/
|
|
| 9 |
dist/
|
| 10 |
build/release/
|
| 11 |
build/pyinstaller_uploader/
|
|
|
|
|
|
| 9 |
dist/
|
| 10 |
build/release/
|
| 11 |
build/pyinstaller_uploader/
|
| 12 |
+
app.zip
|
app.py
CHANGED
|
@@ -14,29 +14,37 @@ try:
|
|
| 14 |
from src.uploader.web_ui import create_uploader_app
|
| 15 |
from src.uploader.main import cli
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
logger.error(f"FATAL ERROR: {e}")
|
| 39 |
logger.error(traceback.format_exc())
|
| 40 |
-
print(f"\
|
| 41 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
sys.exit(1)
|
|
|
|
| 14 |
from src.uploader.web_ui import create_uploader_app
|
| 15 |
from src.uploader.main import cli
|
| 16 |
|
| 17 |
+
# Determine mode
|
| 18 |
+
cli_mode = os.getenv("BIRDNET_UPLOADER_CLI", "").lower() in ("1", "true", "yes")
|
| 19 |
+
has_args = len(sys.argv) > 1
|
| 20 |
+
|
| 21 |
+
logger.info(f"Mode detection: cli_mode={cli_mode}, has_args={has_args}, argv={sys.argv}")
|
| 22 |
+
|
| 23 |
+
if cli_mode or has_args:
|
| 24 |
+
# Run CLI
|
| 25 |
+
logger.info("Starting in CLI mode")
|
| 26 |
+
cli()
|
| 27 |
+
else:
|
| 28 |
+
# Run web UI
|
| 29 |
+
logger.info("Starting in Web UI mode")
|
| 30 |
+
app = create_uploader_app()
|
| 31 |
+
port = int(os.getenv("PORT") or os.getenv("BIRDNET_UPLOADER_PORT") or "7860")
|
| 32 |
+
host = os.getenv("BIRDNET_UPLOADER_HOST") or "0.0.0.0"
|
| 33 |
+
logger.info(f"Launching Gradio app on {host}:{port}")
|
| 34 |
+
print(f"\n{'='*60}")
|
| 35 |
+
print(f"BirdNET Uploader Web UI")
|
| 36 |
+
print(f"Opening browser at: http://localhost:{port}")
|
| 37 |
+
print(f"{'='*60}\n")
|
| 38 |
+
app.launch(server_name=host, server_port=port, show_error=True)
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
logger.error(f"FATAL ERROR: {e}")
|
| 42 |
logger.error(traceback.format_exc())
|
| 43 |
+
print(f"\n{'='*60}", file=sys.stderr)
|
| 44 |
+
print(f"ERROR: {e}", file=sys.stderr)
|
| 45 |
+
print(f"{'='*60}", file=sys.stderr)
|
| 46 |
+
print(f"Details:\n{traceback.format_exc()}", file=sys.stderr)
|
| 47 |
+
print(f"\nFor debugging, see: ~/.birdnet-uploader/logs/", file=sys.stderr)
|
| 48 |
+
print(f"Or run: python debug.bat", file=sys.stderr)
|
| 49 |
+
input("\nPress Enter to close...")
|
| 50 |
sys.exit(1)
|
debug.bat
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Debug script para capturar erros do BirdNET Uploader
|
| 3 |
+
REM Execute este arquivo para ver mensagens de erro
|
| 4 |
+
|
| 5 |
+
setlocal enabledelayedexpansion
|
| 6 |
+
|
| 7 |
+
cd /d "%~dp0"
|
| 8 |
+
|
| 9 |
+
echo.
|
| 10 |
+
echo ===============================================
|
| 11 |
+
echo BirdNET Uploader - DEBUG MODE
|
| 12 |
+
echo ===============================================
|
| 13 |
+
echo.
|
| 14 |
+
echo Tentando executar a aplicacao...
|
| 15 |
+
echo.
|
| 16 |
+
|
| 17 |
+
REM Tentar executar com Python diretamente (mais confiavel)
|
| 18 |
+
python -c "import sys; sys.path.insert(0, '.'); from app import *" 2>&1
|
| 19 |
+
set exitcode=!errorlevel!
|
| 20 |
+
|
| 21 |
+
if !exitcode! equ 0 (
|
| 22 |
+
echo.
|
| 23 |
+
echo SUCESSO: Aplicacao iniciada
|
| 24 |
+
echo.
|
| 25 |
+
) else (
|
| 26 |
+
echo.
|
| 27 |
+
echo ===============================================
|
| 28 |
+
echo ERRO: Falha ao iniciar (codigo: !exitcode!)
|
| 29 |
+
echo ===============================================
|
| 30 |
+
echo.
|
| 31 |
+
echo Tentando com traceback completo...
|
| 32 |
+
echo.
|
| 33 |
+
python app.py
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
pause
|
src/uploader/web_ui.py
CHANGED
|
@@ -149,14 +149,34 @@ def _handle_upload(token: str, repo_id: str, files, csv_file, remote_base: str,
|
|
| 149 |
api = HfApi(token=token)
|
| 150 |
repo_service = RepositoryService(token)
|
| 151 |
progress(0.2, desc="Validating repository...")
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
# Build scan summary from extracted/uploaded files
|
| 162 |
progress(0.3, desc="Scanning files...")
|
|
@@ -283,23 +303,24 @@ def create_uploader_app():
|
|
| 283 |
|
| 284 |
Para uploads maiores (>1 GB) ou melhor performance, baixe o executável portátil:
|
| 285 |
|
| 286 |
-
**[🔗 Download birdnet-uploader-1.0.
|
| 287 |
|
| 288 |
- **Tamanho**: ~109 MB (sem Python necessário)
|
| 289 |
- **Performance**: Upload ilimitado via CLI
|
| 290 |
-
- **Segurança**: Checksum disponível [aqui](https://huggingface.co/datasets/jrrribeiro/birdnet-uploader-releases/resolve/main/releases/v1.0.
|
| 291 |
- **Instruções**: [Setup Guide](https://github.com/jrrribeiro/BirdNET-Uploader-App/blob/main/WINDOWS_PORTABLE_SETUP.md)
|
|
|
|
| 292 |
|
| 293 |
### 📋 Checksum SHA256
|
| 294 |
```
|
| 295 |
-
|
| 296 |
```
|
| 297 |
|
| 298 |
-
### ⚡ Novidades na v1.0.
|
| 299 |
-
- ✅ Corrigido:
|
| 300 |
-
- ✅ Melhorado:
|
| 301 |
-
- ✅
|
| 302 |
-
- ✅ Adicionado:
|
| 303 |
""")
|
| 304 |
|
| 305 |
def _start(token_val, repo_val, files_val, csv_val, remote_base_val, workers_val, progress=gr.Progress()):
|
|
|
|
| 149 |
api = HfApi(token=token)
|
| 150 |
repo_service = RepositoryService(token)
|
| 151 |
progress(0.2, desc="Validating repository...")
|
| 152 |
+
|
| 153 |
+
try:
|
| 154 |
+
validation = repo_service.validate_repo(repo_id)
|
| 155 |
+
if not validation.get("is_valid"):
|
| 156 |
+
# attempt to create required structure
|
| 157 |
+
try:
|
| 158 |
+
repo_service.create_dataset(repo_id, private=True)
|
| 159 |
+
except Exception as e:
|
| 160 |
+
return (
|
| 161 |
+
f"⚠️ Could not validate/create dataset '{repo_id}'. "
|
| 162 |
+
f"Make sure the dataset exists at https://huggingface.co/datasets/{repo_id} "
|
| 163 |
+
f"or create it first. Error: {str(e)[:100]}",
|
| 164 |
+
None
|
| 165 |
+
)
|
| 166 |
+
except Exception as e:
|
| 167 |
+
error_msg = str(e)
|
| 168 |
+
if "404" in error_msg or "Repository Not Found" in error_msg:
|
| 169 |
+
return (
|
| 170 |
+
f"❌ Dataset not found: {repo_id}\n\n"
|
| 171 |
+
f"Please create it first:\n"
|
| 172 |
+
f"1. Go to https://huggingface.co/new-dataset\n"
|
| 173 |
+
f"2. Set Name: {repo_id.split('/')[-1]}\n"
|
| 174 |
+
f"3. Create the dataset\n"
|
| 175 |
+
f"4. Try uploading again",
|
| 176 |
+
None
|
| 177 |
+
)
|
| 178 |
+
else:
|
| 179 |
+
return f"Repository validation failed: {error_msg}", None
|
| 180 |
|
| 181 |
# Build scan summary from extracted/uploaded files
|
| 182 |
progress(0.3, desc="Scanning files...")
|
|
|
|
| 303 |
|
| 304 |
Para uploads maiores (>1 GB) ou melhor performance, baixe o executável portátil:
|
| 305 |
|
| 306 |
+
**[🔗 Download birdnet-uploader-1.0.2-windows.zip](https://huggingface.co/datasets/jrrribeiro/birdnet-uploader-releases/resolve/main/releases/v1.0.2/birdnet-uploader-1.0.2-windows.zip)**
|
| 307 |
|
| 308 |
- **Tamanho**: ~109 MB (sem Python necessário)
|
| 309 |
- **Performance**: Upload ilimitado via CLI
|
| 310 |
+
- **Segurança**: Checksum disponível [aqui](https://huggingface.co/datasets/jrrribeiro/birdnet-uploader-releases/resolve/main/releases/v1.0.2/birdnet-uploader-1.0.2-windows.zip.sha256)
|
| 311 |
- **Instruções**: [Setup Guide](https://github.com/jrrribeiro/BirdNET-Uploader-App/blob/main/WINDOWS_PORTABLE_SETUP.md)
|
| 312 |
+
- **Troubleshooting**: [Guide](https://github.com/jrrribeiro/BirdNET-Uploader-App/blob/main/TROUBLESHOOTING.md)
|
| 313 |
|
| 314 |
### 📋 Checksum SHA256
|
| 315 |
```
|
| 316 |
+
0a9e77a76c57f1200da3446dcbc4bc400b19e3f0a247d7826ee05c4032144753
|
| 317 |
```
|
| 318 |
|
| 319 |
+
### ⚡ Novidades na v1.0.2
|
| 320 |
+
- ✅ **CRÍTICO**: Corrigido: app.py agora executa corretamente no exe (removido if __name__)
|
| 321 |
+
- ✅ Melhorado: Erro 404 do dataset agora mostra instruções claras
|
| 322 |
+
- ✅ Melhorado: Mensagens de erro mais descritivas
|
| 323 |
+
- ✅ Adicionado: test_imports.py para diagnóstico
|
| 324 |
""")
|
| 325 |
|
| 326 |
def _start(token_val, repo_val, files_val, csv_val, remote_base_val, workers_val, progress=gr.Progress()):
|
test_imports.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test imports one by one to find the problematic module
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
|
| 9 |
+
print("=" * 60)
|
| 10 |
+
print("BirdNET Uploader - Import Test")
|
| 11 |
+
print("=" * 60)
|
| 12 |
+
print()
|
| 13 |
+
|
| 14 |
+
modules_to_test = [
|
| 15 |
+
("gradio", "gradio as gr"),
|
| 16 |
+
("huggingface_hub", "HfApi from huggingface_hub"),
|
| 17 |
+
("click", "click"),
|
| 18 |
+
("keyring", "keyring"),
|
| 19 |
+
("pathlib", "Path from pathlib"),
|
| 20 |
+
("tempfile", "tempfile"),
|
| 21 |
+
("shutil", "shutil"),
|
| 22 |
+
("tarfile", "tarfile"),
|
| 23 |
+
("zipfile", "zipfile"),
|
| 24 |
+
("pandas", "pandas"),
|
| 25 |
+
("pyarrow", "pyarrow"),
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
print("Testing standard library and external imports...\n")
|
| 29 |
+
|
| 30 |
+
all_ok = True
|
| 31 |
+
for module, desc in modules_to_test:
|
| 32 |
+
try:
|
| 33 |
+
__import__(module)
|
| 34 |
+
print(f"✅ {module:20s} - {desc}")
|
| 35 |
+
except ImportError as e:
|
| 36 |
+
print(f"❌ {module:20s} - {desc}")
|
| 37 |
+
print(f" Error: {e}")
|
| 38 |
+
all_ok = False
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"⚠️ {module:20s} - {desc}")
|
| 41 |
+
print(f" Error: {e}")
|
| 42 |
+
all_ok = False
|
| 43 |
+
|
| 44 |
+
print()
|
| 45 |
+
print("=" * 60)
|
| 46 |
+
print("Testing src modules...\n")
|
| 47 |
+
|
| 48 |
+
src_modules = [
|
| 49 |
+
"src.uploader.config",
|
| 50 |
+
"src.uploader.auth_service",
|
| 51 |
+
"src.uploader.scanner",
|
| 52 |
+
"src.uploader.deduplicator",
|
| 53 |
+
"src.uploader.batch_uploader",
|
| 54 |
+
"src.uploader.manifest",
|
| 55 |
+
"src.uploader.session_manager",
|
| 56 |
+
"src.uploader.web_ui",
|
| 57 |
+
"src.uploader.main",
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
for module in src_modules:
|
| 61 |
+
try:
|
| 62 |
+
__import__(module)
|
| 63 |
+
print(f"✅ {module}")
|
| 64 |
+
except ImportError as e:
|
| 65 |
+
print(f"❌ {module}")
|
| 66 |
+
print(f" Error: {e}")
|
| 67 |
+
all_ok = False
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"⚠️ {module}")
|
| 70 |
+
print(f" Error: {e}")
|
| 71 |
+
traceback.print_exc()
|
| 72 |
+
all_ok = False
|
| 73 |
+
|
| 74 |
+
print()
|
| 75 |
+
print("=" * 60)
|
| 76 |
+
if all_ok:
|
| 77 |
+
print("✅ All imports successful!")
|
| 78 |
+
print()
|
| 79 |
+
print("Attempting to create app...")
|
| 80 |
+
try:
|
| 81 |
+
from src.uploader.web_ui import create_uploader_app
|
| 82 |
+
app = create_uploader_app()
|
| 83 |
+
print("✅ App created successfully!")
|
| 84 |
+
print()
|
| 85 |
+
print("App details:")
|
| 86 |
+
print(f" Type: {type(app)}")
|
| 87 |
+
print(f" App: {app}")
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(f"❌ Failed to create app: {e}")
|
| 90 |
+
traceback.print_exc()
|
| 91 |
+
else:
|
| 92 |
+
print("❌ Some imports failed!")
|
| 93 |
+
sys.exit(1)
|
| 94 |
+
|
| 95 |
+
print()
|
| 96 |
+
print("=" * 60)
|