olegshulyakov commited on
Commit
9390868
·
verified ·
1 Parent(s): 2f216a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -33
app.py CHANGED
@@ -102,8 +102,8 @@ def upload_to_hub(path, upload_repo, hf_path, token):
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
- return ("You must be logged in to use MLX-my-repo", "error.png")
107
 
108
  token = oauth_token.token
109
  # Verify the token
@@ -113,7 +113,7 @@ def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
113
  username = user_info["name"]
114
  print(f"✅ Logged in as {username}")
115
  except Exception as e:
116
- return (f"❌ Authentication failed: {e}", "error.png")
117
 
118
  try:
119
  model_name = model_id.split('/')[-1]
@@ -148,46 +148,49 @@ def process_model(model_id, q_method, oauth_token: gr.OAuthToken | None):
148
  print(f"❌ Error: {e}")
149
  return (f"Error: {e}", "error.png")
150
  finally:
151
- # clear_hf_cache_space()
152
  print("Folder cleaned up successfully!")
153
 
154
  css="""/* Custom CSS to allow scrolling */
155
  .gradio-container {overflow-y: auto;}
156
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  # Create Gradio interface
158
  with gr.Blocks(css=css) as demo:
159
  gr.Markdown("You must be logged in to use MLX-my-repo.")
160
  gr.LoginButton(min_width=250)
161
 
162
- model_id = HuggingfaceHubSearch(
163
- label="Hub Model ID",
164
- placeholder="Search for model id on Huggingface",
165
- search_type="model",
166
- )
167
-
168
- q_method = gr.Dropdown(
169
- ["FP16", "Q2", "Q3", "Q4", "Q6", "Q8"],
170
- label="Conversion Method",
171
- info="MLX conversion type (FP16 for float16, Q2–Q8 for quantized models)",
172
- value="Q4",
173
- filterable=False,
174
- visible=True
175
- )
176
-
177
- iface = gr.Interface(
178
- fn=process_model,
179
- inputs=[
180
- model_id,
181
- q_method,
182
- ],
183
- outputs=[
184
- gr.Markdown(label="output"),
185
- gr.Image(show_label=False),
186
- ],
187
- title="Create your own MLX Models, blazingly fast ⚡!",
188
- description="The space takes an HF repo as an input, converts it to MLX format (FP16 or quantized), and creates a Public/Private repo under your HF user namespace.",
189
- api_name=False
190
- )
191
 
192
  def restart_space():
193
  HfApi().restart_space(repo_id="olegshulyakov/mlx-my-repo", token=HF_TOKEN, factory_reboot=True)
 
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 is None or oauth_token.token is None:
106
+ raise gr.Error("You must be logged in to use MLX-my-repo", "error.png")
107
 
108
  token = oauth_token.token
109
  # Verify the token
 
113
  username = user_info["name"]
114
  print(f"✅ Logged in as {username}")
115
  except Exception as e:
116
+ raise gr.Error(f"❌ Authentication failed: {e}", "error.png")
117
 
118
  try:
119
  model_name = model_id.split('/')[-1]
 
148
  print(f"❌ Error: {e}")
149
  return (f"Error: {e}", "error.png")
150
  finally:
151
+ clear_hf_cache_space()
152
  print("Folder cleaned up successfully!")
153
 
154
  css="""/* Custom CSS to allow scrolling */
155
  .gradio-container {overflow-y: auto;}
156
  """
157
+
158
+ model_id = HuggingfaceHubSearch(
159
+ label="Hub Model ID",
160
+ placeholder="Search for model id on Huggingface",
161
+ search_type="model",
162
+ )
163
+
164
+ q_method = gr.Dropdown(
165
+ ["FP16", "Q2", "Q3", "Q4", "Q6", "Q8"],
166
+ label="Conversion Method",
167
+ info="MLX conversion type (FP16 for float16, Q2–Q8 for quantized models)",
168
+ value="Q4",
169
+ filterable=False,
170
+ visible=True
171
+ )
172
+
173
+ iface = gr.Interface(
174
+ fn=process_model,
175
+ inputs=[
176
+ model_id,
177
+ q_method,
178
+ ],
179
+ outputs=[
180
+ gr.Markdown(label="output"),
181
+ gr.Image(show_label=False),
182
+ ],
183
+ title="Create your own MLX Models, blazingly fast ⚡!",
184
+ description="The space takes an HF repo as an input, converts it to MLX format (FP16 or quantized), and creates a Public/Private repo under your HF user namespace.",
185
+ api_name=False
186
+ )
187
+
188
  # Create Gradio interface
189
  with gr.Blocks(css=css) as demo:
190
  gr.Markdown("You must be logged in to use MLX-my-repo.")
191
  gr.LoginButton(min_width=250)
192
 
193
+ iface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  def restart_space():
196
  HfApi().restart_space(repo_id="olegshulyakov/mlx-my-repo", token=HF_TOKEN, factory_reboot=True)