Spaces:
Runtime error
Runtime error
temp-9384289
commited on
Commit
·
ffe27dd
1
Parent(s):
083e9ab
fancy
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# notes https://huggingface.co/spaces/Joeythemonster/Text-To-image-AllModels/blob/main/app.py
|
| 2 |
|
| 3 |
-
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
import spaces
|
| 6 |
# import torch
|
|
@@ -13,7 +13,7 @@ import keras
|
|
| 13 |
import time
|
| 14 |
import os
|
| 15 |
|
| 16 |
-
os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
|
| 17 |
|
| 18 |
# options = ['Placeholder A', 'Placeholder B', 'Placeholder C']
|
| 19 |
|
|
@@ -24,31 +24,32 @@ os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
|
|
| 24 |
|
| 25 |
# @spaces.GPU
|
| 26 |
# def predict(steps, seed):
|
| 27 |
-
#
|
| 28 |
-
#
|
| 29 |
-
#
|
| 30 |
-
#
|
| 31 |
|
| 32 |
# gr.Interface(
|
| 33 |
-
#
|
| 34 |
-
#
|
| 35 |
-
#
|
| 36 |
-
#
|
| 37 |
-
#
|
| 38 |
-
#
|
| 39 |
-
#
|
| 40 |
-
#
|
| 41 |
-
#
|
| 42 |
# ).queue().launch()
|
| 43 |
|
| 44 |
|
| 45 |
from diffusers import StableDiffusionPipeline
|
| 46 |
import torch
|
| 47 |
|
|
|
|
| 48 |
modellist=['nathanReitinger/MNIST-diffusion-oneImage',
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
#
|
| 52 |
]
|
| 53 |
|
| 54 |
# pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
|
|
@@ -57,27 +58,29 @@ modellist=['nathanReitinger/MNIST-diffusion-oneImage',
|
|
| 57 |
|
| 58 |
|
| 59 |
def getModel(model):
|
| 60 |
-
|
| 61 |
-
print(model_id)
|
| 62 |
-
if 'diffusion' in model_id:
|
| 63 |
-
pipe = DiffusionPipeline.from_pretrained(model_id)
|
| 64 |
-
pipe = pipe.to("cpu")
|
| 65 |
-
image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
|
| 77 |
import gradio as gr
|
| 78 |
-
interface = gr.Interface(fn=getModel,
|
| 79 |
-
inputs=[gr.Dropdown(modellist)],
|
| 80 |
-
outputs="image",
|
| 81 |
-
title='Model Problems (infringement)')
|
| 82 |
-
|
| 83 |
interface.launch()
|
|
|
|
| 1 |
# notes https://huggingface.co/spaces/Joeythemonster/Text-To-image-AllModels/blob/main/app.py
|
| 2 |
|
| 3 |
+
import tensorflow as tf
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
import spaces
|
| 6 |
# import torch
|
|
|
|
| 13 |
import time
|
| 14 |
import os
|
| 15 |
|
| 16 |
+
# os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
|
| 17 |
|
| 18 |
# options = ['Placeholder A', 'Placeholder B', 'Placeholder C']
|
| 19 |
|
|
|
|
| 24 |
|
| 25 |
# @spaces.GPU
|
| 26 |
# def predict(steps, seed):
|
| 27 |
+
# print("HI")
|
| 28 |
+
# generator = torch.manual_seed(seed)
|
| 29 |
+
# for i in range(1,steps):
|
| 30 |
+
# yield pipeline(generator=generator, num_inference_steps=i).images[0]
|
| 31 |
|
| 32 |
# gr.Interface(
|
| 33 |
+
# predict,
|
| 34 |
+
# inputs=[
|
| 35 |
+
# grc.Slider(0, 1000, label='Inference Steps', value=42, step=1),
|
| 36 |
+
# grc.Slider(0, 2147483647, label='Seed', value=42, step=1),
|
| 37 |
+
# ],
|
| 38 |
+
# outputs=gr.Image(height=28, width=28, type="pil", elem_id="output_image"),
|
| 39 |
+
# css="#output_image{width: 256px !important; height: 256px !important;}",
|
| 40 |
+
# title="Model Problems: Infringing on MNIST!",
|
| 41 |
+
# description="Opening the black box.",
|
| 42 |
# ).queue().launch()
|
| 43 |
|
| 44 |
|
| 45 |
from diffusers import StableDiffusionPipeline
|
| 46 |
import torch
|
| 47 |
|
| 48 |
+
|
| 49 |
modellist=['nathanReitinger/MNIST-diffusion-oneImage',
|
| 50 |
+
'nathanReitinger/MNIST-diffusion',
|
| 51 |
+
# 'nathanReitinger/MNIST-GAN',
|
| 52 |
+
# 'nathanReitinger/MNIST-GAN-noDropout'
|
| 53 |
]
|
| 54 |
|
| 55 |
# pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def getModel(model):
|
| 61 |
+
model_id = model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
(train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()
|
| 64 |
+
RANDO = str(time.time())
|
| 65 |
+
file_path = 'tester/' + model_id.replace("/", "-") + "/" + RANDO + '/'
|
| 66 |
+
os.makedirs(file_path)
|
| 67 |
+
train_images = train_images.reshape(train_images.shape[0], 28, 28, 1).astype('float32')
|
| 68 |
+
train_images = (train_images - 127.5) / 127.5 # Normalize the images to [-1, 1]
|
| 69 |
|
| 70 |
+
print(model_id)
|
| 71 |
+
if 'diffusion' in model_id:
|
| 72 |
+
pipe = DiffusionPipeline.from_pretrained(model_id)
|
| 73 |
+
pipe = pipe.to("cpu")
|
| 74 |
+
image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
|
| 75 |
+
else:
|
| 76 |
+
pipe = DiffusionPipeline.from_pretrained('nathanReitinger/MNIST-diffusion')
|
| 77 |
+
pipe = pipe.to("cpu")
|
| 78 |
+
test = from_pretrained_keras('nathanReitinger/MNIST-GAN')
|
| 79 |
+
image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
|
| 80 |
|
| 81 |
+
return image
|
| 82 |
|
| 83 |
|
| 84 |
import gradio as gr
|
| 85 |
+
interface = gr.Interface(fn=getModel, inputs=[gr.Dropdown(modellist)], css="#output_image{width: 256px !important; height: 256px !important;}", outputs="image", title='Model Problems (infringement)')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
interface.launch()
|