uripper commited on
Commit
8d2a10d
1 Parent(s): 4dcb901

added sample images

Browse files
Files changed (1) hide show
  1. app.py +36 -10
app.py CHANGED
@@ -1,17 +1,43 @@
1
  import gradio as gr
2
- from diffusers import DiffusionPipeline
3
  import torch
 
 
 
4
 
5
- pipeline = DiffusionPipeline.from_pretrained("uripper/GIANNIS", revision="ONNX")
6
- pipeline.to("cuda")
7
- im = pipeline(height=1,width=1,num_channels=1, num_inference_steps=1).images[0]
8
- im.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # When a user clicks button, pipeline will generate an image
10
 
11
- # def pipeline_interface():
12
- # pipeline.to("cuda")
13
- # return pipeline("height=100,width=100").images[0]
14
 
15
- # iface = gr.Interface(fn=pipeline_interface, inputs=[], outputs="image")
16
 
17
- # iface.launch()
 
1
  import gradio as gr
2
+ from diffusers import DDPMPipeline, DDPMScheduler
3
  import torch
4
+ import random
5
+ import PIL
6
+ import os
7
 
8
+ scheduler = DDPMScheduler(num_train_timesteps=200,beta_schedule="linear")
9
+ pipeline = DDPMPipeline.from_pretrained("uripper/GIANNIS", revision="ONNX", scheduler=scheduler)
10
+ num_imgs = len(os.listdir("GIANNIS\stored_images"))
11
+ imgs = os.listdir("GIANNIS\stored_images")
12
+
13
+
14
+ def generate_img():
15
+ random_words = ["blue", "bear", "math", "pi", "apple", "cheese", "monkey", "yellow", "grape", "banana", "orange", "dog", "cat", "fish", "bird", "mouse", "horse", "cow", "sheep", "pig", "chicken", "duck", "frog", "snake", "turtle", "elephant", "lion", "tiger", "giraffe", "zebra", "monkey", "ant", "bee", "butterfly", "camel", "crocodile", "dolphin", "duck", "eagle", "fish", "flamingo", "fox", "frog", "giraffe", "goat", "goldfish", "hamster", "hippopotamus", "horse", "kangaroo", "kitten", "lion", "lobster", "monkey", "octopus", "owl", "panda", "parrot", "penguin", "pig", "puppy", "rabbit", "raccoon", "rhinoceros", "scorpion", "seal", "shark", "snail", "snake", "spider", "squirrel", "swan", "tiger", "whale", "wolf", "zebra"]
16
+ ran_word_1 = random.choice(random_words)
17
+ ran_word_2 = random.choice(random_words)
18
+ ran_word_3 = random.choice(random_words)
19
+ ran_num = str(random.randint(1, 100))
20
+ ran_num2 = str(random.randint(1, 100))
21
+ filename = ran_word_1 + "_" + ran_num + "_" + ran_word_2 + "_" + ran_num2 + "_" + ran_word_3
22
+
23
+
24
+ pipeline.to("cuda")
25
+ images= pipeline().images
26
+ im = images[0]
27
+ im.save(f"GIANNIS\stored_images\{filename}.png")
28
+ return im
29
+
30
+ def show_random_image(num_imgs = num_imgs, imgs = imgs):
31
+ ran_img = random.randint(1, num_imgs)-1
32
+ display_img = "GIANNIS\\stored_images\\"+imgs[ran_img]
33
+ return PIL.Image.open(display_img)
34
+
35
+ for i in range(100):
36
+ generate_img()
37
  # When a user clicks button, pipeline will generate an image
38
 
39
+ iface = gr.Interface(fn=show_random_image, inputs=[], outputs="image")
 
 
40
 
41
+ # iface = gr.Interface(fn=generate_img, inputs=[], outputs="image")
42
 
43
+ iface.launch()