Spaces:
Sleeping
Sleeping
File size: 1,518 Bytes
c5e9f08 4ff5d1d c5e9f08 4ff5d1d c5e9f08 4ff5d1d fb7afb2 4ff5d1d e247ee8 4ff5d1d e247ee8 4ff5d1d c5e9f08 4ff5d1d e247ee8 c5e9f08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import requests
API_URL = "https://carecompanion-keywordextraction.onrender.com/extract_keywords"
def extract_keywords_from_api(text):
if not text.strip():
return "⚠️ Please enter some text."
try:
response = requests.post(API_URL, json={"text": text})
if response.status_code != 200:
return f"❌ API Error: {response.status_code}"
data = response.json()
# Format output nicely
output = ""
for category, items in data.items():
if items:
output += f"### 🩸 {category.capitalize()}\n"
for item in items:
if isinstance(item, list):
output += f"- {item[0]} (score: {item[1]:.2f})\n"
else:
output += f"- {item}\n"
output += "\n"
return output if output else "No keywords found."
except Exception as e:
return f"⚠️ Error: {str(e)}"
demo = gr.Interface(
fn=extract_keywords_from_api,
inputs=gr.Textbox(label="Enter medical text to extract keywords:", lines=5, placeholder="Example: The patient is prescribed amoxicillin and paracetamol for fever."),
outputs=gr.Markdown(label="Extracted Keywords"),
title="🧠 Keyword Extraction from Medical Text",
description="Calls the Render API to extract structured medical keywords.",
theme="soft"
)
if __name__ == "__main__":
demo.launch()
|