Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
extractor = pipeline("summarization", model="
|
| 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=
|
| 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(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
theme="soft"
|
| 24 |
)
|
| 25 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# β
Publicly available summarization model
|
| 5 |
+
extractor = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 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=40, min_length=5, do_sample=False)
|
| 12 |
keywords = result[0]['summary_text']
|
| 13 |
+
return f"π§ **Extracted Keywords (Approx):**\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(
|
| 20 |
+
label="π Enter Text",
|
| 21 |
+
placeholder="Paste your text here...",
|
| 22 |
+
lines=6
|
| 23 |
+
),
|
| 24 |
+
outputs=gr.Markdown(label="π Extracted Keywords"),
|
| 25 |
+
title="π Keyword Extractor (using BART)",
|
| 26 |
+
description="A quick and lightweight keyword extractor built using `facebook/bart-large-cnn` summarization model.",
|
| 27 |
theme="soft"
|
| 28 |
)
|
| 29 |
|