Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
# text summarizer | |
summarizer = pipeline("summarization", model = "facebook/bart-large-cnn") | |
def get_summary(text): | |
output = summarizer(text) | |
return output[0]["summary_text"] | |
# named entity recognition | |
ner_model = pipeline("ner", model = "dslim/bert-large-NER") | |
def get_ner(text): | |
output = ner_model(text) | |
return {"text":text, "entities":output} | |
demo = gr.Blocks() | |
with demo: | |
gr.Markdown("# Try out some cool tasks!") | |
with gr.Tab("Text Summarizer"): | |
sum_input = [gr.Textbox(label="Text to Summarize", placeholder="Enter text to summarize...", lines=4)] | |
sum_output = [gr.Textbox(label="Summarized Text")] | |
sum_btn = gr.Button("Summarize text") | |
sum_btn.click(get_summary, sum_input, sum_output) | |
with gr.Tab("Named Entity Recognition"): | |
ner_input = [gr.Textbox(label="Text to find Entities", placeholder = "Enter text...", lines = 4)] | |
# ner_output = gr.Textbox() | |
ner_output = [gr.HighlightedText(label="Text with entities")] | |
allow_flagging = "never" | |
ner_btn = gr.Button("Generate entities") | |
ner_btn.click(get_ner, ner_input, ner_output) | |
demo.launch() |