Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,11 @@ import subprocess
|
|
| 3 |
import streamlit as st
|
| 4 |
from huggingface_hub import snapshot_download, login
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def check_directory_path(directory_name: str) -> str:
|
| 7 |
if os.path.exists(directory_name):
|
| 8 |
path = os.path.abspath(directory_name)
|
|
@@ -31,7 +36,6 @@ def convert_to_gguf(model_dir, output_file):
|
|
| 31 |
"""
|
| 32 |
st.write(f"π Converting `{model_dir}` to GGUF format...")
|
| 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
|
|
@@ -116,7 +120,6 @@ def upload_to_huggingface(file_path, repo_id, token):
|
|
| 116 |
except Exception as e:
|
| 117 |
st.error(f"β Failed to upload file: {e}")
|
| 118 |
|
| 119 |
-
# Streamlit UI
|
| 120 |
st.title("π¦ LLaMA Model Quantization (llama.cpp)")
|
| 121 |
|
| 122 |
hf_model_name = st.text_input("Enter Hugging Face Model Name", "Qwen/Qwen2.5-1.5B")
|
|
@@ -125,20 +128,23 @@ start_button = st.button("π Start Quantization")
|
|
| 125 |
|
| 126 |
if start_button:
|
| 127 |
with st.spinner("Processing..."):
|
| 128 |
-
quantized_model_path = automate_llama_quantization(hf_model_name, quant_type)
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
if
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
if repo_id and hf_token:
|
| 141 |
-
with st.spinner("Uploading..."):
|
| 142 |
-
upload_to_huggingface(quantized_model_path, repo_id, hf_token)
|
| 143 |
-
else:
|
| 144 |
-
st.warning("Please provide a valid repository ID and Hugging Face token.")
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
from huggingface_hub import snapshot_download, login
|
| 5 |
|
| 6 |
+
if "quantized_model_path" not in st.session_state:
|
| 7 |
+
st.session_state.quantized_model_path = None
|
| 8 |
+
if "upload_to_hf" not in st.session_state:
|
| 9 |
+
st.session_state.upload_to_hf = False
|
| 10 |
+
|
| 11 |
def check_directory_path(directory_name: str) -> str:
|
| 12 |
if os.path.exists(directory_name):
|
| 13 |
path = os.path.abspath(directory_name)
|
|
|
|
| 36 |
"""
|
| 37 |
st.write(f"π Converting `{model_dir}` to GGUF format...")
|
| 38 |
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
|
|
|
| 39 |
cmd = [
|
| 40 |
"python3", "/app/llama.cpp/convert_hf_to_gguf.py", model_dir,
|
| 41 |
"--outtype", "f16", "--outfile", output_file
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
st.error(f"β Failed to upload file: {e}")
|
| 122 |
|
|
|
|
| 123 |
st.title("π¦ LLaMA Model Quantization (llama.cpp)")
|
| 124 |
|
| 125 |
hf_model_name = st.text_input("Enter Hugging Face Model Name", "Qwen/Qwen2.5-1.5B")
|
|
|
|
| 128 |
|
| 129 |
if start_button:
|
| 130 |
with st.spinner("Processing..."):
|
| 131 |
+
st.session_state.quantized_model_path = automate_llama_quantization(hf_model_name, quant_type)
|
| 132 |
+
|
| 133 |
+
if st.session_state.quantized_model_path:
|
| 134 |
+
with open(st.session_state.quantized_model_path, "rb") as f:
|
| 135 |
+
st.download_button("β¬οΈ Download Quantized Model", f, file_name=os.path.basename(st.session_state.quantized_model_path))
|
| 136 |
+
|
| 137 |
+
# Checkbox for upload section
|
| 138 |
+
st.session_state.upload_to_hf = st.checkbox("Upload to Hugging Face", value=st.session_state.upload_to_hf)
|
| 139 |
+
|
| 140 |
+
if st.session_state.upload_to_hf:
|
| 141 |
+
st.write("### Upload to Hugging Face")
|
| 142 |
+
repo_id = st.text_input("Enter Hugging Face Repository ID (e.g., 'username/repo-name')")
|
| 143 |
+
hf_token = st.text_input("Enter Hugging Face Token", type="password")
|
| 144 |
|
| 145 |
+
if st.button("π€ Upload to Hugging Face"):
|
| 146 |
+
if repo_id and hf_token:
|
| 147 |
+
with st.spinner("Uploading..."):
|
| 148 |
+
upload_to_huggingface(st.session_state.quantized_model_path, repo_id, hf_token)
|
| 149 |
+
else:
|
| 150 |
+
st.warning("Please provide a valid repository ID and Hugging Face token.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|