File size: 2,427 Bytes
33384b3
 
 
 
 
 
 
 
 
7791f4d
33384b3
 
e12e22b
 
46a1999
e12e22b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45eb2fa
e12e22b
 
 
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
34
35
36
37
import gradio as gr

title = "Longformer"

description = "Gradio Demo for Longformer. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."

article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2004.05150' target='_blank'>Longformer: The Long-Document Transformer</a></p>"

examples = [
    ["""The Amazon rainforest (Portuguese: Floresta Amaz么nica or Amaz么nia; Spanish: Selva Amaz贸nica, Amazon铆a or usually Amazonia; French: For锚t amazonienne; Dutch: Amazoneregenwoud), 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. States or departments in four nations contain "Amazonas" in their names. 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.""","longformer-base-4096-finetuned-squadv1","Which name is also used to describe the Amazon rainforest in English?"]
]

io1 = gr.Interface.load("huggingface/valhalla/longformer-base-4096-finetuned-squadv1")

io2 = gr.Interface.load("huggingface/allenai/longformer-large-4096-finetuned-triviaqa")


def inference(context, model,question):
    if model == "longformer-base-4096-finetuned-squadv1":
        outlabel = io1(context,question)
    else:
        outlabel = io2(context,question)
    return outlabel
     

gr.Interface(
    inference, 
    [gr.inputs.Textbox(label="Context",lines=10),gr.inputs.Dropdown(choices=["longformer-base-4096-finetuned-squadv1","longformer-large-4096-finetuned-triviaqa"], type="value", default="longformer-base-4096-finetuned-squadv1", label="model"),gr.inputs.Textbox(label="Question Answering")], 
    [gr.outputs.Textbox(label="Output")],
    examples=examples,
    article=article,
    title=title,
    description=description).launch(enable_queue=True)