Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
| 5 |
-
extractor = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
-
def
|
| 8 |
if not text.strip():
|
| 9 |
return "⚠️ Please enter some text."
|
|
|
|
| 10 |
try:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
-
return f"
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
-
inputs=gr.Textbox(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
),
|
| 24 |
-
outputs=gr.Markdown(label="📊 Extracted Keywords"),
|
| 25 |
-
title="🔍 Keyword Extractor (using BART)",
|
| 26 |
-
description="A quick and lightweight keyword extractor built using `facebook/bart-large-cnn` summarization model.",
|
| 27 |
theme="soft"
|
| 28 |
)
|
| 29 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
API_URL = "https://carecompanion-keywordextraction.onrender.com/extract_keywords"
|
|
|
|
| 5 |
|
| 6 |
+
def extract_keywords_from_api(text):
|
| 7 |
if not text.strip():
|
| 8 |
return "⚠️ Please enter some text."
|
| 9 |
+
|
| 10 |
try:
|
| 11 |
+
response = requests.post(API_URL, json={"text": text})
|
| 12 |
+
if response.status_code != 200:
|
| 13 |
+
return f"❌ API Error: {response.status_code}"
|
| 14 |
+
|
| 15 |
+
data = response.json()
|
| 16 |
+
|
| 17 |
+
# Format output nicely
|
| 18 |
+
output = ""
|
| 19 |
+
for category, items in data.items():
|
| 20 |
+
if items:
|
| 21 |
+
output += f"### 🩸 {category.capitalize()}\n"
|
| 22 |
+
for item in items:
|
| 23 |
+
if isinstance(item, list):
|
| 24 |
+
output += f"- {item[0]} (score: {item[1]:.2f})\n"
|
| 25 |
+
else:
|
| 26 |
+
output += f"- {item}\n"
|
| 27 |
+
output += "\n"
|
| 28 |
+
|
| 29 |
+
return output if output else "No keywords found."
|
| 30 |
+
|
| 31 |
except Exception as e:
|
| 32 |
+
return f"⚠️ Error: {str(e)}"
|
| 33 |
|
| 34 |
demo = gr.Interface(
|
| 35 |
+
fn=extract_keywords_from_api,
|
| 36 |
+
inputs=gr.Textbox(label="Enter medical text to extract keywords:", lines=5, placeholder="Example: The patient is prescribed amoxicillin and paracetamol for fever."),
|
| 37 |
+
outputs=gr.Markdown(label="Extracted Keywords"),
|
| 38 |
+
title="🧠 Keyword Extraction from Medical Text",
|
| 39 |
+
description="Calls the Render API to extract structured medical keywords.",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
theme="soft"
|
| 41 |
)
|
| 42 |
|