Tahsin-Mayeesha commited on
Commit
eae27ac
1 Parent(s): b710584
Files changed (2) hide show
  1. app.py +27 -5
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,29 @@
1
- import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ model = AutoModelForSeq2SeqLM.from_pretrained("Mihakram/AraT5-base-question-generation")
4
+ tokenizer = AutoTokenizer.from_pretrained("Mihakram/AraT5-base-question-generation")
5
+
6
 
7
+ import gradio as gr
8
+ def generate__questions(context,answer):
9
+ text="context: " +context + " " + "answer: " + answer + " </s>"
10
+ text_encoding = tokenizer.encode_plus(
11
+ text,return_tensors="pt"
12
+ )
13
+ model.eval()
14
+ generated_ids = model.generate(
15
+ input_ids=text_encoding['input_ids'],
16
+ attention_mask=text_encoding['attention_mask'],
17
+ max_length=64,
18
+ num_beams=5,
19
+ num_return_sequences=1
20
+ )
21
+
22
+ return tokenizer.decode(generated_ids[0],skip_special_tokens=True,clean_up_tokenization_spaces=True).replace('question: ',' ')
23
 
24
+ demo = gr.Interface(fn=generate__questions, inputs=[gr.Textbox(label='Context'),
25
+ gr.Textbox(label='Answer')] ,
26
+ outputs=gr.Textbox(label='Question'),
27
+ title="Arabic Question Generation",
28
+ description="Get the Question from given Context and an Answer")
29
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers