File size: 2,209 Bytes
0ce0464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr
import os
import sys

# Asegurar que se puede importar backend
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from services.summarization_service import SummarizationService
from services.tts_service import TTSService

# Directorio para audios temporales (creado en la raíz)
AUDIO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "audio")
if not os.path.exists(AUDIO_DIR):
    os.makedirs(AUDIO_DIR)

# Inicializar servicios
# Nota: Los modelos se descargarán la primera vez que se ejecute
print("Inicializando servicios de IA...")
summ_service = SummarizationService()
tts_service = TTSService(audio_output_dir=AUDIO_DIR)
print("Servicios listos.")

def process_text(text):
    if not text or not text.strip():
        return "Por favor, introduce un texto.", None
    
    try:
        print("Generando resumen...")
        summary = summ_service.summarize(text)
        
        print("Generando audio...")
        filename = tts_service.synthesize(summary)
        audio_path = os.path.join(AUDIO_DIR, filename)
        
        return summary, audio_path
    except Exception as e:
        return f"Error: {str(e)}", None

# CSS para corregir visualización del reproductor
custom_css = """

.timestamps {

    padding-top: 20px;

}

"""

# Interfaz Gradio
iface = gr.Interface(
    fn=process_text,
    inputs=gr.Textbox(
        lines=10, 
        placeholder="Pega aquí tu texto largo (apuntes, artículos, etc.)...", 
        label="Texto a Resumir"
    ),
    outputs=[
        gr.Textbox(label="Resumen Generado"),
        gr.Audio(label="Escuchar Resumen")
    ],
    title="Estudio Fácil - Resumidor y Lector",
    description="Herramienta de estudio que resume textos largos utilizando Inteligencia Artificial y los lee en voz alta. \n\n**Modelos utilizados:**\n- Resumen: `bert2bert-shared-spanish-finetuned-summarization` (con Micro-Chunking)\n- Voz: `facebook/mms-tts-spa`",
    flagging_mode="never",
    css=custom_css,
    submit_btn="Resumir",
    clear_btn="Limpiar"
)

if __name__ == "__main__":
    iface.launch(server_name="0.0.0.0", server_port=7860, theme="default")