File size: 1,263 Bytes
4f5b0d4
e591979
587753b
50d229b
 
587753b
50d229b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
os.system("pip install gradio diffusers torch transformers")
import gradio as gr
from diffusers import StableDiffusionXLPipeline
import torch

pipe = StableDiffusionXLPipeline.from_pretrained(
    "segmind/SSD-1B", 
    torch_dtype=torch.float16, 
    use_safetensors=True, 
    variant="fp16"
)
pipe.to("cuda")

def generate_image(prompt, neg_prompt):
    image = pipe(
        prompt=prompt, 
        negative_prompt=neg_prompt
    ).images[0]
    return image

prompt = gr.Text(
                label="Prompt",
                show_label=False,
                max_lines=1,
                placeholder="Enter your prompt",
                container=False,
            )
neg_prompt = gr.Text(
                label="Negative Prompt",
                show_label=False,
                max_lines=1,
                placeholder="Enter your negative prompt",
                container=False,
            )

iface = gr.Interface(
    fn=generate_image,
    inputs=[prompt, neg_prompt],
    outputs="image",
    title="Text to Image Generation",
    examples=[
        ["a painting of a cute cat sitting on a chair", "ugly, blurry"],
        ["an astronaut riding a horse on mars", "poorly drawn"]
    ],
    allow_flagging=False
)

iface.launch(share=True)