dgotlieb commited on
Commit
d2eac6f
·
verified ·
1 Parent(s): e873b25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,8 +1,9 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load a stable keyword extraction model once
5
- pipe = pipeline("token-classification", model="ml6team/keyphrase-extraction-distilbert-inspec", aggregation_strategy="simple")
 
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
- # Join the extracted keyword strings into a single line
17
- return ", ".join([kw['word'] for kw in keywords])
 
 
 
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