temp-9384289 commited on
Commit
1592448
1 Parent(s): 004e980
Files changed (41) hide show
  1. app.py +32 -211
  2. requirements.txt +0 -13
  3. tester/generation/1714450880.962815/generated_image.png +0 -0
  4. tester/generation/1714450880.962815/keeper.png +0 -0
  5. tester/generation/1714450880.962815/real_deal.png +0 -0
  6. tester/generation/1714450908.324796/generated_image.png +0 -0
  7. tester/generation/1714450908.324796/keeper.png +0 -0
  8. tester/generation/1714450908.324796/real_deal.png +0 -0
  9. tester/generation/1714450979.7165031/generated_image.png +0 -0
  10. tester/generation/1714450979.7165031/keeper.png +0 -0
  11. tester/generation/1714450979.7165031/real_deal.png +0 -0
  12. tester/generation/1714451016.7755892/generated_image.png +0 -0
  13. tester/generation/1714451016.7755892/keeper.png +0 -0
  14. tester/generation/1714451016.7755892/real_deal.png +0 -0
  15. tester/generation/1714451444.908609/generated_image.png +0 -0
  16. tester/generation/1714451444.908609/keeper.png +0 -0
  17. tester/generation/1714451444.908609/real_deal.png +0 -0
  18. tester/generation/1714451512.23043/generated_image.png +0 -0
  19. tester/generation/1714451512.23043/keeper.png +0 -0
  20. tester/generation/1714451512.23043/real_deal.png +0 -0
  21. tester/generation/1714451550.030316/generated_image.png +0 -0
  22. tester/generation/1714451550.030316/keeper.png +0 -0
  23. tester/generation/1714451550.030316/real_deal.png +0 -0
  24. tester/generation/1714451807.0931032/generated_image.png +0 -0
  25. tester/generation/1714451807.0931032/keeper.png +0 -0
  26. tester/generation/1714451807.0931032/real_deal.png +0 -0
  27. tester/generation/1714451841.973258/generated_image.png +0 -0
  28. tester/generation/1714451841.973258/keeper.png +0 -0
  29. tester/generation/1714451841.973258/real_deal.png +0 -0
  30. tester/generation/1714451921.654916/generated_image.png +0 -0
  31. tester/generation/1714451921.654916/keeper.png +0 -0
  32. tester/generation/1714451921.654916/real_deal.png +0 -0
  33. tester/generation/1714451971.985685/generated_image.png +0 -0
  34. tester/generation/1714451971.985685/keeper.png +0 -0
  35. tester/generation/1714451971.985685/real_deal.png +0 -0
  36. tester/generation/1714452167.314516/generated_image.png +0 -0
  37. tester/generation/1714452167.314516/keeper.png +0 -0
  38. tester/generation/1714452167.314516/real_deal.png +0 -0
  39. tester/generation/1714452200.348824/generated_image.png +0 -0
  40. tester/generation/1714452200.348824/keeper.png +0 -0
  41. tester/generation/1714452200.348824/real_deal.png +0 -0
app.py CHANGED
@@ -13,6 +13,7 @@ from PIL import Image
13
  from huggingface_hub import from_pretrained_keras
14
  from math import sqrt, ceil
15
  import numpy as np
 
16
 
