Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,26 +9,26 @@ import subprocess
|
|
9 |
import multiprocessing
|
10 |
import gradio as gr
|
11 |
|
12 |
-
bitnet_dir = os.path.join(os.getcwd(),
|
13 |
if not os.path.isdir(bitnet_dir):
|
14 |
-
subprocess.run([
|
15 |
-
build_dir = os.path.join(bitnet_dir,
|
16 |
if not os.path.isdir(build_dir):
|
17 |
os.makedirs(build_dir, exist_ok=True)
|
18 |
-
subprocess.run([
|
19 |
-
subprocess.run([
|
20 |
|
21 |
-
script_path = os.path.join(bitnet_dir,
|
22 |
-
model_path = os.environ.get(
|
23 |
|
24 |
def generate(prompt, max_tokens=128, temperature=0.7):
|
25 |
cmd = [
|
26 |
sys.executable,
|
27 |
script_path,
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
]
|
33 |
proc = subprocess.run(cmd, cwd=bitnet_dir, capture_output=True, text=True)
|
34 |
return proc.stdout.strip() if proc.returncode == 0 else proc.stderr.strip()
|
@@ -36,13 +36,13 @@ def generate(prompt, max_tokens=128, temperature=0.7):
|
|
36 |
iface = gr.Interface(
|
37 |
fn=generate,
|
38 |
inputs=[
|
39 |
-
gr.Textbox(lines=2, placeholder=
|
40 |
-
gr.Slider(1, 512, value=128, step=1, label=
|
41 |
-
gr.Slider(0.0, 1.0, value=0.7, step=0.01, label=
|
42 |
],
|
43 |
-
outputs=gr.Textbox(label=
|
44 |
-
title=
|
45 |
)
|
46 |
|
47 |
-
if __name__ ==
|
48 |
iface.launch()
|
|
|
9 |
import multiprocessing
|
10 |
import gradio as gr
|
11 |
|
12 |
+
bitnet_dir = os.path.join(os.getcwd(), "bitnet")
|
13 |
if not os.path.isdir(bitnet_dir):
|
14 |
+
subprocess.run(["git", "clone", "--depth", "1", "--recursive", "https://github.com/microsoft/BitNet.git", "bitnet"], check=True)
|
15 |
+
build_dir = os.path.join(bitnet_dir, "build")
|
16 |
if not os.path.isdir(build_dir):
|
17 |
os.makedirs(build_dir, exist_ok=True)
|
18 |
+
subprocess.run(["cmake", ".."], cwd=build_dir, check=True)
|
19 |
+
subprocess.run(["cmake", "--build", ".", "--config", "Release", "--parallel", str(multiprocessing.cpu_count())], cwd=build_dir, check=True)
|
20 |
|
21 |
+
script_path = os.path.join(bitnet_dir, "run_inference.py")
|
22 |
+
model_path = os.environ.get("MODEL_PATH", "models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf")
|
23 |
|
24 |
def generate(prompt, max_tokens=128, temperature=0.7):
|
25 |
cmd = [
|
26 |
sys.executable,
|
27 |
script_path,
|
28 |
+
"-m", model_path,
|
29 |
+
"-p", prompt,
|
30 |
+
"-n", str(max_tokens),
|
31 |
+
"-temp", str(temperature)
|
32 |
]
|
33 |
proc = subprocess.run(cmd, cwd=bitnet_dir, capture_output=True, text=True)
|
34 |
return proc.stdout.strip() if proc.returncode == 0 else proc.stderr.strip()
|
|
|
36 |
iface = gr.Interface(
|
37 |
fn=generate,
|
38 |
inputs=[
|
39 |
+
gr.Textbox(lines=2, placeholder="enter your prompt here", label="prompt"),
|
40 |
+
gr.Slider(1, 512, value=128, step=1, label="max tokens"),
|
41 |
+
gr.Slider(0.0, 1.0, value=0.7, step=0.01, label="temperature")
|
42 |
],
|
43 |
+
outputs=gr.Textbox(label="completion"),
|
44 |
+
title="bitnet.cpp completion demo"
|
45 |
)
|
46 |
|
47 |
+
if __name__ == "__main__":
|
48 |
iface.launch()
|