Spaces:
Runtime error
Runtime error
File size: 2,139 Bytes
937f590 36fb421 93dd707 937f590 93dd707 937f590 93dd707 937f590 7713986 36fb421 7713986 937f590 d5b9aaa b991d0a 937f590 d7040df 36fb421 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# !pip install -Uq diffusers transformers
# !pip install -Uq gradio
# !pip install -Uq accelerate
import gradio
from diffusers import StableDiffusionPipeline as pipeline
from accelerate import init_empty_weights
import torch
from PIL import Image
import matplotlib.pyplot as plot
my_token = "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"
with init_empty_weights():
pipe = pipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=my_token).to("cuda")
def image_prompt(thing):
prompt = "A children's drawing of a " + thing
return pipe(prompt=prompt, height=512, width=664).images[0]
with gradio.Blocks(css="""
#go-button {
background-color: white;
border-radius: 0;
border: none;
font-family: serif;
background-image: none;
font-weight: 100;
width: fit-content;
display: block;
margin-left: auto;
margin-right: auto;
text-decoration: underline;
box-shadow: none;
}
.rounded-lg {
border: none;
}
.gr-box {
border-radius: 0;
border: 1px solid black;
}
.text-gray-500 {
color: black;
font-family: serif;
font-size: 15px;
}
.border-gray-200 {
border: 1px solid black;
}
.bg-gray-200 {
background-color: white;
--tw-bg-opacity: 0;
}
footer {
display: none;
}
footer {
opacity: 0;
}
#output-image {
border: 1px solid black;
background-color: white;
width: 500px;
display: block;
margin-left: auto;
margin-right: auto;
}
.absolute {
display: none;
}
#input-text {
width: 500px;
display: block;
margin-left: auto;
margin-right: auto;
padding: 0 0 0 0;
}
.py-6 {
padding-top: 0;
padding-bottom: 0;
}
.px-4 {
padding-left: 0;
padding-right: 0;
}
.rounded-lg {
border-radius: 0;
}
""") as demo:
animal = gradio.Textbox(label="a children's drawing of a...", elem_id="input-text")
output = gradio.Image(elem_id="output-image")
go_button = gradio.Button("draw it!", elem_id="go-button")
go_button.click(fn=image_prompt, inputs=animal, outputs=output)
demo.launch() |