Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import PIL.Image
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from .pipeline import DDIMPipelineCustom
|
| 7 |
+
|
| 8 |
+
pipeline = DDIMPipelineCustom.from_pretrained("1aurent/ddpm-mnist-conditional")
|
| 9 |
+
|
| 10 |
+
def predict(steps, seed, value, guidance):
|
| 11 |
+
generator = torch.manual_seed(seed)
|
| 12 |
+
for i in range(1,steps):
|
| 13 |
+
yield pipeline(
|
| 14 |
+
generator=generator,
|
| 15 |
+
condition=torch.tensor([value]),
|
| 16 |
+
guidance=guidance,
|
| 17 |
+
num_inference_steps=steps
|
| 18 |
+
).images[0]
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
predict,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.components.Slider(1, 100, label='Inference Steps', value=20, step=1),
|
| 24 |
+
gr.components.Slider(0, 2147483647, label='Seed', value=69420, step=1),
|
| 25 |
+
gr.components.Slider(0, 9, label='Value', value=5, step=1),
|
| 26 |
+
gr.components.Slider(-2.5, 2.5, label='Guidance Factor', value=1),
|
| 27 |
+
],
|
| 28 |
+
outputs=gr.Image(shape=[28,28], type="pil", elem_id="output_image"),
|
| 29 |
+
css="#output_image img {width: 256px}",
|
| 30 |
+
title="Conditional MNIST",
|
| 31 |
+
description="A DDIM scheduler and UNet model trained on the MNIST dataset for conditional image generation.",
|
| 32 |
+
).queue().launch()
|