File size: 2,615 Bytes
2eb58d1
 
199e379
2eb58d1
 
046a2a3
2eb58d1
11ca63e
2eb58d1
 
a17b7c9
2eb58d1
 
199e379
2eb58d1
4e01792
 
 
 
2eb58d1
 
 
c21f330
2eb58d1
4e01792
c21f330
 
2eb58d1
 
 
 
 
 
c21f330
 
 
2eb58d1
 
 
 
 
 
c21f330
 
2eb58d1
 
 
c21f330
 
2eb58d1
4e01792
2eb58d1
 
 
16489cb
c21f330
2eb58d1
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from turtle import width
import gradio as gr
import random
import inspect
latent = gr.Interface.load("spaces/multimodalart/latentdiffusion")
print(latent)
rudalle = gr.Interface.load("spaces/multimodalart/rudalle")
print(rudalle)
guided = gr.Interface.load("spaces/EleutherAI/clip-guided-diffusion")
print(guided)
def text2image_latent(text,steps,width,height,images,diversity):
    image = latent(text, steps, width, height, images, diversity)[0]
    return(image)
  
def text2image_rudalle(text,aspect,model):
    print(text)
    print(aspect)
    print(model)
    image = rudalle(text,aspect,model)[0]
    print(image)
    return(image)


def text2image_guided(text):
    image = guided(text, None, 10, 600, 0, 0, 0, random.randint(0,2147483647), None, 50, 32)
    print(image)
    image = image[0]
    return(image)

block = gr.Blocks()

with block:
    text = gr.inputs.Textbox(placeholder="Try writing something..")
    which_tab = "Latent Diffusion"
    with gr.Tab("latent"):
        which_tab = "Latent Diffusion"
        steps = gr.inputs.Slider(label="Steps - more steps can increase quality but will take longer to generate",default=45,maximum=50,minimum=1,step=1)
        width = gr.inputs.Radio(label="Width", choices=[32,64,128,256],default=256)
        height = gr.inputs.Radio(label="Height", choices=[32,64,128,256],default=256)
        images = gr.inputs.Slider(label="Images - How many images you wish to generate", default=2, step=1, minimum=1, maximum=4)
        diversity = gr.inputs.Slider(label="Diversity scale - How different from one another you wish the images to be",default=5.0, minimum=1.0, maximum=15.0)
        get_image_latent = gr.Button("Generate Image")
    with gr.Tab("rudalle"):
        which_tab = "ruDALLE"
        aspect = gr.inputs.Radio(label="Aspect Ratio", choices=["Square", "Horizontal", "Vertical"],default="Square")
        model = gr.inputs.Dropdown(label="Model", choices=["Surrealism","Realism", "Emoji"], default="Surrealism")
        get_image_rudalle = gr.Button("Generate Image")
    with gr.Tab("guided"):
        which_tab = "Guided Diffusion"
        get_image_guided = gr.Button("Generate Image")
    #get_image = gr.Button("Generate Image")
    with gr.Column():        
        with gr.Row():
            image = gr.outputs.Image()
    
    print(which_tab)
    get_image_latent.click(text2image_latent, inputs=[text,steps,width,height,images,diversity], outputs=image)
    get_image_rudalle.click(text2image_rudalle, inputs=[text,aspect,model], outputs=image)
    get_image_guided.click(text2image_guided, inputs=text, outputs=image)
block.launch()