Arabic250 commited on
Commit
befac3a
·
verified ·
1 Parent(s): 17f377c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -1,35 +1,33 @@
1
  import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
 
4
 
5
  try:
6
- print("--- Downloading Model from Model Hub ---")
 
7
  model_path = hf_hub_download(
8
  repo_id='Arabic250/gemma-4-gguf-export',
9
  filename='gemma-4-medical.gguf'
10
  )
11
 
12
- print("--- Initializing Llama-CPP ---")
13
- llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
 
14
 
15
- def chat(message, history):
16
- # بناء سياق المحادثة ليحتفظ بالرسائل السابقة
17
- prompt = ""
18
- for user_msg, bot_msg in history:
19
- prompt += f"USER: {user_msg}\nASSISTANT: {bot_msg}\n"
20
-
21
- prompt += f"USER: {message}\nASSISTANT: "
22
-
23
- # echo=False تمنع النموذج من تكرار السؤال في الإجابة
24
- output = llm(prompt, max_tokens=512, stop=['USER:'], echo=False)
25
- return output['choices'][0]['text']
26
-
27
- demo = gr.ChatInterface(fn=chat, title='Gemma 4 Medical')
28
 
 
 
 
 
 
29
  except Exception as e:
30
  with gr.Blocks() as demo:
31
- gr.Markdown(f'# Error: {e}')
32
 
33
  if __name__ == '__main__':
34
- # تحديد المنفذ 7860 صراحةً وهو المنفذ الافتراضي الذي تستمع إليه Hugging Face Spaces
35
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
+ import os
5
 
6
  try:
7
+ # تحميل ملف GGUF من المستودع الخارجي لتجاوز حد المساحة (1GB)
8
+ print("--- Downloading Gemma 4 GGUF Model ---")
9
  model_path = hf_hub_download(
10
  repo_id='Arabic250/gemma-4-gguf-export',
11
  filename='gemma-4-medical.gguf'
12
  )
13
 
14
+ # تهيئة النموذج
15
+ print("--- Initializing Engine ---")
16
+ llm = Llama(model_path=model_path, n_ctx=1024, n_threads=2)
17
 
18
+ def predict(message, history):
19
+ prompt = f"USER: {message}\nASSISTANT: "
20
+ response = llm(prompt, max_tokens=512, stop=['USER:'], echo=False)
21
+ return response['choices'][0]['text']
 
 
 
 
 
 
 
 
 
22
 
23
+ demo = gr.ChatInterface(
24
+ fn=predict,
25
+ title='⚡ Gemma 4 Medical - Docker Edition',
26
+ description='واجهة دردشة طبية تعمل بنظام Docker المستقر.'
27
+ )
28
  except Exception as e:
29
  with gr.Blocks() as demo:
30
+ gr.Markdown(f"# Error: {e}")
31
 
32
  if __name__ == '__main__':
33
+ demo.launch(server_name='0.0.0.0', server_port=7860)