Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,6 +66,9 @@ def fetch_and_display_content(url):
|
|
66 |
text = extract(downloaded, output_format="markdown", with_metadata=True, include_tables=False, include_links=False, include_formatting=True, include_comments=False) #without metadata extraction
|
67 |
metadata, cleaned_text = extract_and_clean_text(text)
|
68 |
detected_lang = detect_language(cleaned_text)
|
|
|
|
|
|
|
69 |
|
70 |
# Add detected language to metadata
|
71 |
metadata["Detected Language"] = detected_lang.upper()
|
@@ -300,13 +303,13 @@ with gr.Blocks() as demo:
|
|
300 |
url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com/article")
|
301 |
|
302 |
voice_selection = gr.Dropdown(AVAILABLE_VOICES, label="Select Voice", value="af_bella")
|
|
|
303 |
with gr.Row():
|
304 |
process_text_button = gr.Button("Fetch Text & Detect Language",scale = 1)
|
305 |
-
process_summary_button = gr.Button("Summarize Text", visible=False,scale = 1)
|
306 |
process_audio_button = gr.Button("Generate Audio", visible=False,scale = 1)
|
307 |
process_ner_button = gr.Button("Extract Entities", visible=False,scale = 1) # ✅ New button for NER
|
308 |
|
309 |
-
|
310 |
with gr.Row():
|
311 |
extracted_text = gr.Textbox(label="Extracted Content", visible=False, interactive=False, lines=15)
|
312 |
metadata_output = gr.JSON(label="Article Metadata", visible=False) # Displays metadata
|
@@ -317,7 +320,7 @@ with gr.Blocks() as demo:
|
|
317 |
summary_output = gr.Textbox(label="Summary", visible=True, interactive=False)
|
318 |
full_audio_output = gr.Audio(label="Generated Audio", visible=True)
|
319 |
ner_output = gr.Textbox(label="Extracted Entities", visible=True, interactive=False)
|
320 |
-
|
321 |
|
322 |
#Add textboxes for default and custom entity types
|
323 |
default_entity_types = gr.Textbox(label="Default Entity Types", value="PERSON, Organization, location, Date, PRODUCT, EVENT", interactive=True)
|
@@ -328,7 +331,7 @@ with gr.Blocks() as demo:
|
|
328 |
fetch_and_display_content,
|
329 |
inputs=[url_input],
|
330 |
|
331 |
-
outputs=[extracted_text, metadata_output, detected_lang,
|
332 |
)
|
333 |
|
334 |
# Automatically generate word cloud when extracted_text changes
|
@@ -339,12 +342,14 @@ with gr.Blocks() as demo:
|
|
339 |
show_progress=True
|
340 |
)
|
341 |
|
342 |
-
process_summary_button.click(hierarchical_summarization, inputs=[extracted_text], outputs=[summary_output])
|
343 |
|
344 |
# Step 2: Generate Audio After Text & Language Are Displayed
|
345 |
-
|
346 |
-
|
347 |
-
|
|
|
|
|
348 |
outputs=[full_audio_output]
|
349 |
)
|
350 |
|
|
|
66 |
text = extract(downloaded, output_format="markdown", with_metadata=True, include_tables=False, include_links=False, include_formatting=True, include_comments=False) #without metadata extraction
|
67 |
metadata, cleaned_text = extract_and_clean_text(text)
|
68 |
detected_lang = detect_language(cleaned_text)
|
69 |
+
|
70 |
+
# Generate Summary Automatically
|
71 |
+
summary_text = hierarchical_summarization(cleaned_text)
|
72 |
|
73 |
# Add detected language to metadata
|
74 |
metadata["Detected Language"] = detected_lang.upper()
|
|
|
303 |
url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com/article")
|
304 |
|
305 |
voice_selection = gr.Dropdown(AVAILABLE_VOICES, label="Select Voice", value="af_bella")
|
306 |
+
tts_option = gr.Radio(["Summary Audio", "Raw Data Audio"], value="Summary Audio", label="Select TTS Source")
|
307 |
with gr.Row():
|
308 |
process_text_button = gr.Button("Fetch Text & Detect Language",scale = 1)
|
|
|
309 |
process_audio_button = gr.Button("Generate Audio", visible=False,scale = 1)
|
310 |
process_ner_button = gr.Button("Extract Entities", visible=False,scale = 1) # ✅ New button for NER
|
311 |
|
312 |
+
|
313 |
with gr.Row():
|
314 |
extracted_text = gr.Textbox(label="Extracted Content", visible=False, interactive=False, lines=15)
|
315 |
metadata_output = gr.JSON(label="Article Metadata", visible=False) # Displays metadata
|
|
|
320 |
summary_output = gr.Textbox(label="Summary", visible=True, interactive=False)
|
321 |
full_audio_output = gr.Audio(label="Generated Audio", visible=True)
|
322 |
ner_output = gr.Textbox(label="Extracted Entities", visible=True, interactive=False)
|
323 |
+
|
324 |
|
325 |
#Add textboxes for default and custom entity types
|
326 |
default_entity_types = gr.Textbox(label="Default Entity Types", value="PERSON, Organization, location, Date, PRODUCT, EVENT", interactive=True)
|
|
|
331 |
fetch_and_display_content,
|
332 |
inputs=[url_input],
|
333 |
|
334 |
+
outputs=[extracted_text, metadata_output, detected_lang, summary_output, process_audio_button,process_ner_button, extracted_text, metadata_output]
|
335 |
)
|
336 |
|
337 |
# Automatically generate word cloud when extracted_text changes
|
|
|
342 |
show_progress=True
|
343 |
)
|
344 |
|
345 |
+
#process_summary_button.click(hierarchical_summarization, inputs=[extracted_text], outputs=[summary_output])
|
346 |
|
347 |
# Step 2: Generate Audio After Text & Language Are Displayed
|
348 |
+
process_audio_button.click(
|
349 |
+
lambda text, summary, lang, voice, tts_choice: generate_audio_kokoro(
|
350 |
+
summary if tts_choice == "Summary Audio" else text, lang, voice
|
351 |
+
),
|
352 |
+
inputs=[extracted_text, summary_output, detected_lang, voice_selection, tts_option],
|
353 |
outputs=[full_audio_output]
|
354 |
)
|
355 |
|