Spaces:
Running
Running
| 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() |