Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# -------------------------------
|
| 5 |
+
# CONFIG
|
| 6 |
+
# -------------------------------
|
| 7 |
+
API_URL = "https://carecompanion-keywordextraction.onrender.com/extract_keywords" # replace with your actual endpoint
|
| 8 |
+
|
| 9 |
+
# -------------------------------
|
| 10 |
+
# FUNCTION TO CALL RENDER API
|
| 11 |
+
# -------------------------------
|
| 12 |
+
def extract_keywords(text):
|
| 13 |
+
try:
|
| 14 |
+
payload = {"text": text}
|
| 15 |
+
response = requests.post(API_URL, json=payload)
|
| 16 |
+
|
| 17 |
+
if response.status_code == 200:
|
| 18 |
+
data = response.json()
|
| 19 |
+
# Customize this based on your API response format
|
| 20 |
+
return data.get("keywords", "No keywords found.")
|
| 21 |
+
else:
|
| 22 |
+
return f"⚠️ API Error {response.status_code}: {response.text}"
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"❌ Connection error: {str(e)}"
|
| 25 |
+
|
| 26 |
+
# -------------------------------
|
| 27 |
+
# GRADIO INTERFACE
|
| 28 |
+
# -------------------------------
|
| 29 |
+
demo = gr.Interface(
|
| 30 |
+
fn=extract_keywords,
|
| 31 |
+
inputs=gr.Textbox(label="Enter text for keyword extraction", placeholder="Paste your text here..."),
|
| 32 |
+
outputs=gr.Textbox(label="Extracted Keywords"),
|
| 33 |
+
title="🔍 Keyword Extraction API Demo",
|
| 34 |
+
description="This Gradio interface calls a deployed keyword extraction API hosted on Render.",
|
| 35 |
+
theme="soft"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# -------------------------------
|
| 39 |
+
# LAUNCH
|
| 40 |
+
# -------------------------------
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
demo.launch()
|