Aadityaramrame's picture
Update app.py
4ff5d1d verified
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()