Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import nltk
|
|
9 |
from nltk.tokenize import sent_tokenize
|
10 |
import torch
|
11 |
from fastapi import FastAPI
|
12 |
-
from fastapi.responses import RedirectResponse, FileResponse
|
13 |
from gtts import gTTS
|
14 |
import tempfile
|
15 |
import os
|
@@ -206,7 +206,7 @@ def summarize_document(file, summary_length: str, enable_tts: bool):
|
|
206 |
try:
|
207 |
summary = generate_summary(text, summary_length)
|
208 |
audio_path = text_to_speech(summary) if enable_tts else None
|
209 |
-
pdf_path = create_pdf(summary, original_filename)
|
210 |
return summary, "Summary complete", audio_path, pdf_path
|
211 |
except Exception as e:
|
212 |
return f"Summarization error: {str(e)}", "Error", None, None
|
@@ -243,6 +243,14 @@ with gr.Blocks(title="Document Summarizer", theme=gr.themes.Soft()) as demo:
|
|
243 |
def toggle_audio_visibility(enable_tts):
|
244 |
return gr.Audio(visible=enable_tts)
|
245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
tts_checkbox.change(
|
247 |
fn=toggle_audio_visibility,
|
248 |
inputs=tts_checkbox,
|
@@ -252,8 +260,11 @@ with gr.Blocks(title="Document Summarizer", theme=gr.themes.Soft()) as demo:
|
|
252 |
submit_btn.click(
|
253 |
fn=summarize_document,
|
254 |
inputs=[file_input, length_radio, tts_checkbox],
|
255 |
-
outputs=[output, status, audio_output, pdf_download]
|
256 |
-
|
|
|
|
|
|
|
257 |
)
|
258 |
|
259 |
# FastAPI endpoints for files
|
@@ -269,4 +280,4 @@ app = gr.mount_gradio_app(app, demo, path="/")
|
|
269 |
|
270 |
@app.get("/")
|
271 |
def redirect_to_interface():
|
272 |
-
return RedirectResponse(url="/")
|
|
|
9 |
from nltk.tokenize import sent_tokenize
|
10 |
import torch
|
11 |
from fastapi import FastAPI
|
12 |
+
from fastapi.responses import RedirectResponse, FileResponse, JSONResponse
|
13 |
from gtts import gTTS
|
14 |
import tempfile
|
15 |
import os
|
|
|
206 |
try:
|
207 |
summary = generate_summary(text, summary_length)
|
208 |
audio_path = text_to_speech(summary) if enable_tts else None
|
209 |
+
pdf_path = create_pdf(summary, original_filename) if summary else None
|
210 |
return summary, "Summary complete", audio_path, pdf_path
|
211 |
except Exception as e:
|
212 |
return f"Summarization error: {str(e)}", "Error", None, None
|
|
|
243 |
def toggle_audio_visibility(enable_tts):
|
244 |
return gr.Audio(visible=enable_tts)
|
245 |
|
246 |
+
def update_ui(summary, status, audio_path, pdf_path):
|
247 |
+
return (
|
248 |
+
summary,
|
249 |
+
status,
|
250 |
+
gr.Audio(visible=audio_path is not None, value=audio_path),
|
251 |
+
gr.File(visible=pdf_path is not None, value=pdf_path)
|
252 |
+
)
|
253 |
+
|
254 |
tts_checkbox.change(
|
255 |
fn=toggle_audio_visibility,
|
256 |
inputs=tts_checkbox,
|
|
|
260 |
submit_btn.click(
|
261 |
fn=summarize_document,
|
262 |
inputs=[file_input, length_radio, tts_checkbox],
|
263 |
+
outputs=[output, status, audio_output, pdf_download]
|
264 |
+
).then(
|
265 |
+
fn=update_ui,
|
266 |
+
inputs=[output, status, audio_output, pdf_download],
|
267 |
+
outputs=[output, status, audio_output, pdf_download]
|
268 |
)
|
269 |
|
270 |
# FastAPI endpoints for files
|
|
|
280 |
|
281 |
@app.get("/")
|
282 |
def redirect_to_interface():
|
283 |
+
return RedirectResponse(url="/")
|