soumo-hug commited on
Commit
174c905
·
verified ·
1 Parent(s): de70972

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -3,7 +3,7 @@ import subprocess
3
  import time
4
  import requests
5
  import gradio as gr
6
- from huggingface_hub import hf_hub_download
7
 
8
  MODEL_REPO = "bartowski/Qwen_Qwen3.5-9B-GGUF"
9
  MODEL_FILE = "Qwen3.5-9B-Q4_K_M.gguf"
@@ -12,12 +12,28 @@ LLAMA_DIR = "llama.cpp"
12
  SERVER_PORT = "8000"
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def download_model():
16
- return hf_hub_download(
17
  repo_id=MODEL_REPO,
18
- filename=MODEL_FILE
19
  )
20
 
 
 
21
 
22
  def setup_llama():
23
  if not os.path.exists(LLAMA_DIR):
@@ -33,7 +49,7 @@ def setup_llama():
33
  )
34
 
35
 
36
- def start_server(model_path):
37
  subprocess.Popen(
38
  [
39
  "./server",
@@ -48,6 +64,7 @@ def start_server(model_path):
48
 
49
  def wait_for_server():
50
  url = f"http://localhost:{SERVER_PORT}/health"
 
51
  for _ in range(60):
52
  try:
53
  requests.get(url, timeout=1)
@@ -72,11 +89,13 @@ def chat(prompt):
72
  return data["choices"][0]["message"]["content"]
73
 
74
 
 
 
75
  model_path = download_model()
76
 
77
  setup_llama()
78
 
79
- start_server(model_path)
80
 
81
  wait_for_server()
82
 
 
3
  import time
4
  import requests
5
  import gradio as gr
6
+ from huggingface_hub import snapshot_download
7
 
8
  MODEL_REPO = "bartowski/Qwen_Qwen3.5-9B-GGUF"
9
  MODEL_FILE = "Qwen3.5-9B-Q4_K_M.gguf"
 
12
  SERVER_PORT = "8000"
13
 
14
 
15
+ def install_build_tools():
16
+ subprocess.run(
17
+ ["apt-get", "update"],
18
+ stdout=subprocess.DEVNULL,
19
+ stderr=subprocess.DEVNULL
20
+ )
21
+
22
+ subprocess.run(
23
+ ["apt-get", "install", "-y", "build-essential", "cmake", "git"],
24
+ stdout=subprocess.DEVNULL,
25
+ stderr=subprocess.DEVNULL
26
+ )
27
+
28
+
29
  def download_model():
30
+ path = snapshot_download(
31
  repo_id=MODEL_REPO,
32
+ allow_patterns=[MODEL_FILE]
33
  )
34
 
35
+ return os.path.join(path, MODEL_FILE)
36
+
37
 
38
  def setup_llama():
39
  if not os.path.exists(LLAMA_DIR):
 
49
  )
50
 
51
 
52
+ def start_llama_server(model_path):
53
  subprocess.Popen(
54
  [
55
  "./server",
 
64
 
65
  def wait_for_server():
66
  url = f"http://localhost:{SERVER_PORT}/health"
67
+
68
  for _ in range(60):
69
  try:
70
  requests.get(url, timeout=1)
 
89
  return data["choices"][0]["message"]["content"]
90
 
91
 
92
+ install_build_tools()
93
+
94
  model_path = download_model()
95
 
96
  setup_llama()
97
 
98
+ start_llama_server(model_path)
99
 
100
  wait_for_server()
101