Spaces:
Runtime error
Runtime error
# !pip install gradio | |
# !pip install -q keybert | |
from keybert import KeyBERT | |
import gradio as gr | |
def greet(text, ngram_min, ngram_max, top_n, diversity, seed_keywords): | |
model_name = 'all-mpnet-base-v2' | |
model = KeyBERT(model_name) | |
if ngram_min > ngram_max: | |
return "ngram_min should no greater than ngram_max!" | |
else: | |
keywords = model.extract_keywords(text, keyphrase_ngram_range=(ngram_min, ngram_max), top_n=top_n, use_mmr=True, | |
diversity=diversity, seed_keywords=seed_keywords) | |
res = "" | |
for keyword in keywords: | |
res += keyword[0] + "\n" | |
return res | |
demo = gr.Interface( | |
fn=greet, | |
inputs=[gr.Textbox(placeholder="Put the text here and click 'submit' to get the keyphrases", label="Input Text"), gr.Slider(1, 5, step = 1, label="Minimum number of words in a keyphrase"), gr.Slider(1, 5, step = 1, label="Maximum number of words in a keyphrase"), | |
gr.Slider(1, 10, step = 1, label="Number of keyphrases"), gr.Slider(0, 1, step = 0.05, label="Diversity of the returned keyphrases"), | |
gr.Textbox(placeholder='This field can be empty', label="Seed Keyword:\nguide the extraction by steering the similarities towards it.")], | |
outputs=[gr.Textbox(label='Extracted Keyphrases')], | |
) | |
demo.launch(debug=True) |