Saliltrehan7 commited on
Commit
c7223ed
1 Parent(s): c393714

Add Application File

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.pipelines import pipeline
2
+ from transformers.models.auto.modeling_auto import AutoModelForQuestionAnswering
3
+ from transformers.models.auto.tokenization_auto import AutoTokenizer
4
+
5
+ model_name = "deepset/xlm-roberta-base-squad2"
6
+
7
+ # a) Get predictions
8
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
9
+ QA_input = {
10
+ 'question': 'Why is model conversion important?',
11
+ 'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.'
12
+ }
13
+ res = nlp(QA_input)
14
+
15
+ # b) Load model & tokenizer
16
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
17
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
18
+
19
+
20
+ import gradio as gr
21
+ 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."
22
+ question = "Which continent is the Amazon rainforest in?"
23
+ gr.Interface.load(
24
+ "huggingface/deepset/roberta-base-squad2",
25
+ theme="default",
26
+ inputs=[gr.inputs.Textbox(lines=7, default=context, label="Context Paragraph"), gr.inputs.Textbox(lines=2, default=question, label="Question")],
27
+ outputs=[gr.outputs.Textbox(label="Answer"), gr.outputs.Textbox(label="Score")],
28
+ title=None).launch(share=True)