File size: 773 Bytes
5df5de8
58aa69c
5df5de8
58aa69c
 
 
 
5df5de8
58aa69c
 
 
 
 
 
5df5de8
58aa69c
 
5df5de8
58aa69c
 
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 AutoModelForCausalLM, AutoTokenizer

# تحميل نموذج LLaMA
model_name = "meta-llama/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# دالة للمحادثة مع الذكاء الاصطناعي
def chat_with_ai(user_input):
    inputs = tokenizer(user_input, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=150)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response

# إنشاء واجهة تفاعلية باستخدام Gradio
iface = gr.Interface(fn=chat_with_ai, inputs="text", outputs="text", title="AI Language Tutor")

# تشغيل التطبيق
iface.launch()