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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -42
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 snapshot_download
7
 
8
  MODEL_REPO = "bartowski/Qwen_Qwen3.5-9B-GGUF"
9
  MODEL_FILE = "Qwen3.5-9B-Q4_K_M.gguf"
@@ -12,54 +12,54 @@ LLAMA_DIR = "llama.cpp"
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):
40
- subprocess.run(
41
- ["git", "clone", "https://github.com/ggerganov/llama.cpp"],
42
- check=True
43
- )
44
-
45
- subprocess.run(
46
- ["make", "-j"],
47
- cwd=LLAMA_DIR,
48
- check=True
49
- )
50
 
 
51
 
52
- def start_llama_server(model_path):
53
- subprocess.Popen(
54
- [
55
- "./server",
56
- "-m", model_path,
57
- "--port", SERVER_PORT,
58
- "--ctx-size", "4096",
59
- "--api"
60
- ],
61
- cwd=LLAMA_DIR
62
- )
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  def wait_for_server():
@@ -89,22 +89,22 @@ def chat(prompt):
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
 
102
 
103
  ui = gr.Interface(
104
  fn=chat,
105
- inputs=gr.Textbox(lines=5, placeholder="Ask Operon something..."),
106
  outputs="text",
107
- title="Operon Dev LLM (Qwen3.5-9B)",
108
  )
109
 
110
  ui.launch(server_name="0.0.0.0", server_port=7860)
 
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
  SERVER_PORT = "8000"
13
 
14
 
15
+ def install_dependencies():
16
+ subprocess.run(["apt-get", "update"])
17
+ subprocess.run([
18
+ "apt-get", "install", "-y",
19
+ "build-essential",
20
+ "cmake",
21
+ "git"
22
+ ])
 
 
 
 
23
 
24
 
25
  def download_model():
26
+ return hf_hub_download(
27
  repo_id=MODEL_REPO,
28
+ filename=MODEL_FILE,
29
+ repo_type="model"
30
  )
31
 
 
 
32
 
33
  def setup_llama():
34
  if not os.path.exists(LLAMA_DIR):
35
+ subprocess.run([
36
+ "git", "clone",
37
+ "https://github.com/ggml-org/llama.cpp"
38
+ ], check=True)
 
 
 
 
 
 
39
 
40
+ os.makedirs(f"{LLAMA_DIR}/build", exist_ok=True)
41
 
42
+ subprocess.run([
43
+ "cmake",
44
+ "-B", "build"
45
+ ], cwd=LLAMA_DIR, check=True)
46
+
47
+ subprocess.run([
48
+ "cmake",
49
+ "--build",
50
+ "build",
51
+ "-j"
52
+ ], cwd=LLAMA_DIR, check=True)
53
+
54
+
55
+ def start_server(model_path):
56
+ subprocess.Popen([
57
+ "./build/bin/llama-server",
58
+ "-m", model_path,
59
+ "--port", SERVER_PORT,
60
+ "--ctx-size", "4096",
61
+ "--api"
62
+ ], cwd=LLAMA_DIR)
63
 
64
 
65
  def wait_for_server():
 
89
  return data["choices"][0]["message"]["content"]
90
 
91
 
92
+ install_dependencies()
93
 
94
  model_path = download_model()
95
 
96
  setup_llama()
97
 
98
+ start_server(model_path)
99
 
100
  wait_for_server()
101
 
102
 
103
  ui = gr.Interface(
104
  fn=chat,
105
+ inputs=gr.Textbox(lines=5),
106
  outputs="text",
107
+ title="Operon Dev LLM (Qwen3.5-9B)"
108
  )
109
 
110
  ui.launch(server_name="0.0.0.0", server_port=7860)