Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,12 +62,12 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
62 |
if oauth_token.token is None:
|
63 |
raise ValueError("You must be logged in to use GGUF-my-repo")
|
64 |
model_name = model_id.split('/')[-1]
|
|
|
65 |
|
66 |
try:
|
67 |
api = HfApi(token=oauth_token.token)
|
68 |
api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False)
|
69 |
|
70 |
-
# Find all files in the downloaded model directory
|
71 |
all_files = []
|
72 |
for root, _, files in os.walk(model_name):
|
73 |
for file in files:
|
@@ -76,7 +76,6 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
76 |
if not all_files:
|
77 |
raise FileNotFoundError("No files found in the downloaded model directory.")
|
78 |
|
79 |
-
# Attempt conversion for all files, regardless of type
|
80 |
for file_path in all_files:
|
81 |
try:
|
82 |
gguf_model_file = f"{os.path.splitext(file_path)[0]}.gguf"
|
@@ -84,11 +83,11 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
84 |
result = subprocess.run(conversion_command, shell=True, capture_output=True)
|
85 |
if result.returncode == 0:
|
86 |
model_file = gguf_model_file
|
87 |
-
break
|
88 |
except Exception as e:
|
89 |
print(f"Conversion attempt failed for {file_path}: {e}")
|
90 |
|
91 |
-
if
|
92 |
raise Exception("Unable to find or convert a suitable model file to GGUF format.")
|
93 |
|
94 |
imatrix_path = "llama.cpp/imatrix.dat"
|
@@ -108,7 +107,6 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
108 |
quantized_gguf_name = f"{model_name.lower()}-{imatrix_q_method.lower()}-imat.gguf" if use_imatrix else f"{model_name.lower()}-{q_method.lower()}.gguf"
|
109 |
quantized_gguf_path = quantized_gguf_name
|
110 |
|
111 |
-
# Quantize the model
|
112 |
os.chdir("llama.cpp")
|
113 |
if use_imatrix:
|
114 |
quantise_ggml = f"./llama-quantize --imatrix {imatrix_path} ../{model_file} ../{quantized_gguf_path} {imatrix_q_method}"
|
@@ -123,13 +121,6 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
123 |
new_repo_url = api.create_repo(repo_id=f"{username}/{model_name}-{imatrix_q_method if use_imatrix else q_method}-GGUF", exist_ok=True, private=private_repo)
|
124 |
new_repo_id = new_repo_url.repo_id
|
125 |
|
126 |
-
try:
|
127 |
-
card = ModelCard.load(model_id, token=oauth_token.token)
|
128 |
-
except:
|
129 |
-
card = ModelCard("")
|
130 |
-
if card.data.tags is None:
|
131 |
-
card.data.tags = []
|
132 |
-
|
133 |
if split_model:
|
134 |
split_upload_model(quantized_gguf_path, new_repo_id, oauth_token, split_max_tensors, split_max_size)
|
135 |
else:
|
@@ -141,8 +132,7 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
141 |
)
|
142 |
except Exception as e:
|
143 |
raise Exception(f"Error uploading quantized model: {e}")
|
144 |
-
|
145 |
-
|
146 |
if use_imatrix and os.path.isfile(imatrix_path):
|
147 |
try:
|
148 |
api.upload_file(
|
@@ -153,12 +143,6 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
153 |
except Exception as e:
|
154 |
raise Exception(f"Error uploading imatrix.dat: {e}")
|
155 |
|
156 |
-
api.upload_file(
|
157 |
-
path_or_fileobj=f"README.md",
|
158 |
-
path_in_repo=f"README.md",
|
159 |
-
repo_id=new_repo_id,
|
160 |
-
)
|
161 |
-
|
162 |
return (
|
163 |
f'Find your repo <a href=\'{new_repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
|
164 |
"llama.png",
|
|
|
62 |
if oauth_token.token is None:
|
63 |
raise ValueError("You must be logged in to use GGUF-my-repo")
|
64 |
model_name = model_id.split('/')[-1]
|
65 |
+
model_file = None
|
66 |
|
67 |
try:
|
68 |
api = HfApi(token=oauth_token.token)
|
69 |
api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False)
|
70 |
|
|
|
71 |
all_files = []
|
72 |
for root, _, files in os.walk(model_name):
|
73 |
for file in files:
|
|
|
76 |
if not all_files:
|
77 |
raise FileNotFoundError("No files found in the downloaded model directory.")
|
78 |
|
|
|
79 |
for file_path in all_files:
|
80 |
try:
|
81 |
gguf_model_file = f"{os.path.splitext(file_path)[0]}.gguf"
|
|
|
83 |
result = subprocess.run(conversion_command, shell=True, capture_output=True)
|
84 |
if result.returncode == 0:
|
85 |
model_file = gguf_model_file
|
86 |
+
break
|
87 |
except Exception as e:
|
88 |
print(f"Conversion attempt failed for {file_path}: {e}")
|
89 |
|
90 |
+
if model_file is None:
|
91 |
raise Exception("Unable to find or convert a suitable model file to GGUF format.")
|
92 |
|
93 |
imatrix_path = "llama.cpp/imatrix.dat"
|
|
|
107 |
quantized_gguf_name = f"{model_name.lower()}-{imatrix_q_method.lower()}-imat.gguf" if use_imatrix else f"{model_name.lower()}-{q_method.lower()}.gguf"
|
108 |
quantized_gguf_path = quantized_gguf_name
|
109 |
|
|
|
110 |
os.chdir("llama.cpp")
|
111 |
if use_imatrix:
|
112 |
quantise_ggml = f"./llama-quantize --imatrix {imatrix_path} ../{model_file} ../{quantized_gguf_path} {imatrix_q_method}"
|
|
|
121 |
new_repo_url = api.create_repo(repo_id=f"{username}/{model_name}-{imatrix_q_method if use_imatrix else q_method}-GGUF", exist_ok=True, private=private_repo)
|
122 |
new_repo_id = new_repo_url.repo_id
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if split_model:
|
125 |
split_upload_model(quantized_gguf_path, new_repo_id, oauth_token, split_max_tensors, split_max_size)
|
126 |
else:
|
|
|
132 |
)
|
133 |
except Exception as e:
|
134 |
raise Exception(f"Error uploading quantized model: {e}")
|
135 |
+
|
|
|
136 |
if use_imatrix and os.path.isfile(imatrix_path):
|
137 |
try:
|
138 |
api.upload_file(
|
|
|
143 |
except Exception as e:
|
144 |
raise Exception(f"Error uploading imatrix.dat: {e}")
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
return (
|
147 |
f'Find your repo <a href=\'{new_repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
|
148 |
"llama.png",
|