Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import cv2
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import torch, os, random
|
6 |
+
from accelerate import Accelerator
|
7 |
+
from transformers import pipeline
|
8 |
+
from diffusers.utils import load_image
|
9 |
+
from diffusers import DiffusionPipeline, DDPMScheduler
|
10 |
+
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS
|
11 |
+
|
12 |
+
accelerator = Accelerator(cpu=True)
|
13 |
+
warp_prior = accelerator.prepare(DiffusionPipeline.from_pretrained("warp-ai/wuerstchen-prior", torch_dtype=torch.bfloat16))
|
14 |
+
warp_prior.scheduler = DDPMScheduler.from_config(warp_prior.scheduler.config)
|
15 |
+
warp_prior = warp_prior.to("cpu")
|
16 |
+
warp = accelerator.prepare(DiffusionPipeline.from_pretrained("warp-ai/wuerstchen", torch_dtype=torch.bfloat16))
|
17 |
+
warp.scheduler = DDPMScheduler.from_config(warp.scheduler.config)
|
18 |
+
warp = warp.to("cpu")
|
19 |
+
generator = torch.Generator(device="cpu").manual_seed(random.randint(1, 4876364))
|
20 |
+
|
21 |
+
def plex(cook, one, two, three):
|
22 |
+
###goof = load_image(img).resize((512, 512))
|
23 |
+
negative_prompt = "lowres,text,bad quality,low quality,jpeg artifacts,ugly,bad hands,bad face,blurry,bad eyes,watermark,signature"
|
24 |
+
warp_out = warp_prior(prompt=cook, height=512,width=512,negative_prompt=negative_prompt,guidance_scale=4.0, num_inference_steps=5,generator=generator)
|
25 |
+
primpt = ""
|
26 |
+
imas = warp(**warp_out, height=512, width=512, num_inference_steps=5, prompt=cook,negative_prompt=primpt,guidance_scale=0.0,output_type="pil",generator=generator).images[0]
|
27 |
+
return imas
|
28 |
+
|
29 |
+
iface = gr.Interface(fn=plex,inputs=[gr.Textbox(label="prompt"), gr.Slider(label="Text Guide",minimum=0.01,step=0.01,maximum=0.99,value=0.5), gr.Slider(label="Your Image Guide",minimum=0.01,step=0.01,maximum=0.99,value=0.5),gr.Slider(label="Generated Image Guide",minimum=0.01,step=0.01,maximum=0.99,value=0.3)], outputs=gr.Image(), title="Txt2Img Wrstchn Interp", description="Txt2Img Wrstchn Interp")
|
30 |
+
iface.queue(max_size=1)
|
31 |
+
iface.launch(max_threads=1)
|