File size: 1,023 Bytes
be95b82
 
 
ba37341
be95b82
 
ba37341
 
be95b82
 
ba37341
db16d10
ba37341
5f6c6c9
ba37341
dde29c3
ba37341
be95b82
 
ba37341
 
 
 
 
 
 
 
 
 
 
 
be95b82
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 multiple NLP tasks!")
    with gr.Tab("Text Summarizer"):
        sum_input = gr.Textbox(placeholder="Enter text to summarize...", lines=4)
        sum_output = gr.Textbox()
        sum_btn = gr.Button("Summarize")
        sum_btn.click(get_summary, sum_input, sum_output)
    with gr.Tab("Named Entity Recognition"):
        ner_input = gr.Textbox(placeholder = "Enter text...", lines = 4)
        ner_output = gr.Textbox()
        ner_btn = gr.Button("Get named entities")
        ner_btn.click(get_ner, ner_input, ner_output)
    

demo.launch()