Spaces:
Sleeping
Sleeping
| 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") | |