Spaces:
Runtime error
Runtime error
Commit
Β·
937f590
1
Parent(s):
c4c47c8
Overhaul style
Browse files
app.py
CHANGED
@@ -1,15 +1,66 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio
|
2 |
from diffusers import StableDiffusionPipeline as pipeline
|
|
|
3 |
import torch
|
4 |
|
|
|
|
|
|
|
5 |
my_token = "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"
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
def image_prompt(thing):
|
9 |
prompt = "A children's drawing of a " + thing
|
10 |
return pipe(prompt=prompt, height=512, width=664).images[0]
|
11 |
|
12 |
-
with gradio.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
animal = gradio.Textbox(label="A kid's drawing of a...")
|
14 |
output = gradio.Image(label="Behold...")
|
15 |
go_button = gradio.Button("Draw it!")
|
|
|
1 |
+
# !pip install -Uq diffusers transformers
|
2 |
+
# !pip install -Uq gradio
|
3 |
+
# !pip install -Uq accelerate
|
4 |
+
|
5 |
import gradio
|
6 |
from diffusers import StableDiffusionPipeline as pipeline
|
7 |
+
from accelerate import init_empty_weights
|
8 |
import torch
|
9 |
|
10 |
+
from PIL import Image
|
11 |
+
import matplotlib.pyplot as plot
|
12 |
+
|
13 |
my_token = "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"
|
14 |
+
|
15 |
+
with init_empty_weights():
|
16 |
+
pipe = pipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=my_token).to("cuda")
|
17 |
+
|
18 |
|
19 |
def image_prompt(thing):
|
20 |
prompt = "A children's drawing of a " + thing
|
21 |
return pipe(prompt=prompt, height=512, width=664).images[0]
|
22 |
|
23 |
+
with gradio.Blocks(css="""
|
24 |
+
#go-button {
|
25 |
+
background-color: white;
|
26 |
+
border-radius: 0;
|
27 |
+
border: none;
|
28 |
+
font-family: serif;
|
29 |
+
background-image: none;
|
30 |
+
font-weight: 100;
|
31 |
+
width: fit-content;
|
32 |
+
display: block;
|
33 |
+
margin-left: auto;
|
34 |
+
margin-right: auto;
|
35 |
+
text-decoration: underline;
|
36 |
+
box-shadow: none;
|
37 |
+
}
|
38 |
+
.rounded-lg {
|
39 |
+
border: none;
|
40 |
+
}
|
41 |
+
.gr-box {
|
42 |
+
border-radius: 0;
|
43 |
+
border: 1px solid black;
|
44 |
+
}
|
45 |
+
.text-gray-500 {
|
46 |
+
color: black;
|
47 |
+
font-family: serif;
|
48 |
+
font-size: 15px;
|
49 |
+
}
|
50 |
+
.border-gray-200 {
|
51 |
+
border: 1px solid black;
|
52 |
+
}
|
53 |
+
.bg-gray-200 {
|
54 |
+
background-color: white;
|
55 |
+
--tw-bg-opacity: 0;
|
56 |
+
}
|
57 |
+
footer {
|
58 |
+
display: none;
|
59 |
+
}
|
60 |
+
footer {
|
61 |
+
opacity: 0;
|
62 |
+
}
|
63 |
+
""") as demo:
|
64 |
animal = gradio.Textbox(label="A kid's drawing of a...")
|
65 |
output = gradio.Image(label="Behold...")
|
66 |
go_button = gradio.Button("Draw it!")
|