Spaces:
Sleeping
Sleeping
Soumalya Das
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
+
|
| 5 |
+
torch.set_num_threads(torch.get_num_threads())
|
| 6 |
+
torch.set_float32_matmul_precision("high")
|
| 7 |
+
|
| 8 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
+
"stablediffusionapi/anything-v5",
|
| 10 |
+
torch_dtype=torch.float32
|
| 11 |
+
)
|
| 12 |
+
pipe = pipe.to("cpu")
|
| 13 |
+
|
| 14 |
+
def generate(prompt, steps, seed):
|
| 15 |
+
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 16 |
+
|
| 17 |
+
for i, out in enumerate(pipe(
|
| 18 |
+
prompt=prompt,
|
| 19 |
+
num_inference_steps=steps,
|
| 20 |
+
generator=generator,
|
| 21 |
+
callback_steps=1,
|
| 22 |
+
callback=lambda step, t, latents: None
|
| 23 |
+
)):
|
| 24 |
+
yield gr.Progress((i + 1) / steps), out.images[0]
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("## 🌀 Anything-V5 CPU Anime Generator")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
prompt = gr.Textbox(
|
| 31 |
+
label="Prompt",
|
| 32 |
+
value="Astronaut in a jungle, cold color palette, muted colors, detailed, anime style"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
steps = gr.Slider(10, 40, value=25, step=1, label="Steps")
|
| 37 |
+
seed = gr.Number(value=42, precision=0, label="Seed")
|
| 38 |
+
|
| 39 |
+
output = gr.Image(type="pil", label="Result")
|
| 40 |
+
|
| 41 |
+
btn = gr.Button("Generate")
|
| 42 |
+
|
| 43 |
+
btn.click(
|
| 44 |
+
fn=generate,
|
| 45 |
+
inputs=[prompt, steps, seed],
|
| 46 |
+
outputs=output
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
demo.launch()
|