Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,17 +65,15 @@ def fetch_and_display_content(url):
|
|
| 65 |
#return cleaned_text, metadata, detected_lang, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 66 |
|
| 67 |
return (
|
| 68 |
-
cleaned_text,
|
| 69 |
-
metadata,
|
| 70 |
-
detected_lang,
|
| 71 |
-
gr.update(visible=True), # β
|
| 72 |
-
gr.update(visible=True), # β
|
| 73 |
gr.update(visible=True), # β
Show Extracted text box
|
| 74 |
gr.update(visible=True), # β
Show Metadata box
|
| 75 |
-
|
| 76 |
-
""
|
| 77 |
-
gr.update(value=cleaned_text, visible=True), # β
Ensure Extracted Text is shown
|
| 78 |
-
gr.update(value=metadata, visible=True) # β
Ensure Metadata is shown
|
| 79 |
)
|
| 80 |
|
| 81 |
### 2οΈβ£ Cleaning Function
|
|
@@ -180,14 +178,10 @@ def extract_entities_with_stanza(text, chunk_size=1000):
|
|
| 180 |
for chunk in chunks:
|
| 181 |
doc = nlp(chunk)
|
| 182 |
for ent in doc.ents:
|
| 183 |
-
|
| 184 |
-
entities.append(f"π **Entity**: \"{ent.text}\" | **Type**: {ent.type}") # β
Format output
|
| 185 |
|
| 186 |
-
#
|
| 187 |
-
if
|
| 188 |
-
return "No entities found."
|
| 189 |
-
|
| 190 |
-
return "\n\n".join(entities) # β
Display as Markdown-formatted text
|
| 191 |
|
| 192 |
### 4οΈβ£ TTS Functionality (KokoroTTS)
|
| 193 |
@spaces.GPU(duration=1000)
|
|
@@ -295,10 +289,11 @@ with gr.Blocks() as demo:
|
|
| 295 |
inputs=[url_input],
|
| 296 |
|
| 297 |
outputs=[
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
| 302 |
]
|
| 303 |
)
|
| 304 |
|
|
|
|
| 65 |
#return cleaned_text, metadata, detected_lang, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 66 |
|
| 67 |
return (
|
| 68 |
+
cleaned_text, # β
Extracted text
|
| 69 |
+
metadata, # β
Metadata (must be a valid JSON object)
|
| 70 |
+
detected_lang, # β
Detected language
|
| 71 |
+
gr.update(visible=True), # β
Make Summary button visible
|
| 72 |
+
gr.update(visible=True), # β
Make Audio button visible
|
| 73 |
gr.update(visible=True), # β
Show Extracted text box
|
| 74 |
gr.update(visible=True), # β
Show Metadata box
|
| 75 |
+
json.dumps([]), # β
Reset Entity output with an empty JSON array instead of ""
|
| 76 |
+
"" # β
Reset Summary output
|
|
|
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
### 2οΈβ£ Cleaning Function
|
|
|
|
| 178 |
for chunk in chunks:
|
| 179 |
doc = nlp(chunk)
|
| 180 |
for ent in doc.ents:
|
| 181 |
+
entities.append({"text": ent.text, "type": ent.type})
|
|
|
|
| 182 |
|
| 183 |
+
# β
Ensure JSON format even if no entities are found
|
| 184 |
+
return json.dumps({"entities": entities}) if entities else json.dumps({"entities": []})
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
### 4οΈβ£ TTS Functionality (KokoroTTS)
|
| 187 |
@spaces.GPU(duration=1000)
|
|
|
|
| 289 |
inputs=[url_input],
|
| 290 |
|
| 291 |
outputs=[
|
| 292 |
+
extracted_text, metadata_output, detected_lang,
|
| 293 |
+
process_summary_button, process_audio_button,
|
| 294 |
+
summary_output, ner_output, # β
Existing Outputs
|
| 295 |
+
gr.update(visible=True), # β
Ensures Extracted Text Box is shown
|
| 296 |
+
gr.update(visible=True) # β
Ensures Metadata Box is shown
|
| 297 |
]
|
| 298 |
)
|
| 299 |
|