File size: 1,405 Bytes
611bd3a
 
 
 
 
 
 
8fb9752
611bd3a
5138bba
 
 
 
 
 
 
 
 
 
 
 
 
477dde5
 
 
611bd3a
 
 
 
 
 
 
 
 
 
84d89e5
8fb9752
611bd3a
 
 
4f73449
 
611bd3a
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
from diffusers import DiffusionPipeline
import spaces
import torch
import PIL.Image
import gradio as gr
import gradio.components as grc
import numpy as np
# import time


# models=[
#     "runwayml/stable-diffusion-v1-5",   
#     "claudfuen/photorealistic-fuen-v1",
#     "nitrosocke/redshift-diffusion",    
# ]
# model_box=[
#     gr.Interface.load(f"models/{models[0]}",live=True,preprocess=True),
#     gr.Interface.load(f"models/{models[1]}",live=True,preprocess=True),
#     gr.Interface.load(f"models/{models[2]}",live=True,preprocess=True),
# ]
# current_model=model_box[0]

pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
device = "cuda" if torch.cuda.is_available() else "cpu"
pipeline = pipeline.to(device=device)

@spaces.GPU
def predict(steps, seed):
    generator = torch.manual_seed(seed)
    for i in range(1,steps):
        yield pipeline(generator=generator, num_inference_steps=i).images[0]

gr.Interface(
    predict,
    inputs=[
        grc.Slider(0, 1000, label='Inference Steps', value=42, step=1),
        grc.Slider(0, 2147483647, label='Seed', value=42, step=1),
    ],
    outputs=gr.Image(height=28, width=28, type="pil", elem_id="output_image"),
    css="#output_image{width: 256px !important; height: 256px !important;}",
    title="Model Problems: Infringing on MNIST!",
    description="Opening the black box.",
).queue().launch()