File size: 2,060 Bytes
4dcb901
8d2a10d
4dcb901
8d2a10d
 
 
4dcb901
8d2a10d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4dcb901
 
8d2a10d
4dcb901
8d2a10d
4dcb901
8d2a10d
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
import gradio as gr
from diffusers import DDPMPipeline, DDPMScheduler
import torch
import random
import PIL
import os

scheduler = DDPMScheduler(num_train_timesteps=200,beta_schedule="linear")
pipeline = DDPMPipeline.from_pretrained("uripper/GIANNIS", revision="ONNX", scheduler=scheduler)
num_imgs = len(os.listdir("GIANNIS\stored_images"))
imgs = os.listdir("GIANNIS\stored_images")


def generate_img():
    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"]
    ran_word_1 = random.choice(random_words)
    ran_word_2 = random.choice(random_words)
    ran_word_3 = random.choice(random_words)
    ran_num = str(random.randint(1, 100))
    ran_num2 = str(random.randint(1, 100))
    filename = ran_word_1 + "_" + ran_num + "_" + ran_word_2 + "_" + ran_num2 + "_" + ran_word_3


    pipeline.to("cuda")
    images= pipeline().images
    im = images[0]
    im.save(f"GIANNIS\stored_images\{filename}.png")
    return im

def show_random_image(num_imgs = num_imgs, imgs = imgs):
    ran_img = random.randint(1, num_imgs)-1
    display_img = "GIANNIS\\stored_images\\"+imgs[ran_img] 
    return PIL.Image.open(display_img)

for i in range(100):
    generate_img()
# When a user clicks button, pipeline will generate an image

iface = gr.Interface(fn=show_random_image, inputs=[], outputs="image")

# iface = gr.Interface(fn=generate_img, inputs=[], outputs="image")

iface.launch()