File size: 953 Bytes
2acfccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import annotations

import os
import tempfile

import gradio as gr
from gradio.data_classes import FileData

# Placeholder "video" so the runtime MIME-upgrade path has something to render.
# The bytes don't need to be a valid mp4 — the workflow decides "this is video"
# from mime_type. If you want a real playable video, replace this with a real .mp4.
SAMPLE_PATH = os.path.join(tempfile.gettempdir(), "gr_api_any_repro.mp4")
if not os.path.exists(SAMPLE_PATH):
    with open(SAMPLE_PATH, "wb") as f:
        f.write(b"\x00" * 1024)


def generate(
    prompt: str,
    seed: float = 42,
    steps: int = 6,
) -> tuple[FileData, str, str]:
    return (
        FileData(path=SAMPLE_PATH, mime_type="video/mp4"),
        f"Report: prompt={prompt!r} seed={int(seed)} steps={steps}",
        f"{prompt} (refined)",
    )


with gr.Blocks() as demo:
    gr.api(generate, api_name="generate")


if __name__ == "__main__":
    demo.launch()