File size: 1,161 Bytes
f88ecf8
9c2391e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
pip install transformers
from transformers import pipeline
import gradio as gr
pipe_ar = pipeline("question-answering",model='ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA') # arabic model
pipe_en = pipeline("question-answering",model='deepset/roberta-base-squad2') # english model

def q_a(lang,text,question):
  if lang == 'Arabic': # if user select arabic
    myinput = {
      'question': question,
      'context':text
  }
    return pipe_ar(myinput)['answer'] # here will use pipe_ar which is the arabic model and return the answer

  elif lang == 'English': # user select english
    myinput = {
    'question': question,
    'context':text
    }
    return pipe_en(myinput)['answer'] #use english model




app = gr.Interface(
    fn= q_a,
    inputs=[gr.Radio(['Arabic', 'English'], label='Select Language',value= 'Arabic'), # radio bottom for select the language and the defult languses will be arabic
            gr.Textbox(label = 'enter text',lines=10),# text box to enter the context
            gr.Textbox(label = 'enter question')],# text box for enter the question
    outputs=gr.Textbox(label = 'answer')# the output will display here
)
app.launch()