Spaces:
Runtime error
Runtime error
File size: 2,526 Bytes
83578c9 611bd3a 9dd07e2 611bd3a 9dd07e2 83578c9 9dd07e2 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# notes https://huggingface.co/spaces/Joeythemonster/Text-To-image-AllModels/blob/main/app.py
from diffusers import DiffusionPipeline
import spaces
# import torch
import PIL.Image
import gradio as gr
import gradio.components as grc
import numpy as np
from huggingface_hub import from_pretrained_keras
import keras
import time
import os
os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
# options = ['Placeholder A', 'Placeholder B', 'Placeholder C']
# 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):
# print("HI")
# 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()
from diffusers import StableDiffusionPipeline
import torch
modellist=['nathanReitinger/MNIST-diffusion-oneImage',
'nathanReitinger/MNIST-diffusion',
# 'nathanReitinger/MNIST-GAN',
# 'nathanReitinger/MNIST-GAN-noDropout'
]
# pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
# device = "cuda" if torch.cuda.is_available() else "cpu"
# pipeline = pipeline.to(device=device)
def getModel(model):
model_id = model
print(model_id)
if 'diffusion' in model_id:
pipe = DiffusionPipeline.from_pretrained(model_id)
pipe = pipe.to("cpu")
image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
else:
pipe = DiffusionPipeline.from_pretrained('nathanReitinger/MNIST-diffusion')
pipe = pipe.to("cpu")
test = from_pretrained_keras('nathanReitinger/MNIST-GAN')
image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
return image
import gradio as gr
interface = gr.Interface(fn=getModel,
inputs=[gr.Dropdown(modellist)],
outputs="image",
title='Model Problems (infringement)')
interface.launch()
|