Download app.py from So66/Fe: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/spaces/So66/Fe/resolve/main/app.py
- Command line
-
hf download hf://spaces/So66/Fe/app.py
-
curl -L -o app.py https://huggingface.co/spaces/So66/Fe/resolve/main/app.py
909 Bytes
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelWithLMHead | |
| # تحميل النموذج | |
| model_name = "aubmindlab/aragpt2-base" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelWithLMHead.from_pretrained(model_name) | |
| def generate_text(prompt): | |
| input_ids = tokenizer.encode(prompt, return_tensors="pt") | |
| output = model.generate( | |
| input_ids, | |
| max_length=50, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_k=50, | |
| top_p=0.95, | |
| num_return_sequences=1 | |
| ) | |
| return tokenizer.decode(output[0], skip_special_tokens=True) | |
| # واجهة Gradio | |
| gr.Interface( | |
| fn=generate_text, | |
| inputs=gr.Textbox(lines=2, placeholder="أدخل بداية النص هنا...", label="نص الإدخال"), | |
| outputs=gr.Textbox(label="النص المُولد"), | |
| title="توليد نص عربي باستخدام AraGPT2" | |
| ).launch() |