File size: 714 Bytes
135eb7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "malhajar/Mistral-7B-v0.1-arabic"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.8)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
iface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(lines=2, placeholder="اكتب هنا", label="المطالبة"),
outputs=gr.Textbox(label="الناتج"),
title="اكتبلي بدون API"
)
iface.launch()
|