Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# تحميل النموذج والمحول
|
5 |
+
model_name = "EleutherAI/gpt-neo-1.3B"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# تعريف وظيفة التفاعل
|
10 |
+
def chat_with_model(input_text):
|
11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
12 |
+
outputs = model.generate(inputs["input_ids"], max_length=150, temperature=1.0)
|
13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return response
|
15 |
+
|
16 |
+
# بناء واجهة Gradio
|
17 |
+
iface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="AI Chatbot")
|
18 |
+
|
19 |
+
# تشغيل الموقع
|
20 |
+
iface.launch()
|