Arabic250 commited on
Commit
3c77f32
·
verified ·
1 Parent(s): 32c58f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,10 +1,8 @@
1
-
2
  import gradio as gr
3
  from llama_cpp import Llama
4
  from huggingface_hub import hf_hub_download
5
 
6
  try:
7
- # This downloads the 9.6GB file into the Space's runtime temporary storage at startup
8
  print("--- Downloading Model from Model Hub ---")
9
  model_path = hf_hub_download(
10
  repo_id='Arabic250/gemma-4-gguf-export',
@@ -15,13 +13,23 @@ try:
15
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
16
 
17
  def chat(message, history):
18
- output = llm(f"USER: {message}\nASSISTANT: ", max_tokens=512, stop=['USER:'])
 
 
 
 
 
 
 
 
19
  return output['choices'][0]['text']
20
 
21
  demo = gr.ChatInterface(fn=chat, title='Gemma 4 Medical')
 
22
  except Exception as e:
23
  with gr.Blocks() as demo:
24
  gr.Markdown(f'# Error: {e}')
25
 
26
  if __name__ == '__main__':
27
- demo.launch()
 
 
 
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',
 
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)