Spaces:
Paused
Paused
CiaraRowles
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -47,25 +47,46 @@ ip_model = IPAdapterInstruct(pipe, image_encoder_path, ip_ckpt, device,dtypein=t
|
|
47 |
cv2.setNumThreads(1)
|
48 |
|
49 |
@spaces.GPU(enable_queue=True)
|
50 |
-
def generate_image(images, prompt, negative_prompt,scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
51 |
faceid_all_embeds = []
|
52 |
first_iteration = True
|
53 |
image = images
|
54 |
-
|
55 |
-
#average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
56 |
-
|
57 |
total_negative_prompt = f"{negative_prompt} {nfaa_negative_prompt}"
|
58 |
-
|
59 |
print("Generating normal")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
image = ip_model.generate(
|
61 |
-
prompt=prompt,
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
)
|
64 |
-
|
65 |
-
print(image)
|
66 |
return image
|
67 |
|
68 |
|
|
|
69 |
def swap_to_gallery(images):
|
70 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
71 |
|
@@ -89,6 +110,18 @@ with gr.Blocks(css=css) as demo:
|
|
89 |
prompt = gr.Textbox(label="Prompt",
|
90 |
info="Try something like 'a photo of a man/woman/person'",
|
91 |
placeholder="A photo of a [man/woman/person]...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality")
|
93 |
submit = gr.Button("Submit")
|
94 |
with gr.Accordion(open=False, label="Advanced Options"):
|
@@ -96,12 +129,11 @@ with gr.Blocks(css=css) as demo:
|
|
96 |
scale = gr.Slider(label="Scale", value=1.0, step=0.1, minimum=0, maximum=5)
|
97 |
with gr.Column():
|
98 |
gallery = gr.Gallery(label="Generated Images")
|
99 |
-
|
100 |
-
#remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
101 |
submit.click(fn=generate_image,
|
102 |
-
inputs=[files,prompt,negative_prompt,scale, nfaa_negative_prompts],
|
103 |
outputs=gallery)
|
104 |
|
105 |
gr.Markdown("This demo includes extra features to mitigate the implicit bias of the model and prevent explicit usage of it to generate content with faces of people, including third parties, that is not safe for all audiences, including naked or semi-naked people.")
|
106 |
-
|
107 |
demo.launch()
|
|
|
47 |
cv2.setNumThreads(1)
|
48 |
|
49 |
@spaces.GPU(enable_queue=True)
|
50 |
+
def generate_image(images, prompt, negative_prompt,instruct_query, scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
51 |
faceid_all_embeds = []
|
52 |
first_iteration = True
|
53 |
image = images
|
54 |
+
|
|
|
|
|
55 |
total_negative_prompt = f"{negative_prompt} {nfaa_negative_prompt}"
|
|
|
56 |
print("Generating normal")
|
57 |
+
|
58 |
+
# Calculate aspect ratio
|
59 |
+
aspect_ratio = image.width / image.height
|
60 |
+
|
61 |
+
# Set base_size (you can adjust this value as needed)
|
62 |
+
base_size = 512
|
63 |
+
|
64 |
+
# Calculate new width and height
|
65 |
+
if aspect_ratio > 1: # Landscape
|
66 |
+
new_width = base_size
|
67 |
+
new_height = int(base_size / aspect_ratio)
|
68 |
+
else: # Portrait or square
|
69 |
+
new_height = base_size
|
70 |
+
new_width = int(base_size * aspect_ratio)
|
71 |
+
|
72 |
+
# Ensure dimensions are multiples of 8 (required by some models)
|
73 |
+
new_width = (new_width // 8) * 8
|
74 |
+
new_height = (new_height // 8) * 8
|
75 |
+
|
76 |
image = ip_model.generate(
|
77 |
+
prompt=prompt,
|
78 |
+
negative_prompt=total_negative_prompt,
|
79 |
+
pil_image=image,
|
80 |
+
scale=scale,
|
81 |
+
width=new_width,
|
82 |
+
height=new_height,
|
83 |
+
num_inference_steps=30,
|
84 |
+
query=instruct_query
|
85 |
)
|
|
|
|
|
86 |
return image
|
87 |
|
88 |
|
89 |
+
|
90 |
def swap_to_gallery(images):
|
91 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
92 |
|
|
|
110 |
prompt = gr.Textbox(label="Prompt",
|
111 |
info="Try something like 'a photo of a man/woman/person'",
|
112 |
placeholder="A photo of a [man/woman/person]...")
|
113 |
+
instruct_query = gr.Dropdown(
|
114 |
+
label="Instruct Query",
|
115 |
+
choices=[
|
116 |
+
"use everything from the image",
|
117 |
+
"use the style",
|
118 |
+
"use the colour",
|
119 |
+
"use the pose",
|
120 |
+
"use the composition",
|
121 |
+
"use the face"
|
122 |
+
],
|
123 |
+
value="use everything from the image"
|
124 |
+
)
|
125 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality")
|
126 |
submit = gr.Button("Submit")
|
127 |
with gr.Accordion(open=False, label="Advanced Options"):
|
|
|
129 |
scale = gr.Slider(label="Scale", value=1.0, step=0.1, minimum=0, maximum=5)
|
130 |
with gr.Column():
|
131 |
gallery = gr.Gallery(label="Generated Images")
|
132 |
+
|
|
|
133 |
submit.click(fn=generate_image,
|
134 |
+
inputs=[files, prompt, negative_prompt,instruct_query, scale, nfaa_negative_prompts, instruct_query],
|
135 |
outputs=gallery)
|
136 |
|
137 |
gr.Markdown("This demo includes extra features to mitigate the implicit bias of the model and prevent explicit usage of it to generate content with faces of people, including third parties, that is not safe for all audiences, including naked or semi-naked people.")
|
138 |
+
|
139 |
demo.launch()
|