Staticaliza commited on
Commit
eb2d7fc
·
verified ·
1 Parent(s): 814fd8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -2,21 +2,20 @@ import spaces
2
  @spaces.GPU(duration=15)
3
  def gpu():
4
  print("[GPU] | GPU maintained.")
5
-
6
  import os
7
  import sys
8
  import subprocess
 
9
  import gradio as gr
10
 
11
- def find_run_script():
12
- for root, dirs, files in os.walk(os.getcwd()):
13
- if "run_inference.py" in files:
14
- return os.path.join(root, "run_inference.py")
15
- return None
16
-
17
- SCRIPT_PATH = find_run_script()
18
- if not SCRIPT_PATH:
19
- raise FileNotFoundError("run_inference.py not found in repo")
20
 
21
  MODEL_PATH = os.environ.get("MODEL_PATH", "models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf")
22
 
@@ -30,9 +29,7 @@ def generate(prompt, max_tokens=128, temperature=0.7):
30
  "-temp", str(temperature)
31
  ]
32
  proc = subprocess.run(cmd, capture_output=True, text=True)
33
- if proc.returncode:
34
- return proc.stderr.strip()
35
- return proc.stdout.strip()
36
 
37
  iface = gr.Interface(
38
  fn=generate,
@@ -43,7 +40,7 @@ iface = gr.Interface(
43
  ],
44
  outputs=gr.Textbox(label="completion"),
45
  title="bitnet.cpp completion demo",
46
- description="auto-detects run_inference.py so it won’t 404"
47
  )
48
 
49
  if __name__ == "__main__":
 
2
  @spaces.GPU(duration=15)
3
  def gpu():
4
  print("[GPU] | GPU maintained.")
5
+
6
  import os
7
  import sys
8
  import subprocess
9
+ import urllib.request
10
  import gradio as gr
11
 
12
+ # download run_inference.py at startup if it’s missing
13
+ SCRIPT_PATH = os.path.join(os.getcwd(), "run_inference.py")
14
+ if not os.path.isfile(SCRIPT_PATH):
15
+ urllib.request.urlretrieve(
16
+ "https://raw.githubusercontent.com/microsoft/BitNet/main/run_inference.py",
17
+ SCRIPT_PATH
18
+ )
 
 
19
 
20
  MODEL_PATH = os.environ.get("MODEL_PATH", "models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf")
21
 
 
29
  "-temp", str(temperature)
30
  ]
31
  proc = subprocess.run(cmd, capture_output=True, text=True)
32
+ return proc.stdout.strip() if proc.returncode == 0 else proc.stderr.strip()
 
 
33
 
34
  iface = gr.Interface(
35
  fn=generate,
 
40
  ],
41
  outputs=gr.Textbox(label="completion"),
42
  title="bitnet.cpp completion demo",
43
+ description="downloads inference script via python so no bash needed"
44
  )
45
 
46
  if __name__ == "__main__":