Spaces:
Sleeping
Sleeping
File size: 1,367 Bytes
2b51af4 |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import gradio as gr
import numpy as np
import time
import os
from PIL import Image
import requests
from io import BytesIO
def create_gif(images):
pil_images = []
for image in images:
if isinstance(image, str):
response = requests.get(image)
image = Image.open(BytesIO(response.content))
else:
image = Image.fromarray((image * 255).astype(np.uint8))
pil_images.append(image)
fp_out = os.path.join(os.path.dirname(__file__), "image.gif")
img = pil_images.pop(0)
img.save(fp=fp_out, format='GIF', append_images=pil_images,
save_all=True, duration=400, loop=0)
return fp_out
def fake_diffusion(steps):
rng = np.random.default_rng()
images = []
for _ in range(steps):
time.sleep(1)
image = rng.random((600, 600, 3))
images.append(image)
yield image, gr.Image(visible=False)
time.sleep(1)
image = "https://gradio-builds.s3.amazonaws.com/diffusion_image/cute_dog.jpg"
images.append(image)
gif_path = create_gif(images)
yield image, gr.Image(value=gif_path, visible=True)
demo = gr.Interface(fake_diffusion,
inputs=gr.Slider(1, 10, 3, step=1),
outputs=["image", gr.Image(label="All Images", visible=False)])
demo.queue()
if __name__ == "__main__":
demo.launch()
|