Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 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 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 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(
|
| 32 |
-
outputs=
|
| 33 |
-
title="🔍 Keyword Extraction
|
| 34 |
-
description="
|
| 35 |
-
theme="soft"
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# -------------------------------
|
| 39 |
-
# LAUNCH
|
| 40 |
-
# -------------------------------
|
| 41 |
if __name__ == "__main__":
|
| 42 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the Hugging Face model for keyword/keyphrase extraction
|
| 5 |
+
extractor = pipeline("text2text-generation", model="ml6team/keyphrase-extraction-distilbert-inspec")
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
def extract_keywords(text):
|
| 8 |
+
if not text.strip():
|
| 9 |
+
return "⚠️ Please enter some text."
|
| 10 |
+
result = extractor(text, max_length=64, clean_up_tokenization_spaces=True)
|
| 11 |
+
return result[0]['generated_text']
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
demo = gr.Interface(
|
| 14 |
fn=extract_keywords,
|
| 15 |
+
inputs=gr.Textbox(lines=6, placeholder="Enter medical or general text here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="🔍 Keyword Extraction",
|
| 18 |
+
description="Extract key phrases and keywords using a Hugging Face Transformer model."
|
|
|
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
if __name__ == "__main__":
|
| 22 |
demo.launch()
|