Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import DDPMPipeline
|
| 2 |
+
import torch
|
| 3 |
+
import PIL.Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import random
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
pipeline = DDPMPipeline.from_pretrained("stevhliu/ddpm-butterflies-128")
|
| 9 |
+
|
| 10 |
+
def predict(steps, seed):
|
| 11 |
+
generator = torch.manual_seed(seed)
|
| 12 |
+
for i in range(1,steps):
|
| 13 |
+
yield pipeline(generator=generator, num_inference_steps=i)["sample"][0]
|
| 14 |
+
|
| 15 |
+
random_seed = random.randint(0, 2147483647)
|
| 16 |
+
gr.Interface(
|
| 17 |
+
predict,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.inputs.Slider(1, 100, label='Inference Steps', default=5, step=1),
|
| 20 |
+
gr.inputs.Slider(0, 2147483647, label='Seed', default=random_seed, step=1),
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Image(shape=[256,256], type="pil", elem_id="output_image"),
|
| 23 |
+
css="#output_image{width: 256px}",
|
| 24 |
+
title="Unconditional butterflies",
|
| 25 |
+
description="A DDPM scheduler and UNet model trained on a subset of the <a href=\"https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset\">Smithsonian Butterflies</a> dataset for unconditional image generation.
|
| 26 |
+
).queue().launch()
|