Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load a
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def extract_keywords(text):
|
| 8 |
"""
|
|
@@ -13,8 +14,11 @@ def extract_keywords(text):
|
|
| 13 |
if not keywords:
|
| 14 |
return "No keywords found."
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
return f"An error occurred: {e}"
|
| 20 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a more general and powerful keyword extraction model
|
| 5 |
+
# Note: This model uses the "ner" task (Named Entity Recognition)
|
| 6 |
+
pipe = pipeline("ner", model="ybelkada/keyword-extraction-llm-transformers", aggregation_strategy="simple")
|
| 7 |
|
| 8 |
def extract_keywords(text):
|
| 9 |
"""
|
|
|
|
| 14 |
if not keywords:
|
| 15 |
return "No keywords found."
|
| 16 |
|
| 17 |
+
# This model's output is slightly different, so we extract the 'word'
|
| 18 |
+
# and replace spaces in multi-word keywords for readability.
|
| 19 |
+
processed_keywords = [kw['word'].replace(' ', ' ') for kw in keywords]
|
| 20 |
+
return ", ".join(processed_keywords)
|
| 21 |
+
|
| 22 |
except Exception as e:
|
| 23 |
return f"An error occurred: {e}"
|
| 24 |
|