PuristanLabs1 commited on
Commit
8c30d30
Β·
verified Β·
1 Parent(s): ef3fda9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
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, # βœ… Extracted content
69
- metadata, # βœ… Article metadata
70
- detected_lang, # βœ… Detected language
71
- gr.update(visible=True), # βœ… Show Summary button
72
- gr.update(visible=True), # βœ… Show Audio button
73
  gr.update(visible=True), # βœ… Show Extracted text box
74
  gr.update(visible=True), # βœ… Show Metadata box
75
- "", # βœ… Reset Summary output when a new URL is fetched
76
- "", # βœ… Reset Entity output when a new URL is fetched
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
- #return entities
187
- if not entities:
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
- extracted_text, metadata_output, detected_lang,
299
- process_summary_button, process_audio_button,
300
- summary_output, ner_output,
301
- extracted_text, metadata_output # βœ… Ensures visibility update
 
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