Derr11 commited on
Commit
3f46c32
·
verified ·
1 Parent(s): 4dd86c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
  import torch
4
  import spaces # مكتبة ZeroGPU
5
 
6
  # 1. إعدادات النموذج (Qwen3-Omni-Thinking)
7
- # نستخدم نسخة Thinking للحصول على قدرات الاستنتاج العميق
8
  MODEL_ID = "Qwen/Qwen3-Omni-30B-A3B-Thinking"
9
 
10
  print(f"جاري تحميل النموذج العملاق {MODEL_ID}... هذا سيستغرق بضعة دقائق.")
@@ -21,7 +20,8 @@ nf4_config = BitsAndBytesConfig(
21
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
22
 
23
  # تحميل النموذج مع الضغط
24
- model = AutoModelForCausalLM.from_pretrained(
 
25
  MODEL_ID,
26
  quantization_config=nf4_config,
27
  device_map="auto",
@@ -31,10 +31,8 @@ model = AutoModelForCausalLM.from_pretrained(
31
  print("تم تحميل النموذج بنجاح! المعلم جاهز.")
32
 
33
  # 2. دالة التفكير والرد
34
- @spaces.GPU(duration=120) # نزيد الوقت المسموح لأن التفكير يأخذ وقتاً
35
  def chat_with_thinking_model(message, history):
36
- # تجهيز سياق المحادثة
37
- # نماذج Thinking لا تحتاج عادةً لـ System Prompt معقد، هي تفهم السياق فوراً
38
  messages = []
39
 
40
  for user_msg, bot_msg in history:
@@ -43,7 +41,6 @@ def chat_with_thinking_model(message, history):
43
 
44
  messages.append({"role": "user", "content": message})
45
 
46
- # تحويل النص لأرقام
47
  text = tokenizer.apply_chat_template(
48
  messages,
49
  tokenize=False,
@@ -52,12 +49,10 @@ def chat_with_thinking_model(message, history):
52
 
53
  model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
54
 
55
- # التوليد
56
- # نماذج التفكير قد تولد نصوصاً طويلة تشرح فيها خطوات الحل
57
  generated_ids = model.generate(
58
  **model_inputs,
59
- max_new_tokens=1024, # نعطيه مساحة ليفكر
60
- temperature=0.7 # توازن بين الإبداع والدقة
61
  )
62
 
63
  generated_ids = [
 
1
  import gradio as gr
2
+ from transformers import AutoModel, AutoTokenizer, BitsAndBytesConfig
3
  import torch
4
  import spaces # مكتبة ZeroGPU
5
 
6
  # 1. إعدادات النموذج (Qwen3-Omni-Thinking)
 
7
  MODEL_ID = "Qwen/Qwen3-Omni-30B-A3B-Thinking"
8
 
9
  print(f"جاري تحميل النموذج العملاق {MODEL_ID}... هذا سيستغرق بضعة دقائق.")
 
20
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
21
 
22
  # تحميل النموذج مع الضغط
23
+ # التعديل هنا: استخدام AutoModel بدلاً من AutoModelForCausalLM
24
+ model = AutoModel.from_pretrained(
25
  MODEL_ID,
26
  quantization_config=nf4_config,
27
  device_map="auto",
 
31
  print("تم تحميل النموذج بنجاح! المعلم جاهز.")
32
 
33
  # 2. دالة التفكير والرد
34
+ @spaces.GPU(duration=120)
35
  def chat_with_thinking_model(message, history):
 
 
36
  messages = []
37
 
38
  for user_msg, bot_msg in history:
 
41
 
42
  messages.append({"role": "user", "content": message})
43
 
 
44
  text = tokenizer.apply_chat_template(
45
  messages,
46
  tokenize=False,
 
49
 
50
  model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
51
 
 
 
52
  generated_ids = model.generate(
53
  **model_inputs,
54
+ max_new_tokens=1024,
55
+ temperature=0.7
56
  )
57
 
58
  generated_ids = [