Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,9 @@
|
|
1 |
-
import
|
2 |
-
import streamlit as st
|
3 |
from keybert import KeyBERT
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
model = load_model()
|
11 |
|
12 |
-
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|