yut23387 commited on
Commit
8c9080d
·
verified ·
1 Parent(s): 17cd270

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -41
app.py CHANGED
@@ -3,57 +3,52 @@ from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
  import gradio as gr
5
 
6
- # إعدادات الموديل
7
- REPO_ID = "yut23387/My-Private-Brain"
8
- FILENAME = "DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf"
 
9
 
10
- print(f"🚀 Starting download for: {FILENAME}...")
11
 
12
  try:
13
  model_path = hf_hub_download(
14
  repo_id=REPO_ID,
15
  filename=FILENAME
16
  )
17
- print(f"✅ Download path: {model_path}")
18
-
19
- # --- بداية التشخيص ---
20
- # 1. فحص حجم الملف
21
- file_size = os.path.getsize(model_path)
22
- print(f"📦 File Size: {file_size / (1024 * 1024):.2f} MB")
23
-
24
- if file_size < 100 * 1024 * 1024: # إذا كان أقل من 100 ميجا
25
- print("⚠️ WARNING: The file is suspiciously small! It might be an LFS pointer, not the real model.")
26
- else:
27
- print("✅ File size looks correct (Big binary file).")
28
- # --- نهاية التشخيص ---
29
-
30
- print("⚙️ Loading LLM (with verbose=True)...")
 
 
 
 
31
 
32
- # تشغيل الموديل مع تفعيل السجلات (verbose=True) لرؤية سبب الرفض
33
- llm = Llama(
34
- model_path=model_path,
35
- n_ctx=2048,
36
- n_threads=2,
37
- verbose=True # فعلناها لنرى الخطأ الداخلي
38
  )
39
- print("✅ LLM Loaded successfully!")
40
-
41
- except Exception as e:
42
- print(f"\n❌ FATAL ERROR:\n{e}")
43
- # لا نوقف البرنامج حتى نتمكن من قراءة اللوج
44
- pass
45
-
46
- # واجهة بسيطة (لن تعمل إذا فشل التحميل، لكن وضعناها لكي لا ينهار التطبيق)
47
- def dummy_chat(message, history):
48
- return "Model failed to load. Check logs."
49
 
50
- if 'llm' in locals():
51
- def generate_response(message, history):
52
- output = llm(f"User: {message}\nAssistant: ", max_tokens=256, stop=["User:"], echo=False)
53
- return output['choices'][0]['text']
54
- demo = gr.ChatInterface(fn=generate_response, title="AI Bank")
55
- else:
56
- demo = gr.ChatInterface(fn=dummy_chat, title="Error Loading Model")
57
 
 
58
  if __name__ == "__main__":
59
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
3
  from huggingface_hub import hf_hub_download
4
  import gradio as gr
5
 
6
+ # 1. سنستخدم نموذج Qwen 2.5 المستقر (من المصدر العام مؤقتاً لتشغيل المشروع)
7
+ # هذا لا يمنع أن البوت أصبح "خاصاً بك" ويعمل على مساحتك
8
+ REPO_ID = "bartowski/Qwen2.5-1.5B-Instruct-GGUF"
9
+ FILENAME = "Qwen2.5-1.5B-Instruct-Q4_K_M.gguf"
10
 
11
+ print(f"🚀 Starting download for: {FILENAME} from {REPO_ID}")
12
 
13
  try:
14
  model_path = hf_hub_download(
15
  repo_id=REPO_ID,
16
  filename=FILENAME
17
  )
18
+ print(f"✅ Model downloaded to: {model_path}")
19
+ except Exception as e:
20
+ print(f"❌ Error downloading: {e}")
21
+ raise e
22
+
23
+ print("⚙️ Loading LLM...")
24
+ # إعدادات مناسبة جداً لسرعة الرد
25
+ llm = Llama(
26
+ model_path=model_path,
27
+ n_ctx=4096,
28
+ n_threads=2,
29
+ verbose=False
30
+ )
31
+ print(" LLM Loaded!")
32
+
33
+ def generate_response(message, history):
34
+ # تنسيق Qwen 2.5 للحصول على أفضل دقة
35
+ prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
36
 
37
+ output = llm(
38
+ prompt,
39
+ max_tokens=512,
40
+ stop=["<|im_end|>"],
41
+ echo=False
 
42
  )
43
+ return output['choices'][0]['text']
 
 
 
 
 
 
 
 
 
44
 
45
+ # واجهة بسيطة للتجربة
46
+ demo = gr.ChatInterface(
47
+ fn=generate_response,
48
+ title="My Private AI 🧠",
49
+ description="Qwen 2.5 - Running Securely on Docker"
50
+ )
 
51
 
52
+ # تشغيل السيرفر
53
  if __name__ == "__main__":
54
  demo.launch(server_name="0.0.0.0", server_port=7860)