import tempfile | |
from pathlib import Path | |
from PIL import Image | |
import gradio as gr | |
def fake(): | |
image = Image.new("RGB", (512, 512)) | |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmpfile: | |
image.save(tmpfile, "JPEG", quality=80, optimize=True, progressive=True) | |
return Path(tmpfile.name) | |
with gr.Blocks() as demo: | |
t = gr.Textbox() | |
i = gr.Image(type="filepath") | |
t.submit(fake, None, i) | |
demo.launch() |