File size: 1,848 Bytes
2df9553
 
99671bd
 
 
 
 
 
 
 
 
2df9553
 
 
 
 
 
99671bd
2df9553
 
99671bd
 
 
 
2df9553
99671bd
2df9553
 
 
 
99671bd
2df9553
 
99671bd
 
2df9553
99671bd
2df9553
99671bd
2df9553
 
 
869b788
99671bd
2df9553
 
 
 
 
99671bd
2df9553
 
 
 
 
 
 
 
99671bd
 
 
 
 
 
2df9553
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
62
63
64
65
66
import gradio as gr

def generateImage(prompt, n_prompt, modelName):

    return models[modelName].process(prompt, n_prompt)




def create_demo():

    with gr.Blocks() as demo:
        with gr.Column():
            prompt = gr.Textbox(label='Prompt')
            n_prompt = gr.Textbox(
                label='Negative Prompt',
                value=
                'ugly, disfigured, deformed'
            )

            modelName = gr.Dropdown(choices = list(models.keys()), 
                                        label = "Model", 
                                        value=list(models.keys())[0])

            run_button = gr.Button('Run')
        gr.Markdown("### [Stable Diffusion Art](https://stable-diffusion-art.com/) -- tutorials and resources. Read [Model license](https://huggingface.co/spaces/CompVis/stable-diffusion-license).")
        result = gr.Gallery(label='Output',
                            show_label=False,
                            elem_id='gallery').style(columns=1, rows=1, preview=True)        


        inputs = [
            prompt,
            n_prompt,
            modelName,
        ]

        prompt.submit(
            fn=generateImage,
            inputs=inputs,
            outputs=result
        )
        n_prompt.submit(
            fn=generateImage,
            inputs=inputs,
            outputs=result
        )

        run_button.click(
            fn=generateImage,
            inputs=inputs,
            outputs=result
        )
    return demo


if __name__ == '__main__':
    from model import Model
    models = {
        "Stable Diffusion v1.5": Model("runwayml/stable-diffusion-v1-5"),
        "Realistic Vision v2.0": Model("SG161222/Realistic_Vision_V2.0"),
        "Anything v3.0": Model("Linaqruf/anything-v3.0")
              }
    demo = create_demo()
    demo.queue().launch()