Spaces:
Running
Running
Oleg Shulyakov
commited on
Commit
·
438ce1e
1
Parent(s):
d1518f3
Fix model naming
Browse files
app.py
CHANGED
@@ -33,10 +33,10 @@ QUANT_PARAMS = {
|
|
33 |
def list_files_in_folder(folder_path):
|
34 |
# List all files and directories in the specified folder
|
35 |
all_items = os.listdir(folder_path)
|
36 |
-
|
37 |
# Filter out only files
|
38 |
files = [item for item in all_items if os.path.isfile(os.path.join(folder_path, item))]
|
39 |
-
|
40 |
return files
|
41 |
|
42 |
def clear_hf_cache_space():
|
@@ -98,18 +98,18 @@ def upload_to_hub(path, upload_repo, hf_path, oauth_token):
|
|
98 |
path_in_repo=file,
|
99 |
repo_id=upload_repo,
|
100 |
)
|
101 |
-
|
102 |
-
print(f"Upload successful, go to https://huggingface.co/{upload_repo} for details.")
|
103 |
|
104 |
def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
105 |
if oauth_token.token is None:
|
106 |
raise ValueError("You must be logged in to use MLX-my-repo")
|
107 |
-
|
108 |
model_name = model_id.split('/')[-1]
|
109 |
username = whoami(oauth_token.token)["name"]
|
110 |
try:
|
111 |
if q_method == "FP16":
|
112 |
-
upload_repo = f"{username}/{model_name}-
|
113 |
with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
|
114 |
# The target directory must not exist
|
115 |
mlx_path = os.path.join(tmpdir, "mlx")
|
@@ -119,7 +119,7 @@ def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
|
119 |
print("Upload done")
|
120 |
else:
|
121 |
q_bits = QUANT_PARAMS[q_method]
|
122 |
-
upload_repo = f"{username}/{model_name}-
|
123 |
with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
|
124 |
# The target directory must not exist
|
125 |
mlx_path = os.path.join(tmpdir, "mlx")
|
@@ -141,7 +141,7 @@ css="""/* Custom CSS to allow scrolling */
|
|
141 |
.gradio-container {overflow-y: auto;}
|
142 |
"""
|
143 |
# Create Gradio interface
|
144 |
-
with gr.Blocks(css=css) as demo:
|
145 |
gr.Markdown("You must be logged in to use MLX-my-repo.")
|
146 |
gr.LoginButton(min_width=250)
|
147 |
|
@@ -159,7 +159,7 @@ with gr.Blocks(css=css) as demo:
|
|
159 |
filterable=False,
|
160 |
visible=True
|
161 |
)
|
162 |
-
|
163 |
iface = gr.Interface(
|
164 |
fn=process_model,
|
165 |
inputs=[
|
|
|
33 |
def list_files_in_folder(folder_path):
|
34 |
# List all files and directories in the specified folder
|
35 |
all_items = os.listdir(folder_path)
|
36 |
+
|
37 |
# Filter out only files
|
38 |
files = [item for item in all_items if os.path.isfile(os.path.join(folder_path, item))]
|
39 |
+
|
40 |
return files
|
41 |
|
42 |
def clear_hf_cache_space():
|
|
|
98 |
path_in_repo=file,
|
99 |
repo_id=upload_repo,
|
100 |
)
|
101 |
+
|
102 |
+
print(f"Upload successful, go to https://huggingface.co/{upload_repo} for details.")
|
103 |
|
104 |
def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
|
105 |
if oauth_token.token is None:
|
106 |
raise ValueError("You must be logged in to use MLX-my-repo")
|
107 |
+
|
108 |
model_name = model_id.split('/')[-1]
|
109 |
username = whoami(oauth_token.token)["name"]
|
110 |
try:
|
111 |
if q_method == "FP16":
|
112 |
+
upload_repo = f"{username}/{model_name}-fp16"
|
113 |
with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
|
114 |
# The target directory must not exist
|
115 |
mlx_path = os.path.join(tmpdir, "mlx")
|
|
|
119 |
print("Upload done")
|
120 |
else:
|
121 |
q_bits = QUANT_PARAMS[q_method]
|
122 |
+
upload_repo = f"{username}/{model_name}-{q_bits}bit"
|
123 |
with tempfile.TemporaryDirectory(dir="converted") as tmpdir:
|
124 |
# The target directory must not exist
|
125 |
mlx_path = os.path.join(tmpdir, "mlx")
|
|
|
141 |
.gradio-container {overflow-y: auto;}
|
142 |
"""
|
143 |
# Create Gradio interface
|
144 |
+
with gr.Blocks(css=css) as demo:
|
145 |
gr.Markdown("You must be logged in to use MLX-my-repo.")
|
146 |
gr.LoginButton(min_width=250)
|
147 |
|
|
|
159 |
filterable=False,
|
160 |
visible=True
|
161 |
)
|
162 |
+
|
163 |
iface = gr.Interface(
|
164 |
fn=process_model,
|
165 |
inputs=[
|