Spaces:
Running
Running
fix space, update packages (#75)
Browse files- fix: update packages (3642047ee41b6660126a9f3cacdf70cd64d8c9f2)
- fix: update packages (833f7a4e9ee0d35384861d2f7149c895f126a908)
- README.md +1 -1
- app.py +39 -28
- requirements.txt +4 -3
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🐐
|
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
hf_oauth: true
|
| 9 |
hf_oauth_scopes:
|
| 10 |
- read-repos
|
|
|
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.50.0
|
| 8 |
hf_oauth: true
|
| 9 |
hf_oauth_scopes:
|
| 10 |
- read-repos
|
app.py
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import tempfile
|
|
|
|
| 3 |
|
| 4 |
os.environ["HF_HUB_CACHE"] = "cache"
|
|
|
|
| 5 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
from huggingface_hub import HfApi
|
| 9 |
from huggingface_hub import whoami
|
| 10 |
from huggingface_hub import ModelCard
|
|
|
|
| 11 |
from huggingface_hub import scan_cache_dir
|
| 12 |
from huggingface_hub import logging
|
| 13 |
|
|
@@ -32,15 +36,6 @@ QUANT_PARAMS = {
|
|
| 32 |
"Q8": 8,
|
| 33 |
}
|
| 34 |
|
| 35 |
-
def list_files_in_folder(folder_path):
|
| 36 |
-
# List all files and directories in the specified folder
|
| 37 |
-
all_items = os.listdir(folder_path)
|
| 38 |
-
|
| 39 |
-
# Filter out only files
|
| 40 |
-
files = [item for item in all_items if os.path.isfile(os.path.join(folder_path, item))]
|
| 41 |
-
|
| 42 |
-
return files
|
| 43 |
-
|
| 44 |
def clear_hf_cache_space():
|
| 45 |
scan = scan_cache_dir()
|
| 46 |
to_delete = []
|
|
@@ -89,29 +84,42 @@ def upload_to_hub(path, upload_repo, hf_path, oauth_token):
|
|
| 89 |
|
| 90 |
api = HfApi(token=oauth_token.token)
|
| 91 |
api.create_repo(repo_id=upload_repo, exist_ok=True)
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
print(files)
|
| 95 |
-
for file in files:
|
| 96 |
-
file_path = os.path.join(path, file)
|
| 97 |
-
print(f"Uploading file: {file_path}")
|
| 98 |
-
api.upload_file(
|
| 99 |
-
path_or_fileobj=file_path,
|
| 100 |
-
path_in_repo=file,
|
| 101 |
-
repo_id=upload_repo,
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
print(f"Upload successful, go to https://huggingface.co/{upload_repo} for details.")
|
| 105 |
|
| 106 |
def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
| 107 |
-
if oauth_token.token is None:
|
| 108 |
raise ValueError("You must be logged in to use MLX-my-repo")
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
model_name = model_id.split('/')[-1]
|
| 111 |
username = whoami(oauth_token.token)["name"]
|
| 112 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# Fail early if the tokenizer requires custom code
|
| 114 |
-
_ = AutoTokenizer.from_pretrained(model_id, trust_remote_code=False)
|
| 115 |
|
| 116 |
if q_method == "FP16":
|
| 117 |
upload_repo = f"{username}/{model_name}-mlx-fp16"
|
|
@@ -137,17 +145,20 @@ def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
|
| 137 |
"llama.png",
|
| 138 |
)
|
| 139 |
except Exception as e:
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
finally:
|
| 142 |
clear_hf_cache_space()
|
| 143 |
print("Folder cleaned up successfully!")
|
| 144 |
|
| 145 |
-
|
| 146 |
.gradio-container {overflow-y: auto;}
|
| 147 |
"""
|
| 148 |
|
| 149 |
# Create Gradio interface
|
| 150 |
-
with gr.Blocks(css=
|
| 151 |
gr.Markdown("You must be logged in to use MLX-my-repo.")
|
| 152 |
gr.LoginButton(min_width=250)
|
| 153 |
|
|
@@ -165,7 +176,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 165 |
filterable=False,
|
| 166 |
visible=True
|
| 167 |
)
|
| 168 |
-
|
| 169 |
iface = gr.Interface(
|
| 170 |
fn=process_model,
|
| 171 |
inputs=[
|
|
|
|
| 1 |
import os
|
| 2 |
+
import shutil
|
| 3 |
import tempfile
|
| 4 |
+
import traceback
|
| 5 |
|
| 6 |
os.environ["HF_HUB_CACHE"] = "cache"
|
| 7 |
+
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
| 8 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
from huggingface_hub import HfApi
|
| 12 |
from huggingface_hub import whoami
|
| 13 |
from huggingface_hub import ModelCard
|
| 14 |
+
from huggingface_hub import model_info
|
| 15 |
from huggingface_hub import scan_cache_dir
|
| 16 |
from huggingface_hub import logging
|
| 17 |
|
|
|
|
| 36 |
"Q8": 8,
|
| 37 |
}
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def clear_hf_cache_space():
|
| 40 |
scan = scan_cache_dir()
|
| 41 |
to_delete = []
|
|
|
|
| 84 |
|
| 85 |
api = HfApi(token=oauth_token.token)
|
| 86 |
api.create_repo(repo_id=upload_repo, exist_ok=True)
|
| 87 |
+
api.upload_folder(folder_path=path, repo_id=upload_repo)
|
| 88 |
|
| 89 |
+
print(f"Upload successful, go to https://huggingface.co/{upload_repo} for details.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
| 92 |
+
if oauth_token is None or oauth_token.token is None:
|
| 93 |
raise ValueError("You must be logged in to use MLX-my-repo")
|
| 94 |
+
|
| 95 |
+
# Set token for mlx_lm.convert which doesn't accept a token parameter
|
| 96 |
+
os.environ["HF_TOKEN"] = oauth_token.token
|
| 97 |
+
|
| 98 |
model_name = model_id.split('/')[-1]
|
| 99 |
username = whoami(oauth_token.token)["name"]
|
| 100 |
try:
|
| 101 |
+
# Check model size vs available disk (need ~2x for download + conversion)
|
| 102 |
+
info = model_info(model_id, token=oauth_token.token)
|
| 103 |
+
if info.safetensors and info.safetensors.total:
|
| 104 |
+
model_bytes = info.safetensors.total
|
| 105 |
+
elif info.siblings:
|
| 106 |
+
model_bytes = sum(s.size or 0 for s in info.siblings)
|
| 107 |
+
else:
|
| 108 |
+
model_bytes = 0
|
| 109 |
+
if model_bytes > 0:
|
| 110 |
+
free_bytes = shutil.disk_usage(".").free
|
| 111 |
+
required_bytes = model_bytes * 2
|
| 112 |
+
if free_bytes < required_bytes:
|
| 113 |
+
model_gb = model_bytes / (1024**3)
|
| 114 |
+
free_gb = free_bytes / (1024**3)
|
| 115 |
+
raise ValueError(
|
| 116 |
+
f"Not enough disk space. Model is ~{model_gb:.1f}GB, "
|
| 117 |
+
f"need ~{model_gb * 2:.1f}GB for conversion, "
|
| 118 |
+
f"but only {free_gb:.1f}GB available."
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
# Fail early if the tokenizer requires custom code
|
| 122 |
+
_ = AutoTokenizer.from_pretrained(model_id, token=oauth_token.token, trust_remote_code=False)
|
| 123 |
|
| 124 |
if q_method == "FP16":
|
| 125 |
upload_repo = f"{username}/{model_name}-mlx-fp16"
|
|
|
|
| 145 |
"llama.png",
|
| 146 |
)
|
| 147 |
except Exception as e:
|
| 148 |
+
traceback.print_exc()
|
| 149 |
+
error_type = type(e).__name__
|
| 150 |
+
error_msg = str(e) or "No details available"
|
| 151 |
+
return (f"**{error_type}**: {error_msg}", "error.png")
|
| 152 |
finally:
|
| 153 |
clear_hf_cache_space()
|
| 154 |
print("Folder cleaned up successfully!")
|
| 155 |
|
| 156 |
+
CSS = """/* Custom CSS to allow scrolling */
|
| 157 |
.gradio-container {overflow-y: auto;}
|
| 158 |
"""
|
| 159 |
|
| 160 |
# Create Gradio interface
|
| 161 |
+
with gr.Blocks(css=CSS) as demo:
|
| 162 |
gr.Markdown("You must be logged in to use MLX-my-repo.")
|
| 163 |
gr.LoginButton(min_width=250)
|
| 164 |
|
|
|
|
| 176 |
filterable=False,
|
| 177 |
visible=True
|
| 178 |
)
|
| 179 |
+
|
| 180 |
iface = gr.Interface(
|
| 181 |
fn=process_model,
|
| 182 |
inputs=[
|
requirements.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
hf-transfer
|
| 2 |
-
|
| 3 |
-
|
|
|
|
| 4 |
APScheduler
|
| 5 |
mlx[cpu]
|
| 6 |
-
mlx-lm=
|
|
|
|
| 1 |
hf-transfer
|
| 2 |
+
audioop-lts
|
| 3 |
+
gradio[oauth]>=5.50.0,<6.0.0
|
| 4 |
+
gradio_huggingfacehub_search>=0.0.12
|
| 5 |
APScheduler
|
| 6 |
mlx[cpu]
|
| 7 |
+
mlx-lm>=0.31.2
|