Spaces:
Runtime error
Runtime error
sara.mesquita commited on
Commit Β·
6241834
1
Parent(s): 2401678
UI ADJUSTS
Browse files
app.py
CHANGED
|
@@ -42,15 +42,10 @@ C_CARD = "#F4F4F0"
|
|
| 42 |
C_RED = "#E53935"
|
| 43 |
C_ORANGE = "#FB8C00"
|
| 44 |
|
| 45 |
-
# βββ Head HTML para carregar Γcones ββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
-
# Esta Γ© a forma correta de injetar bibliotecas externas no Gradio
|
| 47 |
-
HEAD_HTML = """
|
| 48 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous">
|
| 49 |
-
"""
|
| 50 |
-
|
| 51 |
# βββ CSS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 52 |
CSS = f"""
|
| 53 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
|
|
|
| 54 |
|
| 55 |
* {{ box-sizing: border-box; font-family: 'Inter', sans-serif; }}
|
| 56 |
|
|
@@ -59,7 +54,7 @@ CSS = f"""
|
|
| 59 |
max-width: 480px !important;
|
| 60 |
margin: 0 auto !important;
|
| 61 |
padding: 0 !important;
|
| 62 |
-
background: #f8f9fa !important;
|
| 63 |
min-height: 100dvh;
|
| 64 |
}}
|
| 65 |
|
|
@@ -184,7 +179,7 @@ footer {{ display: none !important; }}
|
|
| 184 |
border: 1px solid #eaeaea !important;
|
| 185 |
display: flex;
|
| 186 |
flex-direction: column;
|
| 187 |
-
gap: 20px;
|
| 188 |
}}
|
| 189 |
.reg-label {{
|
| 190 |
font-size: 14px;
|
|
@@ -261,7 +256,6 @@ footer {{ display: none !important; }}
|
|
| 261 |
}}
|
| 262 |
#status-card.ok {{ background: #e8f5e9; color: #2e7d32; border-left: 4px solid {C_GREEN}; padding: 14px 16px; }}
|
| 263 |
#status-card.err {{ background: #ffebee; color: #b71c1c; border-left: 4px solid {C_RED}; padding: 14px 16px; }}
|
| 264 |
-
|
| 265 |
/* GPS box */
|
| 266 |
#gps-box {{
|
| 267 |
display: flex;
|
|
@@ -274,6 +268,10 @@ footer {{ display: none !important; }}
|
|
| 274 |
color: #2e7d32;
|
| 275 |
font-weight: 500;
|
| 276 |
border: 1px solid #c8e6c9;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
}}
|
| 278 |
|
| 279 |
/* Animals list */
|
|
@@ -319,42 +317,81 @@ footer {{ display: none !important; }}
|
|
| 319 |
}}
|
| 320 |
"""
|
| 321 |
|
|
|
|
| 322 |
# βββ GPS JavaScript βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 323 |
GPS_HTML = """
|
| 324 |
<div id="gps-box">
|
| 325 |
-
<span id="gps-icon" style="font-size:18px"><i class="fa-solid fa-location-
|
| 326 |
-
<span id="gps-text">
|
| 327 |
</div>
|
| 328 |
<script>
|
| 329 |
(function() {
|
|
|
|
|
|
|
| 330 |
var icon = document.getElementById('gps-icon');
|
| 331 |
var text = document.getElementById('gps-text');
|
|
|
|
| 332 |
function setCoords(coords) {
|
|
|
|
| 333 |
var tb = document.querySelector('#gps-coords textarea');
|
| 334 |
if (tb) {
|
| 335 |
var nativeSet = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set;
|
| 336 |
nativeSet.call(tb, JSON.stringify(coords));
|
| 337 |
tb.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
}
|
|
|
|
|
|
|
| 340 |
if (!navigator.geolocation) {
|
|
|
|
| 341 |
icon.innerHTML = '<i class="fa-solid fa-triangle-exclamation"></i>';
|
| 342 |
-
text.textContent = 'GPS
|
| 343 |
return;
|
| 344 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
navigator.geolocation.getCurrentPosition(
|
| 346 |
function(pos) {
|
|
|
|
| 347 |
var lat = parseFloat(pos.coords.latitude.toFixed(5));
|
| 348 |
var lng = parseFloat(pos.coords.longitude.toFixed(5));
|
| 349 |
-
icon.innerHTML = '<i class="fa-solid fa-
|
| 350 |
-
text.
|
| 351 |
setCoords({ lat: lat, lng: lng });
|
| 352 |
},
|
| 353 |
function(err) {
|
|
|
|
| 354 |
icon.innerHTML = '<i class="fa-solid fa-triangle-exclamation"></i>';
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
},
|
| 357 |
-
|
| 358 |
);
|
| 359 |
})();
|
| 360 |
</script>
|
|
@@ -544,7 +581,7 @@ def get_stats_html():
|
|
| 544 |
|
| 545 |
|
| 546 |
# βββ Gradio app βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 547 |
-
with gr.Blocks(css=CSS,
|
| 548 |
|
| 549 |
# Top bar
|
| 550 |
gr.HTML(
|
|
|
|
| 42 |
C_RED = "#E53935"
|
| 43 |
C_ORANGE = "#FB8C00"
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# βββ CSS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
CSS = f"""
|
| 47 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
| 48 |
+
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
|
| 49 |
|
| 50 |
* {{ box-sizing: border-box; font-family: 'Inter', sans-serif; }}
|
| 51 |
|
|
|
|
| 54 |
max-width: 480px !important;
|
| 55 |
margin: 0 auto !important;
|
| 56 |
padding: 0 !important;
|
| 57 |
+
background: #f8f9fa !important; /* Fundo levemente cinza para destacar os cards */
|
| 58 |
min-height: 100dvh;
|
| 59 |
}}
|
| 60 |
|
|
|
|
| 179 |
border: 1px solid #eaeaea !important;
|
| 180 |
display: flex;
|
| 181 |
flex-direction: column;
|
| 182 |
+
gap: 20px; /* EspaΓ§amento entre os passos */
|
| 183 |
}}
|
| 184 |
.reg-label {{
|
| 185 |
font-size: 14px;
|
|
|
|
| 256 |
}}
|
| 257 |
#status-card.ok {{ background: #e8f5e9; color: #2e7d32; border-left: 4px solid {C_GREEN}; padding: 14px 16px; }}
|
| 258 |
#status-card.err {{ background: #ffebee; color: #b71c1c; border-left: 4px solid {C_RED}; padding: 14px 16px; }}
|
|
|
|
| 259 |
/* GPS box */
|
| 260 |
#gps-box {{
|
| 261 |
display: flex;
|
|
|
|
| 268 |
color: #2e7d32;
|
| 269 |
font-weight: 500;
|
| 270 |
border: 1px solid #c8e6c9;
|
| 271 |
+
transition: all 0.3s ease;
|
| 272 |
+
}}
|
| 273 |
+
#gps-box i.fa-pulse {{
|
| 274 |
+
animation: fa-pulse 1s infinite;
|
| 275 |
}}
|
| 276 |
|
| 277 |
/* Animals list */
|
|
|
|
| 317 |
}}
|
| 318 |
"""
|
| 319 |
|
| 320 |
+
# βββ GPS JavaScript βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 321 |
# βββ GPS JavaScript βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 322 |
GPS_HTML = """
|
| 323 |
<div id="gps-box">
|
| 324 |
+
<span id="gps-icon" style="font-size:18px"><i class="fa-solid fa-location-crosshairs fa-pulse"></i></span>
|
| 325 |
+
<span id="gps-text">Requesting location permission...</span>
|
| 326 |
</div>
|
| 327 |
<script>
|
| 328 |
(function() {
|
| 329 |
+
console.log('GPS script loaded');
|
| 330 |
+
|
| 331 |
var icon = document.getElementById('gps-icon');
|
| 332 |
var text = document.getElementById('gps-text');
|
| 333 |
+
|
| 334 |
function setCoords(coords) {
|
| 335 |
+
console.log('Setting coords:', coords);
|
| 336 |
var tb = document.querySelector('#gps-coords textarea');
|
| 337 |
if (tb) {
|
| 338 |
var nativeSet = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set;
|
| 339 |
nativeSet.call(tb, JSON.stringify(coords));
|
| 340 |
tb.dispatchEvent(new Event('input', { bubbles: true }));
|
| 341 |
+
console.log('Coords set successfully');
|
| 342 |
+
} else {
|
| 343 |
+
console.error('GPS coords textarea not found');
|
| 344 |
}
|
| 345 |
}
|
| 346 |
+
|
| 347 |
+
// Verificar se geolocation estΓ‘ disponΓvel
|
| 348 |
if (!navigator.geolocation) {
|
| 349 |
+
console.error('Geolocation not supported');
|
| 350 |
icon.innerHTML = '<i class="fa-solid fa-triangle-exclamation"></i>';
|
| 351 |
+
text.textContent = 'GPS nΓ£o disponΓvel neste navegador.';
|
| 352 |
return;
|
| 353 |
}
|
| 354 |
+
|
| 355 |
+
console.log('Requesting geolocation...');
|
| 356 |
+
|
| 357 |
+
// OpΓ§Γ΅es mais agressivas para forΓ§ar o pedido de permissΓ£o
|
| 358 |
+
var options = {
|
| 359 |
+
enableHighAccuracy: true,
|
| 360 |
+
timeout: 15000,
|
| 361 |
+
maximumAge: 0 // ForΓ§a nova requisiΓ§Γ£o sempre
|
| 362 |
+
};
|
| 363 |
+
|
| 364 |
navigator.geolocation.getCurrentPosition(
|
| 365 |
function(pos) {
|
| 366 |
+
console.log('Position obtained:', pos);
|
| 367 |
var lat = parseFloat(pos.coords.latitude.toFixed(5));
|
| 368 |
var lng = parseFloat(pos.coords.longitude.toFixed(5));
|
| 369 |
+
icon.innerHTML = '<i class="fa-solid fa-location-dot"></i>';
|
| 370 |
+
text.innerHTML = '<i class="fa-solid fa-check"></i> LocalizaΓ§Γ£o: ' + lat + ', ' + lng;
|
| 371 |
setCoords({ lat: lat, lng: lng });
|
| 372 |
},
|
| 373 |
function(err) {
|
| 374 |
+
console.error('Geolocation error:', err.code, err.message);
|
| 375 |
icon.innerHTML = '<i class="fa-solid fa-triangle-exclamation"></i>';
|
| 376 |
+
|
| 377 |
+
// Mensagens mais especΓficas para cada tipo de erro
|
| 378 |
+
if (err.code === 1) {
|
| 379 |
+
// PERMISSION_DENIED
|
| 380 |
+
text.innerHTML = '<i class="fa-solid fa-xmark"></i> PermissΓ£o negada. Por favor, habilite a localizaΓ§Γ£o nas configuraΓ§Γ΅es do navegador.';
|
| 381 |
+
} else if (err.code === 2) {
|
| 382 |
+
// POSITION_UNAVAILABLE
|
| 383 |
+
text.innerHTML = '<i class="fa-solid fa-xmark"></i> LocalizaΓ§Γ£o indisponΓvel. Verifique se o GPS estΓ‘ ativo.';
|
| 384 |
+
} else if (err.code === 3) {
|
| 385 |
+
// TIMEOUT
|
| 386 |
+
text.innerHTML = '<i class="fa-solid fa-clock"></i> Tempo esgotado ao buscar localizaΓ§Γ£o. Tente novamente.';
|
| 387 |
+
} else {
|
| 388 |
+
text.innerHTML = '<i class="fa-solid fa-xmark"></i> Erro ao obter localizaΓ§Γ£o: ' + err.message;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
// Registra mesmo sem GPS (com coordenadas vazias)
|
| 392 |
+
setCoords({});
|
| 393 |
},
|
| 394 |
+
options
|
| 395 |
);
|
| 396 |
})();
|
| 397 |
</script>
|
|
|
|
| 581 |
|
| 582 |
|
| 583 |
# βββ Gradio app βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 584 |
+
with gr.Blocks(css=CSS, theme=gr.themes.Base(), title="Spotted Animal") as demo:
|
| 585 |
|
| 586 |
# Top bar
|
| 587 |
gr.HTML(
|