-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradio_app.py
47 lines (42 loc) · 1.17 KB
/
gradio_app.py
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
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)