Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, GPTNeoXForCausalLM
|
3 |
+
|
4 |
+
# تحميل النماذج
|
5 |
+
tokenizer_ara = AutoTokenizer.from_pretrained("aubmindlab/bert-base-arabertv02")
|
6 |
+
model_ara = AutoModelForSequenceClassification.from_pretrained("aubmindlab/bert-base-arabertv02")
|
7 |
+
tokenizer_gpt = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
8 |
+
model_gpt = GPTNeoXForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b")
|
9 |
+
|
10 |
+
# دالة للتنبؤ
|
11 |
+
def generate_text(input_text):
|
12 |
+
input_ids_ara = tokenizer_ara(input_text, return_tensors="pt").input_ids
|
13 |
+
outputs_ara = model_ara(input_ids_ara)
|
14 |
+
input_ids_gpt = tokenizer_gpt(outputs_ara.logits.argmax(-1).item(), return_tensors="pt").input_ids
|
15 |
+
outputs_gpt = model_gpt.generate(input_ids_gpt, max_length=100)
|
16 |
+
generated_text = tokenizer_gpt.decode(outputs_gpt[0])
|
17 |
+
return generated_text
|
18 |
+
|
19 |
+
# واجهة المستخدم
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_text,
|
22 |
+
inputs=gr.Textbox(lines=5, placeholder="أدخل نصًا عربيًا هنا..."),
|
23 |
+
outputs=gr.Textbox(lines=5),
|
24 |
+
title="توليد النصوص العربية باستخدام AraBERT و GPT-NeoX",
|
25 |
+
description="أدخل نصًا عربيًا وستقوم هذه الأداة بتحليله باستخدام AraBERT ثم توليد نص جديد باستخدام GPT-NeoX."
|
26 |
+
)
|
27 |
+
|
28 |
+
iface.launch()
|