nimool commited on
Commit
1687c0f
·
1 Parent(s): c671e2c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import RobertaForQuestionAnswering
3
+ from transformers import BertForQuestionAnswering
4
+ from transformers import AutoTokenizer
5
+
6
+ model1 = RobertaForQuestionAnswering.from_pretrained("pedramyazdipoor/persian_xlm_roberta_large")
7
+ tokenizer1 = AutoTokenizer.from_pretrained("pedramyazdipoor/persian_xlm_roberta_large")
8
+
9
+ roberta_large = pipeline(task='question-answering', model=model1, tokenizer=tokenizer1)
10
+
11
+ def Q_A(contetx, question):
12
+ answer_pedram = roberta_large({"question":question, "context":context})['answer']
13
+ return answer_pedram
14
+
15
+
16
+
17
+ # Create title, description and article strings
18
+ title = "Question and answer based on Roberta model"
19
+ description = "سیستم پردازش زبانی پرسش و پاسخ"
20
+ article = "آموزش داده شده با مدل زبانی روبرتا"
21
+
22
+
23
+ demo = gr.Interface(fn=Q_A, # mapping function from input to output
24
+ inputs=[gr.Textbox(label='پرسش خوذ را وارد کنید:', show_label=True, text_align='right'),
25
+ gr.Textbox(label='متن منبع خود را وارد کنید', show_label=True, text_align='right')], # what are the inputs?
26
+ outputs=gr.Text(), # what are the outputs?
27
+ # our fn has two outputs, therefore we have two outputs
28
+ # Create examples list from "examples/" directory
29
+ title=title,
30
+ description=description,
31
+ article=article)
32
+
33
+ # Launch the demo!
34
+ demo.launch(share=True)