Fix Gradio Demo

#162
by freddyaboulton HF staff - opened
Files changed (1) hide show
  1. app.py +78 -76
app.py CHANGED
@@ -324,82 +324,68 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
324
  css="""/* Custom CSS to allow scrolling */
325
  .gradio-container {overflow-y: auto;}
326
  """
327
- # Create Gradio interface
328
- with gr.Blocks(css=css) as demo:
329
- gr.Markdown("You must be logged in to use GGUF-my-repo.")
330
- gr.LoginButton(min_width=250)
331
-
332
- model_id = HuggingfaceHubSearch(
333
- label="Hub Model ID",
334
- placeholder="Search for model id on Huggingface",
335
- search_type="model",
336
- )
337
-
338
- q_method = gr.Dropdown(
339
- ["Q2_K", "Q3_K_S", "Q3_K_M", "Q3_K_L", "Q4_0", "Q4_K_S", "Q4_K_M", "Q5_0", "Q5_K_S", "Q5_K_M", "Q6_K", "Q8_0"],
340
- label="Quantization Method",
341
- info="GGML quantization type",
342
- value="Q4_K_M",
343
- filterable=False,
344
- visible=True
345
- )
346
-
347
- imatrix_q_method = gr.Dropdown(
348
- ["IQ3_M", "IQ3_XXS", "Q4_K_M", "Q4_K_S", "IQ4_NL", "IQ4_XS", "Q5_K_M", "Q5_K_S"],
349
- label="Imatrix Quantization Method",
350
- info="GGML imatrix quants type",
351
- value="IQ4_NL",
352
- filterable=False,
353
- visible=False
354
- )
355
-
356
- use_imatrix = gr.Checkbox(
357
- value=False,
358
- label="Use Imatrix Quantization",
359
- info="Use importance matrix for quantization."
360
- )
361
-
362
- private_repo = gr.Checkbox(
363
- value=False,
364
- label="Private Repo",
365
- info="Create a private repo under your username."
366
- )
367
-
368
- train_data_file = gr.File(
369
- label="Training Data File",
370
- file_types=["txt"],
371
- visible=False
372
- )
373
-
374
- split_model = gr.Checkbox(
375
- value=False,
376
- label="Split Model",
377
- info="Shard the model using gguf-split."
378
- )
379
-
380
- split_max_tensors = gr.Number(
381
- value=256,
382
- label="Max Tensors per File",
383
- info="Maximum number of tensors per file when splitting model.",
384
- visible=False
385
- )
386
-
387
- split_max_size = gr.Textbox(
388
- label="Max File Size",
389
- info="Maximum file size when splitting model (--split-max-size). May leave empty to use the default. Accepted suffixes: M, G. Example: 256M, 5G",
390
- visible=False
391
- )
392
-
393
- def update_visibility(use_imatrix):
394
- return gr.update(visible=not use_imatrix), gr.update(visible=use_imatrix), gr.update(visible=use_imatrix)
395
-
396
- use_imatrix.change(
397
- fn=update_visibility,
398
- inputs=use_imatrix,
399
- outputs=[q_method, imatrix_q_method, train_data_file]
400
- )
401
-
402
- iface = gr.Interface(
403
  fn=process_model,
404
  inputs=[
405
  model_id,
@@ -421,6 +407,13 @@ with gr.Blocks(css=css) as demo:
421
  api_name=False
422
  )
423
 
 
 
 
 
 
 
 
424
  def update_split_visibility(split_model):
425
  return gr.update(visible=split_model), gr.update(visible=split_model)
426
 
@@ -430,6 +423,15 @@ with gr.Blocks(css=css) as demo:
430
  outputs=[split_max_tensors, split_max_size]
431
  )
432
 
 
 
 
 
 
 
 
 
 
433
  def restart_space():
434
  HfApi().restart_space(repo_id="ggml-org/gguf-my-repo", token=HF_TOKEN, factory_reboot=True)
435
 
 
324
  css="""/* Custom CSS to allow scrolling */
325
  .gradio-container {overflow-y: auto;}
326
  """
327
+ model_id = HuggingfaceHubSearch(
328
+ label="Hub Model ID",
329
+ placeholder="Search for model id on Huggingface",
330
+ search_type="model",
331
+ )
332
+
333
+ q_method = gr.Dropdown(
334
+ ["Q2_K", "Q3_K_S", "Q3_K_M", "Q3_K_L", "Q4_0", "Q4_K_S", "Q4_K_M", "Q5_0", "Q5_K_S", "Q5_K_M", "Q6_K", "Q8_0"],
335
+ label="Quantization Method",
336
+ info="GGML quantization type",
337
+ value="Q4_K_M",
338
+ filterable=False,
339
+ visible=True
340
+ )
341
+
342
+ imatrix_q_method = gr.Dropdown(
343
+ ["IQ3_M", "IQ3_XXS", "Q4_K_M", "Q4_K_S", "IQ4_NL", "IQ4_XS", "Q5_K_M", "Q5_K_S"],
344
+ label="Imatrix Quantization Method",
345
+ info="GGML imatrix quants type",
346
+ value="IQ4_NL",
347
+ filterable=False,
348
+ visible=False
349
+ )
350
+
351
+ use_imatrix = gr.Checkbox(
352
+ value=False,
353
+ label="Use Imatrix Quantization",
354
+ info="Use importance matrix for quantization."
355
+ )
356
+
357
+ private_repo = gr.Checkbox(
358
+ value=False,
359
+ label="Private Repo",
360
+ info="Create a private repo under your username."
361
+ )
362
+
363
+ train_data_file = gr.File(
364
+ label="Training Data File",
365
+ file_types=["txt"],
366
+ visible=False
367
+ )
368
+
369
+ split_model = gr.Checkbox(
370
+ value=False,
371
+ label="Split Model",
372
+ info="Shard the model using gguf-split."
373
+ )
374
+
375
+ split_max_tensors = gr.Number(
376
+ value=256,
377
+ label="Max Tensors per File",
378
+ info="Maximum number of tensors per file when splitting model.",
379
+ visible=False
380
+ )
381
+
382
+ split_max_size = gr.Textbox(
383
+ label="Max File Size",
384
+ info="Maximum file size when splitting model (--split-max-size). May leave empty to use the default. Accepted suffixes: M, G. Example: 256M, 5G",
385
+ visible=False
386
+ )
387
+
388
+ iface = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  fn=process_model,
390
  inputs=[
391
  model_id,
 
407
  api_name=False
408
  )
409
 
410
+ # Create Gradio interface
411
+ with gr.Blocks(css=css) as demo:
412
+ gr.Markdown("You must be logged in to use GGUF-my-repo.")
413
+ gr.LoginButton(min_width=250)
414
+
415
+ iface.render()
416
+
417
  def update_split_visibility(split_model):
418
  return gr.update(visible=split_model), gr.update(visible=split_model)
419
 
 
423
  outputs=[split_max_tensors, split_max_size]
424
  )
425
 
426
+ def update_visibility(use_imatrix):
427
+ return gr.update(visible=not use_imatrix), gr.update(visible=use_imatrix), gr.update(visible=use_imatrix)
428
+
429
+ use_imatrix.change(
430
+ fn=update_visibility,
431
+ inputs=use_imatrix,
432
+ outputs=[q_method, imatrix_q_method, train_data_file]
433
+ )
434
+
435
  def restart_space():
436
  HfApi().restart_space(repo_id="ggml-org/gguf-my-repo", token=HF_TOKEN, factory_reboot=True)
437