Spaces:
Running
Running
Convert
Browse files- app.py +9 -8
- converted/.keep +0 -0
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import shutil
|
3 |
-
import
|
4 |
-
import signal
|
5 |
|
6 |
os.environ["HF_HUB_CACHE"] = "cache"
|
7 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
@@ -100,18 +99,20 @@ def process_model(model_id, q_method,oauth_token: gr.OAuthToken | None):
|
|
100 |
try:
|
101 |
upload_repo = username + "/" + model_name + "-mlx"
|
102 |
print(upload_repo)
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
107 |
return (
|
108 |
-
f'Find your repo <a href
|
109 |
"llama.png",
|
110 |
)
|
111 |
except Exception as e:
|
112 |
return (f"Error: {e}", "error.png")
|
113 |
finally:
|
114 |
-
shutil.rmtree("mlx_model", ignore_errors=True)
|
115 |
clear_hf_cache_space()
|
116 |
print("Folder cleaned up successfully!")
|
117 |
|
|
|
1 |
import os
|
2 |
import shutil
|
3 |
+
import tempfile
|
|
|
4 |
|
5 |
os.environ["HF_HUB_CACHE"] = "cache"
|
6 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
|
|
99 |
try:
|
100 |
upload_repo = username + "/" + model_name + "-mlx"
|
101 |
print(upload_repo)
|
102 |
+
with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
|
103 |
+
# The target dir must not exist
|
104 |
+
mlx_path = os.path.join(tmpdir, "mlx")
|
105 |
+
convert(model_id, mlx_path=mlx_path, quantize=True)
|
106 |
+
print("Conversion done")
|
107 |
+
upload_to_hub(path=mlx_path, upload_repo=upload_repo, hf_path=model_id, token=oauth_token.token)
|
108 |
+
print("Upload done")
|
109 |
return (
|
110 |
+
f'Find your repo <a href="https://hf.co/{upload_repo}" target="_blank" style="text-decoration:underline">here</a>',
|
111 |
"llama.png",
|
112 |
)
|
113 |
except Exception as e:
|
114 |
return (f"Error: {e}", "error.png")
|
115 |
finally:
|
|
|
116 |
clear_hf_cache_space()
|
117 |
print("Folder cleaned up successfully!")
|
118 |
|
converted/.keep
ADDED
File without changes
|