Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files76 unmodified lines7778798081828384808182440 unmodified lines52352452553153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857952652752858 unmodified lines58758858964464564664764864965065159059159222 unmodified lines61561661768068168268368461861962076 unmodified lines
MIN_STEPS = 4
SETTINGS_HELP = """Saves the prompt, the canvas and the sliders — everything typed rather than uploaded. Images,audio and video are not saved: gradio keeps them in a temporary folder that is gone by the next visit, so a savedpath would come back as a dead file."""
# Seconds of GPU one request needs, from the packed sequence it is about to denoise: linear in the rows for the# matmuls, quadratic for the attention, against the AoTI block package this Space runs.STEP_LINEAR, STEP_QUADRATIC, SAFETY = 1.1745e-4, 3.8396e-9, 1.3440 unmodified lines ) return path, refined, gr.update(visible=bool(refined))
# ----------------------------------------------------------------------------------------------------------------# Settings file# ----------------------------------------------------------------------------------------------------------------# Everything typed rather than uploaded, so a session can be picked up where it was left off. The references# themselves are deliberately left out: gradio hands them over as paths into a per-session temporary directory that# is gone by the next visit, so a saved path would restore as a dead file rather than as the image.
SETTINGS_VERSION = 1SETTINGS_KEYS = ["prompt", "upsample", "canvas", "match", "duration", "steps", "seed"]
def save_settings(*values): """Write the current controls to a `.json` and reveal it for download.""" payload = {"version": SETTINGS_VERSION, "saved": time.strftime("%Y-%m-%d %H:%M:%S")} payload.update(dict(zip(SETTINGS_KEYS, values)))
directory = os.path.join(tempfile.gettempdir(), "h3-settings") os.makedirs(directory, exist_ok=True) path = os.path.join(directory, f"h3-settings-{int(time.time())}.json") with open(path, "w", encoding="utf-8") as handle: json.dump(payload, handle, ensure_ascii=False, indent=2, default=str) return gr.update(value=path, visible=True)
def load_settings(path): """Restore the controls from a `.json`. A key the file does not carry leaves its control alone, so a settings file written by an older version of this Space still loads.""" if not path: return [gr.update() for _ in SETTINGS_KEYS] try: with open(path, encoding="utf-8") as handle: payload = json.load(handle) except Exception as error: raise gr.Error(f"Файлът с настройки не се чете: `{type(error).__name__}: {error}`") if not isinstance(payload, dict): raise gr.Error("Това не е файл с настройки на този Space.")
updates = [] for key in SETTINGS_KEYS: value = payload.get(key) # An unknown canvas label would be rejected by the conditioner, which is the wrong place to find out. if value is None or (key == "canvas" and value not in CANVASES): updates.append(gr.update()) else: updates.append(gr.update(value=value)) return updates
load_models()
INTRO = """# MiniMax-H3 Reference58 unmodified lines steps = gr.Slider(label="Steps", minimum=MIN_STEPS, maximum=40, step=1, value=28) seed = gr.Number(label="Seed", value=42, precision=0)
with gr.Accordion("Settings file", open=False): gr.Markdown(SETTINGS_HELP) save = gr.Button("Save settings to .json", size="sm") settings_download = gr.File(label="Your settings", visible=False, interactive=False) settings_upload = gr.File( label="Load a settings .json", file_types=[".json"], type="filepath" )
with gr.Column(): result = gr.Video(label="Video + soundtrack") # An output, so it can be revealed only for a request that asked for a rewrite.22 unmodified lines image.change(auto_canvas, image, canvas, show_progress="hidden", api_name=False) video.change(auto_canvas, video, canvas, show_progress="hidden", api_name=False)
# Same order as `SETTINGS_KEYS`. settings_fields = [prompt, upsample, canvas, match, duration, steps, seed] save.click(save_settings, settings_fields, settings_download, api_name=False) settings_upload.upload(load_settings, settings_upload, settings_fields, api_name=False) # Same order as `generate`'s signature: the five leading columns first, then the remaining image slots. request = [ prompt, images[0], audio, video, canvas, *images[1:], match, duration, steps, seed, upsample ]app.py-67