Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py.text.111.txt +51 -0
- requirements (33).txt +9 -0
app.py.text.111.txt
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import cv2
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import torch
|
6 |
+
from accelerate import Accelerator
|
7 |
+
from transformers import pipeline
|
8 |
+
from diffusers.utils import load_image
|
9 |
+
from diffusers import KandinskyV22PriorPipeline, KandinskyV22Pipeline
|
10 |
+
|
11 |
+
accelerator = Accelerator(cpu=True)
|
12 |
+
|
13 |
+
generator = torch.Generator(device="cpu").manual_seed(43)
|
14 |
+
pope_prior = accelerator.prepare(KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float32))
|
15 |
+
pope_prior = accelerator.prepare(pope_prior.to("cpu"))
|
16 |
+
|
17 |
+
pope = accelerator.prepare(KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float32))
|
18 |
+
pope = accelerator.prepare(pope.to("cpu"))
|
19 |
+
|
20 |
+
def plex(img, cook, one, two, three):
|
21 |
+
goof = load_image(img).resize((512, 512))
|
22 |
+
# We pass the prompt and negative prompt through the prior to generate image embeddings
|
23 |
+
prompt = cook
|
24 |
+
negative_prior_prompt = "lowres,text,bad quality,low quality,jpeg artifacts,ugly,bad hands,bad face,blurry,bad eyes,watermark,signature"
|
25 |
+
img_emb = pope_prior(prompt=prompt, image=goof, strength=0.85, num_prior_inference_steps=10, generator=generator)
|
26 |
+
negative_emb = pope_prior(prompt=negative_prior_prompt, image=goof, strength=1, num_neg_inference_steps=10, generator=generator)
|
27 |
+
|
28 |
+
# run text2img pipeline
|
29 |
+
imags = pope(
|
30 |
+
image_embeds=img_emb.image_embeds,
|
31 |
+
negative_image_embeds=negative_emb.image_embeds,
|
32 |
+
num_inference_steps=20,
|
33 |
+
generator=generator,
|
34 |
+
height=512,
|
35 |
+
width=512,
|
36 |
+
).images[0]
|
37 |
+
|
38 |
+
## return imags
|
39 |
+
images_texts = [cook, goof, imags]
|
40 |
+
|
41 |
+
# specify the weights for each condition in images_texts
|
42 |
+
weights = [one, two, three]
|
43 |
+
|
44 |
+
# We can leave the prompt empty
|
45 |
+
primpt = ""
|
46 |
+
prior_out = pope_prior.interpolate(images_texts, weights)
|
47 |
+
imas = pope(**prior_out, height=512, width=512).images[0]
|
48 |
+
return imas
|
49 |
+
|
50 |
+
iface = gr.Interface(fn=plex,inputs=[gr.Image(label="drop", type="pil"), gr.Textbox(label="prompt"), gr.Slider(label="Text Guide",minimum=0.01,step=0.01,maximum=1,value=0.5), gr.Slider(label="Your Image Guide",minimum=0.01,step=0.01,maximum=1,value=0.5),gr.Slider(label="Generated Image Guide",minimum=0.01,step=0.01,maximum=1,value=0.3)], outputs=gr.Image(), title="Ksky22 Cntrl Gdd Interp", description="ksky22 Cntrl Gdd Interp")
|
51 |
+
iface.launch()
|
requirements (33).txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
numpy
|
5 |
+
opencv-python
|
6 |
+
diffusers
|
7 |
+
controlnet_aux
|
8 |
+
mediapipe
|
9 |
+
accelerate
|