Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
pipe_ar = pipeline("question-answering",model='ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA') # arabic model
|
4 |
+
pipe_en = pipeline("question-answering",model='deepset/roberta-base-squad2') # english model
|
5 |
+
|
6 |
+
def q_a(lang,text,question):
|
7 |
+
if lang == 'Arabic': # if user select arabic
|
8 |
+
myinput = {
|
9 |
+
'question': question,
|
10 |
+
'context':text
|
11 |
+
}
|
12 |
+
return pipe_ar(myinput)['answer'] # here will use pipe_ar which is the arabic model and return the answer
|
13 |
+
|
14 |
+
elif lang == 'English': # user select english
|
15 |
+
myinput = {
|
16 |
+
'question': question,
|
17 |
+
'context':text
|
18 |
+
}
|
19 |
+
return pipe_en(myinput)['answer'] #use english model
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
app = gr.Interface(
|
25 |
+
fn= q_a,
|
26 |
+
inputs=[gr.Radio(['Arabic', 'English'], label='Select Language',value= 'Arabic'), # radio bottom for select the language and the defult languses will be arabic
|
27 |
+
gr.Textbox(label = 'enter text',lines=10),# text box to enter the context
|
28 |
+
gr.Textbox(label = 'enter question')],# text box for enter the question
|
29 |
+
outputs=gr.Textbox(label = 'answer')# the output will display here
|
30 |
+
)
|
31 |
+
app.launch()
|