Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,6 @@ import subprocess
|
|
3 |
import streamlit as st
|
4 |
from huggingface_hub import snapshot_download
|
5 |
|
6 |
-
import subprocess
|
7 |
-
|
8 |
def check_directory_path(directory_name: str) -> str:
|
9 |
if os.path.exists(directory_name):
|
10 |
path = os.path.abspath(directory_name)
|
@@ -16,9 +14,9 @@ QUANT_TYPES = [
|
|
16 |
"Q5_K_M", "Q5_K_S", "Q6_K"
|
17 |
]
|
18 |
|
19 |
-
model_dir_path=check_directory_path("llama.cpp")
|
20 |
|
21 |
-
def download_model(hf_model_name, output_dir="models"):
|
22 |
"""
|
23 |
Downloads a Hugging Face model and saves it locally.
|
24 |
"""
|
@@ -35,8 +33,8 @@ def convert_to_gguf(model_dir, output_file):
|
|
35 |
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
36 |
st.write(model_dir_path)
|
37 |
cmd = [
|
38 |
-
|
39 |
-
|
40 |
]
|
41 |
process = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
42 |
if process.returncode == 0:
|
@@ -54,10 +52,10 @@ def quantize_llama(model_path, quantized_output_path, quant_type):
|
|
54 |
subprocess.run(["chmod", "+x", quantize_path], check=True)
|
55 |
|
56 |
cmd = [
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
]
|
62 |
|
63 |
process = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
@@ -71,7 +69,7 @@ def automate_llama_quantization(hf_model_name, quant_type):
|
|
71 |
"""
|
72 |
Orchestrates the entire quantization process.
|
73 |
"""
|
74 |
-
output_dir = "models"
|
75 |
gguf_file = os.path.join(output_dir, f"{hf_model_name.replace('/', '_')}.gguf")
|
76 |
quantized_file = gguf_file.replace(".gguf", f"-{quant_type}.gguf")
|
77 |
|
@@ -107,5 +105,4 @@ if start_button:
|
|
107 |
quantized_model_path = automate_llama_quantization(hf_model_name, quant_type)
|
108 |
if quantized_model_path:
|
109 |
with open(quantized_model_path, "rb") as f:
|
110 |
-
st.download_button("⬇️ Download Quantized Model", f, file_name=os.path.basename(quantized_model_path))
|
111 |
-
|
|
|
3 |
import streamlit as st
|
4 |
from huggingface_hub import snapshot_download
|
5 |
|
|
|
|
|
6 |
def check_directory_path(directory_name: str) -> str:
|
7 |
if os.path.exists(directory_name):
|
8 |
path = os.path.abspath(directory_name)
|
|
|
14 |
"Q5_K_M", "Q5_K_S", "Q6_K"
|
15 |
]
|
16 |
|
17 |
+
model_dir_path = check_directory_path("/app/llama.cpp")
|
18 |
|
19 |
+
def download_model(hf_model_name, output_dir="/tmp/models"):
|
20 |
"""
|
21 |
Downloads a Hugging Face model and saves it locally.
|
22 |
"""
|
|
|
33 |
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
34 |
st.write(model_dir_path)
|
35 |
cmd = [
|
36 |
+
"python3", "/app/llama.cpp/convert_hf_to_gguf.py", model_dir,
|
37 |
+
"--outtype", "f16", "--outfile", output_file
|
38 |
]
|
39 |
process = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
40 |
if process.returncode == 0:
|
|
|
52 |
subprocess.run(["chmod", "+x", quantize_path], check=True)
|
53 |
|
54 |
cmd = [
|
55 |
+
"/app/llama.cpp/build/bin/llama-quantize",
|
56 |
+
model_path,
|
57 |
+
quantized_output_path,
|
58 |
+
quant_type
|
59 |
]
|
60 |
|
61 |
process = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
69 |
"""
|
70 |
Orchestrates the entire quantization process.
|
71 |
"""
|
72 |
+
output_dir = "/tmp/models"
|
73 |
gguf_file = os.path.join(output_dir, f"{hf_model_name.replace('/', '_')}.gguf")
|
74 |
quantized_file = gguf_file.replace(".gguf", f"-{quant_type}.gguf")
|
75 |
|
|
|
105 |
quantized_model_path = automate_llama_quantization(hf_model_name, quant_type)
|
106 |
if quantized_model_path:
|
107 |
with open(quantized_model_path, "rb") as f:
|
108 |
+
st.download_button("⬇️ Download Quantized Model", f, file_name=os.path.basename(quantized_model_path))
|
|