File size: 2,030 Bytes
4dcb901
a8f4037
8d2a10d
1894a81
4dcb901
a8f4037
 
f8e8a2d
 
8d2a10d
 
 
 
 
 
 
 
 
 
 
 
195f198
 
 
 
8d2a10d
 
f8e8a2d
8d2a10d
 
f8e8a2d
 
 
 
8d2a10d
88a9b91
 
4dcb901
 
195f198
4dcb901
195f198
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
44
import gradio as gr
from diffusers import PNDMPipeline, IPNDMScheduler
import random


scheduler = IPNDMScheduler(num_train_timesteps=50)
pipeline = PNDMPipeline.from_pretrained("uripper/GIANNIS", scheduler=scheduler)
# num_imgs = len(os.listdir("\stored_images"))
# imgs = os.listdir("\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


    try:
        pipeline.to("cuda")
    except:
        pass
    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()