Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
extractor = pipeline("
|
| 6 |
|
| 7 |
def extract_keywords(text):
|
| 8 |
if not text.strip():
|
| 9 |
return "⚠️ Please enter some text."
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
demo = gr.Interface(
|
| 14 |
fn=extract_keywords,
|
| 15 |
-
inputs=gr.Textbox(lines=6, placeholder="
|
| 16 |
-
outputs="
|
| 17 |
-
title="🔍 Keyword
|
| 18 |
-
description="
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a ready-made keyword extraction / summarization model
|
| 5 |
+
extractor = pipeline("summarization", model="pszemraj/keyword-extraction-distilbart-cnn-12-6")
|
| 6 |
|
| 7 |
def extract_keywords(text):
|
| 8 |
if not text.strip():
|
| 9 |
return "⚠️ Please enter some text."
|
| 10 |
+
try:
|
| 11 |
+
result = extractor(text, max_length=64, min_length=5, do_sample=False)
|
| 12 |
+
keywords = result[0]['summary_text']
|
| 13 |
+
return f"🧠 **Extracted Keywords:**\n\n{keywords}"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"❌ Error: {str(e)}"
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=extract_keywords,
|
| 19 |
+
inputs=gr.Textbox(label="📝 Enter text here", lines=6, placeholder="Paste medical or general text..."),
|
| 20 |
+
outputs=gr.Markdown(label="📊 Keywords"),
|
| 21 |
+
title="🔍 Keyword Extractor (Hugging Face Model)",
|
| 22 |
+
description="A lightweight keyword extraction tool using a fine-tuned DistilBART model.",
|
| 23 |
+
theme="soft"
|
| 24 |
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|