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() |