17
  modelieo=[
18
  'nathanReitinger/MNIST-diffusion',
@@ -77,9 +78,9 @@ def get_sims(gen_filepath, gen_label, file_path, hunting_time_limit):
77
  now = time.time()
78
  if now-start > hunting_time_limit:
79
  print(str(now-start) + "s")
80
- return lowest_image_path
81
 
82
- return lowest_image_path
83
 
84
 
85
  def digit_recognition(filename):
@@ -186,215 +187,35 @@ def TextToImage(Prompt,inference_steps, model):
186
  hunting_time_limit = abs(int(prompt))
187
 
188
  original_image, other_images = get_other(image, hunting_time_limit)
 
 
189
  ai_gen = Image.open(open(original_image, 'rb'))
190
- training_data = Image.open(open(other_images, 'rb'))
191
- return [ai_gen, training_data]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
 
194
- import gradio as gr
195
- interface = gr.Interface(fn=TextToImage,
196
- inputs=[gr.Textbox(show_label=True, label='How many seconds to hunt for copies?',), gr.Slider(1, 1000, label='Inference Steps', value=100, step=1), gr.Dropdown(modelieo)],
197
- outputs=gr.Gallery(label="Generated image", show_label=True, elem_id="gallery", columns=[2], rows=[1], object_fit="contain", height="auto"),
198
- # css="#output_image{width: 256px !important; height: 256px !important;}",
199
- title='Unconditional Image Generation')
200
-
201
- interface.launch()
202
-
203
-
204
-
205
-
206
-
207
- # import tensorflow as tf
208
- # from diffusers import DiffusionPipeline
209
- # import spaces
210
- # # import torch
211
- # import PIL.Image
212
- # from PIL import Image
213
- # from torch.autograd import Variable
214
- # import gradio as gr
215
- # import gradio.components as grc
216
- # import numpy as np
217
- # from huggingface_hub import from_pretrained_keras
218
- # from image_similarity_measures.evaluate import evaluation
219
- # import keras
220
- # import time
221
- # import requests
222
- # import matplotlib.pyplot as plt
223
- # import os
224
- # from pytorch_msssim import ssim, ms_ssim, SSIM, MS_SSIM
225
- # from gradio_imageslider import ImageSlider
226
-
227
- # # os.environ['KMP_DUPLICATE_LIB_OK']='TRUE'
228
-
229
- # # options = ['Placeholder A', 'Placeholder B', 'Placeholder C']
230
-
231
-
232
- # # pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
233
- # # device = "cuda" if torch.cuda.is_available() else "cpu"
234
- # # pipeline = pipeline.to(device=device)
235
-
236
- # # @spaces.GPU
237
- # # def predict(steps, seed):
238
- # # print("HI")
239
- # # generator = torch.manual_seed(seed)
240
- # # for i in range(1,steps):
241
- # # yield pipeline(generator=generator, num_inference_steps=i).images[0]
242
-
243
- # # gr.Interface(
244
- # # predict,
245
- # # inputs=[
246
- # # grc.Slider(0, 1000, label='Inference Steps', value=42, step=1),
247
- # # grc.Slider(0, 2147483647, label='Seed', value=42, step=1),
248
- # # ],
249
- # # outputs=gr.Image(height=28, width=28, type="pil", elem_id="output_image"),
250
- # # css="#output_image{width: 256px !important; height: 256px !important;}",
251
- # # title="Model Problems: Infringing on MNIST!",
252
- # # description="Opening the black box.",
253
- # # ).queue().launch()
254
-
255
-
256
- # from diffusers import StableDiffusionPipeline
257
- # import torch
258
-
259
-
260
- # modellist=['nathanReitinger/MNIST-diffusion-oneImage',
261
- # 'nathanReitinger/MNIST-diffusion',
262
- # # 'nathanReitinger/MNIST-GAN',
263
- # # 'nathanReitinger/MNIST-GAN-noDropout'
264
- # ]
265
-
266
- # # pipeline = DiffusionPipeline.from_pretrained("nathanReitinger/MNIST-diffusion-oneImage")
267
- # # device = "cuda" if torch.cuda.is_available() else "cpu"
268
- # # pipeline = pipeline.to(device=device)
269
-
270
-
271
- # def getModel(model):
272
- # model_id = model
273
-
274
- # (train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()
275
- # RANDO = str(time.time())
276
- # file_path = 'tester/' + model_id.replace("/", "-") + "/" + RANDO + '/'
277
- # os.makedirs(file_path)
278
- # train_images = train_images.reshape(train_images.shape[0], 28, 28, 1).astype('float32')
279
- # train_images = (train_images - 127.5) / 127.5 # Normalize the images to [-1, 1]
280
-
281
- # print(model_id)
282
- # image = None
283
- # if 'diffusion' in model_id:
284
- # pipe = DiffusionPipeline.from_pretrained(model_id)
285
- # pipe = pipe.to("cpu")
286
- # image = pipe(generator= torch.manual_seed(42), num_inference_steps=1).images[0]
287
- # else:
288
- # pipe = DiffusionPipeline.from_pretrained('nathanReitinger/MNIST-diffusion')
289
- # pipe = pipe.to("cpu")
290
- # test = from_pretrained_keras('nathanReitinger/MNIST-GAN')
291
- # image = pipe(generator= torch.manual_seed(42), num_inference_steps=40).images[0]
292
-
293
- # ########################################### let's save this image for comparison to others
294
- # fig = plt.figure(figsize=(1, 1))
295
- # plt.subplot(1, 1, 0+1)
296
- # plt.imshow(image, cmap='gray')
297
- # plt.axis('off')
298
- # plt.savefig(file_path + 'generated_image.png')
299
- # plt.close()
300
-
301
- # API_URL = "https://api-inference.huggingface.co/models/farleyknight/mnist-digit-classification-2022-09-04"
302
-
303
- # # get a prediction on what number this is
304
- # def query(filename):
305
- # with open(filename, "rb") as f:
306
- # data = f.read()
307
- # response = requests.post(API_URL, data=data)
308
- # return response.json()
309
-
310
- # # use latest model to generate a new image, return path
311
- # ret = False
312
- # output = None
313
- # while ret == False:
314
- # output = query(file_path + 'generated_image.png')
315
- # if 'error' in output:
316
- # time.sleep(10)
317
- # ret = False
318
- # else:
319
- # ret = True
320
- # print(output)
321
-
322
- # low_score_log = ''
323
- # this_label_for_this_image = int(output[0]['label'])
324
- # low_score_log += "this image has been identified as a:" + str(this_label_for_this_image) + "\n" + str(output) + "\n"
325
- # print("===================")
326
-
327
- # lowest_score = 10000
328
- # lowest_image = None
329
-
330
- # for i in range(len(train_labels)):
331
- # # print(i)
332
- # if train_labels[i] == this_label_for_this_image:
333
-
334
- # ###
335
- # # get a real image (of correct number)
336
- # ###
337
-
338
- # # print(i)
339
- # to_check = train_images[i]
340
- # fig = plt.figure(figsize=(1, 1))
341
- # plt.subplot(1, 1, 0+1)
342
- # plt.imshow(to_check, cmap='gray')
343
- # plt.axis('off')
344
- # plt.savefig(file_path + 'real_deal.png')
345
- # plt.close()
346
-
347
- # # baseline = evaluation(org_img_path='results/real_deal.png', pred_img_path='results/real_deal.png', metrics=["rmse", "psnr"])
348
- # # print("---")
349
-
350
- # ###
351
- # # check how close that real training data is to generated number
352
- # ###
353
- # results = evaluation(org_img_path=file_path + 'real_deal.png', pred_img_path=file_path+'generated_image.png', metrics=["rmse", "psnr"])
354
- # if results['rmse'] < lowest_score:
355
-
356
- # lowest_score = results['rmse']
357
- # lowest_image = to_check
358
-
359
- # # image1 = np.array(Image.open(file_path + 'real_deal.png'))
360
- # # image2 = np.array(Image.open(file_path + 'generated_image.png'))
361
- # # img1 = torch.from_numpy(image1).float().unsqueeze(0).unsqueeze(0)/255.0
362
- # # img2 = torch.from_numpy(image2).float().unsqueeze(0).unsqueeze(0)/255.0
363
- # # img1 = Variable( img1, requires_grad=False)
364
- # # img2 = Variable( img2, requires_grad=True)
365
- # # ssim_score = ssim(img1, img2).item()
366
-
367
- # # # sys.exit()
368
- # # # l2 = distance.euclidean(image1, image2)
369
-
370
- # # low_score_log += 'rmse score:' + str(lowest_score) + "\n"
371
- # # low_score_log += 'ssim score:' + str(ssim_score) + "\n"
372
- # # low_score_log += 'found when:' + str(round( ((i/len(train_labels)) * 100),2 )) + '%' + "\n"
373
-
374
- # # low_score_log += "---------\n"
375
-
376
- # # print(lowest_score, ssim_score, str(round( ((i/len(train_labels)) * 100),2 )) + '%')
377
-
378
- # # fig = plt.figure(figsize=(1, 1))
379
- # # plt.subplot(1, 1, 0+1)
380
- # # plt.imshow(to_check, cmap='gray')
381
- # # plt.axis('off')
382
- # # plt.savefig(file_path+str(i) + "--" + str(lowest_score) + '---most_close.png')
383
- # # plt.close()
384
-
385
-
386
- # # f = open(file_path + "score_log.txt", "w+")
387
- # # f.write(low_score_log)
388
- # # f.close()
389
-
390
- # print("Done!")
391
-
392
-
393
- # ############################################ return image that you just generated
394
- # return [image, lowest_image]
395
-
396
-
397
- # import gradio as gr
398
- # output = "image"
399
- # interface = gr.Interface(fn=getModel, inputs=[gr.Dropdown(modellist)], css="#output_image{width: 256px !important; height: 256px !important;}", outputs=output, title='Model Problems (infringement)') # outputs="image",
400
- # interface.launch(debug=True)
 
13
  from huggingface_hub import from_pretrained_keras
14
  from math import sqrt, ceil
15
  import numpy as np
16
+ import gradio as gr
17
 
18
  modelieo=[
19
  'nathanReitinger/MNIST-diffusion',
 
78
  now = time.time()
79
  if now-start > hunting_time_limit:
80
  print(str(now-start) + "s")
81
+ return [lowest_image_path, lowest_score]
82
 
83
+ return [lowest_image_path, lowest_score]
84
 
85
 
86
  def digit_recognition(filename):
 
187
  hunting_time_limit = abs(int(prompt))
188
 
189
  original_image, other_images = get_other(image, hunting_time_limit)
190
+ the_file = other_images[0]
191
+ the_rmse = other_images[1]
192
  ai_gen = Image.open(open(original_image, 'rb'))
193
+ training_data = Image.open(open(the_file, 'rb'))
194
+
195
+ another_one = (training_data, "RMSE: " + str(round(the_rmse,5) ))
196
+
197
+ return [ai_gen, another_one]
198
+
199
+
200
+ with gr.Blocks() as app:
201
+
202
+ interface = gr.Interface(fn=TextToImage,
203
+ inputs=[gr.Textbox(show_label=True, label='How many seconds to hunt for copies?',), gr.Slider(1, 1000, label='Inference Steps', value=100, step=1), gr.Dropdown(modelieo)],
204
+ outputs=gr.Gallery(label="Generated image", show_label=True, elem_id="gallery", columns=[2], rows=[1], object_fit="contain", height="auto"),
205
+ # css="#output_image{width: 256px !important; height: 256px !important;}",
206
+ title='Unconditional Image Generation',
207
+ )
208
+ gr.HTML(
209
+ "<hr>"
210
+ "<h1><center>Do machine learing models store protected content?</center></h1>" +
211
+ "<p><center><span style='color: red;'>Enter a time to hunt for copies (seconds), select a model, and hit submit!</center></p>" +
212
+ "<p><center><strong>These image generation models will give you a 'bespoke' generation ❤ of an MNIST hand-drawn digit</p>" +
213
+ "<p><center>then the program will search in training data (for <i>n</i> seconds) to find similar images: <a href='https://medium.com/@mygreatlearning/rmse-what-does-it-mean-2d446c0b1d0e'>RMSE<a>, lower is more similar</p>" +
214
+ "<p><a href='https://nathanreitinger.umiacs.io'>@nathanReitinger<a></p>"
215
+ )
216
+
217
+ app.queue().launch()
218
+ # interface.launch(share=True)
219
+
220
 
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -2,24 +2,11 @@
2
 
3
  diffusers==0.27.2
4
  gradio==4.28.3
5
- <<<<<<< HEAD
6
  huggingface-hub==0.22.2
7
  image-similarity-measures==0.3.6
8
  matplotlib==3.8.4
9
  numpy==1.25.2
10
  pillow==10.3.0
11
  requests==2.31.0
12
- =======
13
- gradio_imageslider==0.0.20
14
- huggingface-hub==0.22.2
15
- image-similarity-measures==0.3.6
16
- keras==2.11.0
17
- matplotlib==3.8.4
18
- numpy==1.25.2
19
- pillow==10.3.0
20
- pytorch-msssim==1.0.0
21
- requests==2.31.0
22
- spaces==0.26.2
23
- >>>>>>> 0fceaca51b594336a55134745a393f595fe283f7
24
  tensorflow==2.11.0
25
  torch==2.2.2
 
2
 
3
  diffusers==0.27.2
4
  gradio==4.28.3
 
5
  huggingface-hub==0.22.2
6
  image-similarity-measures==0.3.6
7
  matplotlib==3.8.4
8
  numpy==1.25.2
9
  pillow==10.3.0
10
  requests==2.31.0
 
 
 
 
 
 
 
 
 
 
 
 
11
  tensorflow==2.11.0
12
  torch==2.2.2
tester/generation/1714450880.962815/generated_image.png ADDED
tester/generation/1714450880.962815/keeper.png ADDED
tester/generation/1714450880.962815/real_deal.png ADDED
tester/generation/1714450908.324796/generated_image.png ADDED
tester/generation/1714450908.324796/keeper.png ADDED
tester/generation/1714450908.324796/real_deal.png ADDED
tester/generation/1714450979.7165031/generated_image.png ADDED
tester/generation/1714450979.7165031/keeper.png ADDED
tester/generation/1714450979.7165031/real_deal.png ADDED
tester/generation/1714451016.7755892/generated_image.png ADDED
tester/generation/1714451016.7755892/keeper.png ADDED
tester/generation/1714451016.7755892/real_deal.png ADDED
tester/generation/1714451444.908609/generated_image.png ADDED
tester/generation/1714451444.908609/keeper.png ADDED
tester/generation/1714451444.908609/real_deal.png ADDED
tester/generation/1714451512.23043/generated_image.png ADDED
tester/generation/1714451512.23043/keeper.png ADDED
tester/generation/1714451512.23043/real_deal.png ADDED
tester/generation/1714451550.030316/generated_image.png ADDED
tester/generation/1714451550.030316/keeper.png ADDED
tester/generation/1714451550.030316/real_deal.png ADDED
tester/generation/1714451807.0931032/generated_image.png ADDED
tester/generation/1714451807.0931032/keeper.png ADDED
tester/generation/1714451807.0931032/real_deal.png ADDED
tester/generation/1714451841.973258/generated_image.png ADDED
tester/generation/1714451841.973258/keeper.png ADDED
tester/generation/1714451841.973258/real_deal.png ADDED
tester/generation/1714451921.654916/generated_image.png ADDED
tester/generation/1714451921.654916/keeper.png ADDED
tester/generation/1714451921.654916/real_deal.png ADDED
tester/generation/1714451971.985685/generated_image.png ADDED
tester/generation/1714451971.985685/keeper.png ADDED
tester/generation/1714451971.985685/real_deal.png ADDED
tester/generation/1714452167.314516/generated_image.png ADDED
tester/generation/1714452167.314516/keeper.png ADDED
tester/generation/1714452167.314516/real_deal.png ADDED
tester/generation/1714452200.348824/generated_image.png ADDED
tester/generation/1714452200.348824/keeper.png ADDED
tester/generation/1714452200.348824/real_deal.png ADDED