Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("salti/arabic-t5-small-question-paraphrasing", use_fast=True)
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("salti/arabic-t5-small-question-paraphrasing").eval();
|
7 |
+
prompt = "أعد صياغة: "
|
8 |
+
|
9 |
+
@torch.inference_mode()
|
10 |
+
def paraphrase(question):
|
11 |
+
question = prompt + question
|
12 |
+
input_ids = tokenizer(question, return_tensors="pt").input_ids
|
13 |
+
generated_tokens = model.generate(input_ids).squeeze().cpu().numpy()
|
14 |
+
return tokenizer.decode(generated_tokens, skip_special_tokens=True)
|
15 |
+
|
16 |
+
|
17 |
+
iface = gr.Interface(fn=paraphrase, inputs="text", outputs="text")
|
18 |
+
iface.launch()
|