Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1395,27 +1395,27 @@ with gr.Blocks(title="Extractor de Facturas con IA Avanzada") as demo:
|
|
| 1395 |
texto_state = gr.State()
|
| 1396 |
|
| 1397 |
gr.Markdown("""
|
| 1398 |
-
#
|
| 1399 |
-
###
|
| 1400 |
""")
|
| 1401 |
|
| 1402 |
gr.Markdown("---")
|
| 1403 |
|
| 1404 |
with gr.Tabs():
|
| 1405 |
# ============= TAB 1: EXTRACCIÓN AUTOMÁTICA =============
|
| 1406 |
-
with gr.Tab("
|
| 1407 |
with gr.Row():
|
| 1408 |
with gr.Column(scale=1):
|
| 1409 |
-
gr.Markdown("###
|
| 1410 |
pdf_input = gr.File(label="Seleccionar factura PDF", file_types=[".pdf"], type="filepath")
|
| 1411 |
-
btn_extraer = gr.Button("
|
| 1412 |
|
| 1413 |
# Indicador de carga silencioso
|
| 1414 |
loading_extraccion = gr.HTML(visible=False, value="""
|
| 1415 |
<div style="text-align: center; padding: 20px;">
|
| 1416 |
<div class="spinner"></div>
|
| 1417 |
<p style="margin-top: 10px; color: #2196F3; font-weight: bold;">
|
| 1418 |
-
|
| 1419 |
</p>
|
| 1420 |
</div>
|
| 1421 |
<style>
|
|
@@ -1436,57 +1436,57 @@ with gr.Blocks(title="Extractor de Facturas con IA Avanzada") as demo:
|
|
| 1436 |
""")
|
| 1437 |
|
| 1438 |
gr.Markdown("---")
|
| 1439 |
-
gr.Markdown("###
|
| 1440 |
-
csv_output = gr.File(label="
|
| 1441 |
|
| 1442 |
gr.Markdown("---")
|
| 1443 |
-
gr.Markdown("###
|
| 1444 |
template_selector = gr.Radio(
|
| 1445 |
choices=["Clásico", "Moderno", "Elegante"],
|
| 1446 |
value="Moderno",
|
| 1447 |
label="Estilo de factura"
|
| 1448 |
)
|
| 1449 |
-
btn_generar_pdf = gr.Button("
|
| 1450 |
-
pdf_output = gr.File(label="
|
| 1451 |
pdf_status = gr.Textbox(label="Estado", interactive=False, lines=2)
|
| 1452 |
|
| 1453 |
with gr.Column(scale=2):
|
| 1454 |
-
gr.Markdown("###
|
| 1455 |
info_util = gr.Markdown(value="*Aquí aparecerá información relevante una vez procesada la factura*")
|
| 1456 |
gr.Markdown("---")
|
| 1457 |
with gr.Tabs():
|
| 1458 |
-
with gr.Tab("
|
| 1459 |
tabla_preview = gr.DataFrame(label="Datos estructurados en formato tabular", wrap=True)
|
| 1460 |
-
with gr.Tab("
|
| 1461 |
texto_extraido = gr.Textbox(label="Texto extraído del PDF", lines=18)
|
| 1462 |
-
with gr.Tab("
|
| 1463 |
resumen_tecnico = gr.Markdown(label="Estructura de datos y metadatos")
|
| 1464 |
|
| 1465 |
# ============= TAB 2: ASISTENTE IA CON VOZ Y AVATAR =============
|
| 1466 |
# ============= TAB 2: ASISTENTE IA CON ANÁLISIS EMOCIONAL =============
|
| 1467 |
-
with gr.Tab("
|
| 1468 |
gr.Markdown("""
|
| 1469 |
-
#
|
| 1470 |
-
### Pregúntale cualquier cosa sobre tu factura
|
| 1471 |
""")
|
| 1472 |
|
| 1473 |
with gr.Row():
|
| 1474 |
with gr.Column(scale=1):
|
| 1475 |
pregunta_ia = gr.Textbox(
|
| 1476 |
-
label="
|
| 1477 |
placeholder="Ejemplo: ¿Cuál es el total de esta factura?",
|
| 1478 |
value="¿Cuál es el total de esta factura y cuándo debería pagarla?",
|
| 1479 |
lines=4
|
| 1480 |
)
|
| 1481 |
|
| 1482 |
-
btn_consulta_ia = gr.Button("
|
| 1483 |
|
| 1484 |
# Indicador de carga
|
| 1485 |
loading_ia = gr.HTML(visible=False, value="""
|
| 1486 |
<div style="text-align: center; padding: 20px;">
|
| 1487 |
<div class="spinner-ia"></div>
|
| 1488 |
<p style="margin-top: 10px; color: #9C27B0; font-weight: bold;">
|
| 1489 |
-
|
| 1490 |
</p>
|
| 1491 |
</div>
|
| 1492 |
<style>
|
|
@@ -1503,7 +1503,7 @@ with gr.Blocks(title="Extractor de Facturas con IA Avanzada") as demo:
|
|
| 1503 |
""")
|
| 1504 |
|
| 1505 |
gr.Markdown("---")
|
| 1506 |
-
gr.Markdown("####
|
| 1507 |
gr.Markdown("""
|
| 1508 |
- ¿Cuál es el total de la factura?
|
| 1509 |
- ¿Qué es la base imponible?
|
|
@@ -1516,69 +1516,32 @@ with gr.Blocks(title="Extractor de Facturas con IA Avanzada") as demo:
|
|
| 1516 |
emocion_detectada = gr.Markdown(value="", visible=True)
|
| 1517 |
|
| 1518 |
with gr.Column(scale=2):
|
| 1519 |
-
gr.Markdown("###
|
| 1520 |
|
| 1521 |
-
|
| 1522 |
-
avatar_html = gr.HTML(value="""
|
| 1523 |
-
<div style="text-align: center; padding: 30px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 20px; margin-bottom: 20px;">
|
| 1524 |
-
<div class="robot-avatar" style="margin: 0 auto;">
|
| 1525 |
-
<svg width="120" height="120" viewBox="0 0 120 120">
|
| 1526 |
-
<!-- Cabeza del robot -->
|
| 1527 |
-
<rect x="30" y="35" width="60" height="50" rx="10" fill="#ffffff" stroke="#667eea" stroke-width="3"/>
|
| 1528 |
-
<!-- Antena -->
|
| 1529 |
-
<line x1="60" y1="35" x2="60" y2="20" stroke="#667eea" stroke-width="3"/>
|
| 1530 |
-
<circle cx="60" cy="15" r="5" fill="#764ba2"/>
|
| 1531 |
-
<!-- Ojos -->
|
| 1532 |
-
<circle cx="45" cy="55" r="6" fill="#667eea" class="eye-blink"/>
|
| 1533 |
-
<circle cx="75" cy="55" r="6" fill="#667eea" class="eye-blink"/>
|
| 1534 |
-
<!-- Boca -->
|
| 1535 |
-
<rect x="40" y="70" width="40" height="8" rx="4" fill="#667eea"/>
|
| 1536 |
-
</svg>
|
| 1537 |
-
</div>
|
| 1538 |
-
<p style="color: white; font-weight: bold; margin-top: 15px; font-size: 18px;">
|
| 1539 |
-
🤖 Asistente IA Listo
|
| 1540 |
-
</p>
|
| 1541 |
-
</div>
|
| 1542 |
-
<style>
|
| 1543 |
-
.eye-blink {
|
| 1544 |
-
animation: blink 3s infinite;
|
| 1545 |
-
}
|
| 1546 |
-
@keyframes blink {
|
| 1547 |
-
0%, 49%, 51%, 100% { opacity: 1; }
|
| 1548 |
-
50% { opacity: 0.3; }
|
| 1549 |
-
}
|
| 1550 |
-
</style>
|
| 1551 |
-
""")
|
| 1552 |
|
| 1553 |
-
gr.Markdown("###
|
| 1554 |
resultado_ia = gr.Markdown(
|
| 1555 |
value="*Haz una pregunta y el asistente te responderá aquí...*"
|
| 1556 |
)
|
| 1557 |
|
| 1558 |
gr.Markdown("---")
|
| 1559 |
-
gr.Markdown("###
|
| 1560 |
|
| 1561 |
with gr.Row():
|
| 1562 |
with gr.Column():
|
| 1563 |
audio_respuesta = gr.Audio(
|
| 1564 |
-
label="
|
| 1565 |
type="filepath",
|
| 1566 |
visible=True,
|
| 1567 |
autoplay=True
|
| 1568 |
)
|
| 1569 |
with gr.Column():
|
| 1570 |
transcripcion_output = gr.File(
|
| 1571 |
-
label="
|
| 1572 |
)
|
| 1573 |
|
| 1574 |
-
|
| 1575 |
-
💡 **Características mejoradas:**
|
| 1576 |
-
- 🎭 Análisis emocional del texto
|
| 1577 |
-
- 🎤 Voz sintetizada de alta calidad
|
| 1578 |
-
- 📝 Transcripción descargable en TXT
|
| 1579 |
-
- 🤖 Avatar interactivo que responde visualmente
|
| 1580 |
-
- 📊 Indicador de emoción detectada
|
| 1581 |
-
""")
|
| 1582 |
|
| 1583 |
# ============= TAB 3: HERRAMIENTAS IA AVANZADAS =============
|
| 1584 |
with gr.Tab("🔬 Análisis Avanzado IA"):
|
|
|
|
| 1395 |
texto_state = gr.State()
|
| 1396 |
|
| 1397 |
gr.Markdown("""
|
| 1398 |
+
# FACTULAB
|
| 1399 |
+
### Extrae datos de facturas PDF con IA, rápido y sin complicaciones.
|
| 1400 |
""")
|
| 1401 |
|
| 1402 |
gr.Markdown("---")
|
| 1403 |
|
| 1404 |
with gr.Tabs():
|
| 1405 |
# ============= TAB 1: EXTRACCIÓN AUTOMÁTICA =============
|
| 1406 |
+
with gr.Tab("Extracción Automática"):
|
| 1407 |
with gr.Row():
|
| 1408 |
with gr.Column(scale=1):
|
| 1409 |
+
gr.Markdown("### Subir Factura PDF")
|
| 1410 |
pdf_input = gr.File(label="Seleccionar factura PDF", file_types=[".pdf"], type="filepath")
|
| 1411 |
+
btn_extraer = gr.Button(" Extraer Datos de la Factura", variant="primary", size="lg")
|
| 1412 |
|
| 1413 |
# Indicador de carga silencioso
|
| 1414 |
loading_extraccion = gr.HTML(visible=False, value="""
|
| 1415 |
<div style="text-align: center; padding: 20px;">
|
| 1416 |
<div class="spinner"></div>
|
| 1417 |
<p style="margin-top: 10px; color: #2196F3; font-weight: bold;">
|
| 1418 |
+
Procesando tu factura...
|
| 1419 |
</p>
|
| 1420 |
</div>
|
| 1421 |
<style>
|
|
|
|
| 1436 |
""")
|
| 1437 |
|
| 1438 |
gr.Markdown("---")
|
| 1439 |
+
gr.Markdown("### Descarga tu factura en formato CSV")
|
| 1440 |
+
csv_output = gr.File(label="CSV Tabular (separado por comas)")
|
| 1441 |
|
| 1442 |
gr.Markdown("---")
|
| 1443 |
+
gr.Markdown("### Rediseña tu PDF con un template")
|
| 1444 |
template_selector = gr.Radio(
|
| 1445 |
choices=["Clásico", "Moderno", "Elegante"],
|
| 1446 |
value="Moderno",
|
| 1447 |
label="Estilo de factura"
|
| 1448 |
)
|
| 1449 |
+
btn_generar_pdf = gr.Button("Generar Factura PDF", variant="secondary", size="lg")
|
| 1450 |
+
pdf_output = gr.File(label="Descargar PDF generado")
|
| 1451 |
pdf_status = gr.Textbox(label="Estado", interactive=False, lines=2)
|
| 1452 |
|
| 1453 |
with gr.Column(scale=2):
|
| 1454 |
+
gr.Markdown("### ")
|
| 1455 |
info_util = gr.Markdown(value="*Aquí aparecerá información relevante una vez procesada la factura*")
|
| 1456 |
gr.Markdown("---")
|
| 1457 |
with gr.Tabs():
|
| 1458 |
+
with gr.Tab("Vista previa CSV"):
|
| 1459 |
tabla_preview = gr.DataFrame(label="Datos estructurados en formato tabular", wrap=True)
|
| 1460 |
+
with gr.Tab("Texto procesado de tu PDF"):
|
| 1461 |
texto_extraido = gr.Textbox(label="Texto extraído del PDF", lines=18)
|
| 1462 |
+
with gr.Tab("Más información"):
|
| 1463 |
resumen_tecnico = gr.Markdown(label="Estructura de datos y metadatos")
|
| 1464 |
|
| 1465 |
# ============= TAB 2: ASISTENTE IA CON VOZ Y AVATAR =============
|
| 1466 |
# ============= TAB 2: ASISTENTE IA CON ANÁLISIS EMOCIONAL =============
|
| 1467 |
+
with gr.Tab(" Pregunta a la IA sobre tu factura"):
|
| 1468 |
gr.Markdown("""
|
| 1469 |
+
# Modelo base IA
|
| 1470 |
+
### Pregúntale cualquier cosa sobre tu factura
|
| 1471 |
""")
|
| 1472 |
|
| 1473 |
with gr.Row():
|
| 1474 |
with gr.Column(scale=1):
|
| 1475 |
pregunta_ia = gr.Textbox(
|
| 1476 |
+
label="Tu pregunta ",
|
| 1477 |
placeholder="Ejemplo: ¿Cuál es el total de esta factura?",
|
| 1478 |
value="¿Cuál es el total de esta factura y cuándo debería pagarla?",
|
| 1479 |
lines=4
|
| 1480 |
)
|
| 1481 |
|
| 1482 |
+
btn_consulta_ia = gr.Button("Consultar", variant="primary", size="lg")
|
| 1483 |
|
| 1484 |
# Indicador de carga
|
| 1485 |
loading_ia = gr.HTML(visible=False, value="""
|
| 1486 |
<div style="text-align: center; padding: 20px;">
|
| 1487 |
<div class="spinner-ia"></div>
|
| 1488 |
<p style="margin-top: 10px; color: #9C27B0; font-weight: bold;">
|
| 1489 |
+
El asistente está analizando...
|
| 1490 |
</p>
|
| 1491 |
</div>
|
| 1492 |
<style>
|
|
|
|
| 1503 |
""")
|
| 1504 |
|
| 1505 |
gr.Markdown("---")
|
| 1506 |
+
gr.Markdown("#### Ejemplos de preguntas:")
|
| 1507 |
gr.Markdown("""
|
| 1508 |
- ¿Cuál es el total de la factura?
|
| 1509 |
- ¿Qué es la base imponible?
|
|
|
|
| 1516 |
emocion_detectada = gr.Markdown(value="", visible=True)
|
| 1517 |
|
| 1518 |
with gr.Column(scale=2):
|
| 1519 |
+
gr.Markdown("### ")
|
| 1520 |
|
| 1521 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1522 |
|
| 1523 |
+
gr.Markdown("### Respuesta a tu consulta")
|
| 1524 |
resultado_ia = gr.Markdown(
|
| 1525 |
value="*Haz una pregunta y el asistente te responderá aquí...*"
|
| 1526 |
)
|
| 1527 |
|
| 1528 |
gr.Markdown("---")
|
| 1529 |
+
gr.Markdown("### Lectura automática de la respuesta")
|
| 1530 |
|
| 1531 |
with gr.Row():
|
| 1532 |
with gr.Column():
|
| 1533 |
audio_respuesta = gr.Audio(
|
| 1534 |
+
label=" Reproducir respuesta en audio",
|
| 1535 |
type="filepath",
|
| 1536 |
visible=True,
|
| 1537 |
autoplay=True
|
| 1538 |
)
|
| 1539 |
with gr.Column():
|
| 1540 |
transcripcion_output = gr.File(
|
| 1541 |
+
label=" Descargar Transcripción (TXT)"
|
| 1542 |
)
|
| 1543 |
|
| 1544 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1545 |
|
| 1546 |
# ============= TAB 3: HERRAMIENTAS IA AVANZADAS =============
|
| 1547 |
with gr.Tab("🔬 Análisis Avanzado IA"):
|