vinni1484 commited on
Commit
ef0970f
1 Parent(s): 1d83f2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -38
app.py CHANGED
@@ -1,41 +1,9 @@
1
- import pandas as pd
2
- import streamlit as st
3
  from keybert import KeyBERT
4
 
5
- @st.cache(allow_output_mutation=True, suppress_st_warning=True, show_spinner=True)
6
- def load_model():
7
- model = KeyBERT("sentence-transformers/xlm-r-distilroberta-base-paraphrase-v1")
8
- return model
9
-
10
- model = load_model()
11
 
12
- placeholder = st.empty()
13
- text_input = placeholder.text_area("Paste or write text", height=300)
14
-
15
- top_n = st.sidebar.slider("Select a number of keywords", 1, 10, 5, 1)
16
- min_ngram = st.sidebar.number_input("Minimum number of words in each keyword", 1, 5, 1, 1)
17
- max_ngram = st.sidebar.number_input("Maximum number of words in each keyword", min_ngram, 5, 3, step=1)
18
- st.sidebar.code(f"ngram_range=({min_ngram}, {max_ngram})")
19
-
20
- params = {"docs": text_input, "top_n": top_n, "keyphrase_ngram_range": (min_ngram, max_ngram), "stop_words": 'english'}
21
-
22
- add_diversity = st.sidebar.checkbox("Adjust diversity of keywords")
23
-
24
- if add_diversity:
25
- method = st.sidebar.selectbox("Select a method", ("Max Sum Similarity", "Maximal Marginal Relevance"))
26
- if method == "Max Sum Similarity":
27
- nr_candidates = st.sidebar.slider("nr_candidates", 20, 50, 20, 2)
28
- params["use_maxsum"] = True
29
- params["nr_candidates"] = nr_candidates
30
-
31
- elif method == "Maximal Marginal Relevance":
32
- diversity = st.sidebar.slider("diversity", 0.1, 1.0, 0.6, 0.01)
33
- params["use_mmr"] = True
34
- params["diversity"] = diversity
35
-
36
- keywords = model.extract_keywords(**params)
37
-
38
- if keywords != []:
39
- st.info("Extracted keywords")
40
- keywords = pd.DataFrame(keywords, columns=["keyword", "relevance"])
41
- st.table(keywords)
 
1
+ import gradio as gr
 
2
  from keybert import KeyBERT
3
 
4
+ def keywords(text):
5
+ model = KeyBERT("sentence-transformers/xlm-r-distilroberta-base-paraphrase-v1")
6
+ keywords = model.extract_keywords("The quick brown fox jumps over the lazy dog.")
7
+ return keywords
 
 
8
 
9
+ gr.Interface(keywords, "text", "text",title="Keyword Extractor").launch()