File size: 1,792 Bytes
2a2c864
b8db52d
 
6da417a
2a2c864
 
 
 
6da417a
 
 
b8db52d
 
8cea305
 
 
 
 
 
 
6da417a
 
 
8cea305
b8db52d
6da417a
 
8cea305
 
 
b8db52d
2a2c864
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
import gradio as gr
from transformers import pipeline

qa_pipeline = pipeline(task="question-answering",model="Intel/bert-base-uncased-squadv1.1-sparse-80-1x4-block-pruneofa")

def greet(name):
    return "Hello " + name + "!!"

def predict(question,context):
    
    predictions = qa_pipeline(context=context,question=question)
    return predictions

md = """
App coming soon! 

Based on the [Prune Once for All: Sparse Pre-Trained Language Models](https://arxiv.org/abs/2111.05754) paper.

"""

context = "The Amazon rainforest, also known in English as Amazonia or the Amazon Jungle, is a moist broadleaf forest that covers most of the Amazon basin of South America. This basin encompasses 7,000,000 square kilometres (2,700,000 sq mi), of which 5,500,000 square kilometres (2,100,000 sq mi) are covered by the rainforest. This region includes territory belonging to nine nations. The majority of the forest is contained within Brazil, with 60% of the rainforest, followed by Peru with 13%, Colombia with 10%, and with minor amounts in Venezuela, Ecuador, Bolivia, Guyana, Suriname and French Guiana. The Amazon represents over half of the planet's remaining rainforests, and comprises the largest and most biodiverse tract of tropical rainforest in the world, with an estimated 390 billion individual trees divided into 16,000 species."
question = "Which continent is the Amazon rainforest in?"

iface = gr.Interface(
    fn=predict, 
    inputs=[gr.inputs.Textbox(lines=5, default=context, label="Context Paragraph"), gr.inputs.Textbox(lines=2, default=question, label="Question")],
    outputs=[gr.outputs.Textbox(label="Answer"), gr.outputs.Textbox(label="Score")],
    title = "Question & Answer with Sparse BERT using the SQuAD dataset",
    description = md
    )

iface.launch()