olegshulyakov commited on
Commit
512570f
·
verified ·
1 Parent(s): f9def96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -35
app.py CHANGED
@@ -20,7 +20,7 @@ import mlx_lm
20
  from mlx_lm import convert
21
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
23
- SPACE_HOST = os.environ.get("SPACE_HOST")
24
 
25
  # I'm not sure if we need to add more stuff here
26
  QUANT_PARAMS = {
@@ -155,49 +155,47 @@ 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(redirect=f"https://{SPACE_HOST}/login/callback")
 
 
 
 
 
 
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)
197
 
198
  scheduler = BackgroundScheduler()
199
  scheduler.add_job(restart_space, "interval", seconds=21600)
200
  scheduler.start()
201
 
202
  # Launch the interface
203
- demo.queue(default_concurrency_limit=1, max_size=5).launch(debug=True, show_api=False)
 
20
  from mlx_lm import convert
21
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
23
+ SPACE_ID = os.environ.get("SPACE_ID")
24
 
25
  # I'm not sure if we need to add more stuff here
26
  QUANT_PARAMS = {
 
155
  .gradio-container {overflow-y: auto;}
156
  """
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  # Create Gradio interface
159
  with gr.Blocks(css=css) as demo:
160
  gr.Markdown("You must be logged in to use MLX-my-repo.")
161
+ gr.LoginButton()
162
+
163
+ model_id = HuggingfaceHubSearch(
164
+ label="Hub Model ID",
165
+ placeholder="Search for model id on Huggingface",
166
+ search_type="model",
167
+ )
168
 
169
+ q_method = gr.Dropdown(
170
+ ["FP16", "Q2", "Q3", "Q4", "Q6", "Q8"],
171
+ label="Conversion Method",
172
+ info="MLX conversion type (FP16 for float16, Q2–Q8 for quantized models)",
173
+ value="Q4",
174
+ filterable=False,
175
+ visible=True
176
+ )
177
+
178
+ iface = gr.Interface(
179
+ fn=process_model,
180
+ inputs=[
181
+ model_id,
182
+ q_method,
183
+ ],
184
+ outputs=[
185
+ gr.Markdown(label="output"),
186
+ gr.Image(show_label=False),
187
+ ],
188
+ title="Create your own MLX Models, blazingly fast ⚡!",
189
+ 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.",
190
+ api_name=False
191
+ )
192
 
193
  def restart_space():
194
+ HfApi().restart_space(repo_id=SPACE_ID, token=HF_TOKEN, factory_reboot=True)
195
 
196
  scheduler = BackgroundScheduler()
197
  scheduler.add_job(restart_space, "interval", seconds=21600)
198
  scheduler.start()
199
 
200
  # Launch the interface
201
+ demo.launch()