dagloop5 commited on
Commit
36aa8df
·
verified ·
1 Parent(s): d0cfcec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -67
app.py CHANGED
@@ -77,11 +77,6 @@ MAX_IMAGE_SLOTS, OPEN_IMAGE_SLOTS = 9, 2
77
 
78
  MIN_STEPS = 4
79
 
80
- SETTINGS_HELP = """Saves the prompt, the canvas and the sliders — everything typed rather than uploaded. Images,
81
- audio and video are not saved: gradio keeps them in a temporary folder that is gone by the next visit, so a saved
82
- path would come back as a dead file.
83
- """
84
-
85
  # Seconds of GPU one request needs, from the packed sequence it is about to denoise: linear in the rows for the
86
  # matmuls, quadratic for the attention, against the AoTI block package this Space runs.
87
  STEP_LINEAR, STEP_QUADRATIC, SAFETY = 1.1745e-4, 3.8396e-9, 1.3
@@ -528,55 +523,6 @@ def generate(
528
  )
529
  return path, refined, gr.update(visible=bool(refined))
530
 
531
-
532
- # ----------------------------------------------------------------------------------------------------------------
533
- # Settings file
534
- # ----------------------------------------------------------------------------------------------------------------
535
- # Everything typed rather than uploaded, so a session can be picked up where it was left off. The references
536
- # themselves are deliberately left out: gradio hands them over as paths into a per-session temporary directory that
537
- # is gone by the next visit, so a saved path would restore as a dead file rather than as the image.
538
-
539
- SETTINGS_VERSION = 1
540
- SETTINGS_KEYS = ["prompt", "upsample", "canvas", "match", "duration", "steps", "seed"]
541
-
542
-
543
- def save_settings(*values):
544
- """Write the current controls to a `.json` and reveal it for download."""
545
- payload = {"version": SETTINGS_VERSION, "saved": time.strftime("%Y-%m-%d %H:%M:%S")}
546
- payload.update(dict(zip(SETTINGS_KEYS, values)))
547
-
548
- directory = os.path.join(tempfile.gettempdir(), "h3-settings")
549
- os.makedirs(directory, exist_ok=True)
550
- path = os.path.join(directory, f"h3-settings-{int(time.time())}.json")
551
- with open(path, "w", encoding="utf-8") as handle:
552
- json.dump(payload, handle, ensure_ascii=False, indent=2, default=str)
553
- return gr.update(value=path, visible=True)
554
-
555
-
556
- def load_settings(path):
557
- """Restore the controls from a `.json`. A key the file does not carry leaves its control alone, so a settings
558
- file written by an older version of this Space still loads."""
559
- if not path:
560
- return [gr.update() for _ in SETTINGS_KEYS]
561
- try:
562
- with open(path, encoding="utf-8") as handle:
563
- payload = json.load(handle)
564
- except Exception as error:
565
- raise gr.Error(f"Файлът с настройки не се чете: `{type(error).__name__}: {error}`")
566
- if not isinstance(payload, dict):
567
- raise gr.Error("Това не е файл с настройки на този Space.")
568
-
569
- updates = []
570
- for key in SETTINGS_KEYS:
571
- value = payload.get(key)
572
- # An unknown canvas label would be rejected by the conditioner, which is the wrong place to find out.
573
- if value is None or (key == "canvas" and value not in CANVASES):
574
- updates.append(gr.update())
575
- else:
576
- updates.append(gr.update(value=value))
577
- return updates
578
-
579
-
580
  load_models()
581
 
582
  INTRO = """# MiniMax-H3 Reference
@@ -641,14 +587,6 @@ with gr.Blocks(title="MiniMax-H3 Reference Custom Lora") as demo:
641
  steps = gr.Slider(label="Steps", minimum=MIN_STEPS, maximum=40, step=1, value=28)
642
  seed = gr.Number(label="Seed", value=42, precision=0)
643
 
644
- with gr.Accordion("Settings file", open=False):
645
- gr.Markdown(SETTINGS_HELP)
646
- save = gr.Button("Save settings to .json", size="sm")
647
- settings_download = gr.File(label="Your settings", visible=False, interactive=False)
648
- settings_upload = gr.File(
649
- label="Load a settings .json", file_types=[".json"], type="filepath"
650
- )
651
-
652
  with gr.Column():
653
  result = gr.Video(label="Video + soundtrack")
654
  # An output, so it can be revealed only for a request that asked for a rewrite.
@@ -677,11 +615,6 @@ with gr.Blocks(title="MiniMax-H3 Reference Custom Lora") as demo:
677
  image.change(auto_canvas, image, canvas, show_progress="hidden", api_name=False)
678
  video.change(auto_canvas, video, canvas, show_progress="hidden", api_name=False)
679
 
680
- # Same order as `SETTINGS_KEYS`.
681
- settings_fields = [prompt, upsample, canvas, match, duration, steps, seed]
682
- save.click(save_settings, settings_fields, settings_download, api_name=False)
683
- settings_upload.upload(load_settings, settings_upload, settings_fields, api_name=False)
684
- # Same order as `generate`'s signature: the five leading columns first, then the remaining image slots.
685
  request = [
686
  prompt, images[0], audio, video, canvas, *images[1:], match, duration, steps, seed, upsample
687
  ]
 
77
 
78
  MIN_STEPS = 4
79
 
 
 
 
 
 
80
  # Seconds of GPU one request needs, from the packed sequence it is about to denoise: linear in the rows for the
81
  # matmuls, quadratic for the attention, against the AoTI block package this Space runs.
82
  STEP_LINEAR, STEP_QUADRATIC, SAFETY = 1.1745e-4, 3.8396e-9, 1.3
 
523
  )
524
  return path, refined, gr.update(visible=bool(refined))
525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  load_models()
527
 
528
  INTRO = """# MiniMax-H3 Reference
 
587
  steps = gr.Slider(label="Steps", minimum=MIN_STEPS, maximum=40, step=1, value=28)
588
  seed = gr.Number(label="Seed", value=42, precision=0)
589
 
 
 
 
 
 
 
 
 
590
  with gr.Column():
591
  result = gr.Video(label="Video + soundtrack")
592
  # An output, so it can be revealed only for a request that asked for a rewrite.
 
615
  image.change(auto_canvas, image, canvas, show_progress="hidden", api_name=False)
616
  video.change(auto_canvas, video, canvas, show_progress="hidden", api_name=False)
617
 
 
 
 
 
 
618
  request = [
619
  prompt, images[0], audio, video, canvas, *images[1:], match, duration, steps, seed, upsample
620
  ]