Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# اسم مستودع الموديل متاعك
|
| 6 |
+
model_name = "Dav66/Te"
|
| 7 |
+
|
| 8 |
+
# تحميل التوكنيزر والموديل
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
def generate_text(prompt):
|
| 13 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 14 |
+
outputs = model.generate(**inputs, max_length=100)
|
| 15 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
return text
|
| 17 |
+
|
| 18 |
+
# واجهة Gradio
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=generate_text,
|
| 21 |
+
inputs=gr.Textbox(lines=2, placeholder="اكتب هنا النص..."),
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="توليد نص بالعربي",
|
| 24 |
+
description="تطبيق بسيط يعرض موديلك على Hugging Face Space"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
iface.launch()
|