Spaces:
Running
on
Zero
Running
on
Zero
TempleX
commited on
Commit
·
b74b343
1
Parent(s):
cc3fc01
Update README
Browse files
app.py
CHANGED
@@ -36,12 +36,12 @@ def get_example():
|
|
36 |
[
|
37 |
get_image_path_list('./assets/aragaki_identity'),
|
38 |
"An oil painting of a smiling woman.",
|
39 |
-
"A collage of images, monochrome, lowres, bad anatomy, worst quality, low quality",
|
40 |
],
|
41 |
[
|
42 |
get_image_path_list('./assets/blindbox_style'),
|
43 |
"Donald Trump",
|
44 |
-
"A collage of images, monochrome, lowres, bad anatomy, worst quality, low quality",
|
45 |
],
|
46 |
]
|
47 |
return case
|
@@ -72,10 +72,8 @@ easyref = EasyRef(pipe, multimodal_llm_path, ip_ckpt, device, num_tokens=64, use
|
|
72 |
cv2.setNumThreads(1)
|
73 |
|
74 |
@spaces.GPU(enable_queue=True)
|
75 |
-
def generate_image(images, prompt, negative_prompt,
|
76 |
print("Generating")
|
77 |
-
new_width, new_height = adaptive_resize(width, height)
|
78 |
-
print("The output resolution is adaptively resized from {ori} to {new}".format(ori=res2string(width, height), new=res2string(new_width, new_height)))
|
79 |
template = "Visualize a scene that closely resembles the provided images, capturing the essence and details described in this prompt:\n"
|
80 |
system_prompt = [template + prompt, template]
|
81 |
image = easyref.generate(
|
@@ -83,11 +81,10 @@ def generate_image(images, prompt, negative_prompt, height, width, scale, num_in
|
|
83 |
system_prompt=system_prompt,
|
84 |
prompt=prompt,
|
85 |
negative_prompt=negative_prompt,
|
|
|
86 |
num_samples=1,
|
87 |
num_inference_steps=num_inference_steps,
|
88 |
-
seed=seed
|
89 |
-
height=new_height,
|
90 |
-
width=new_width)
|
91 |
print(image)
|
92 |
return image
|
93 |
|
@@ -116,7 +113,7 @@ with gr.Blocks(css=css) as demo:
|
|
116 |
label="Upload several reference images",
|
117 |
file_types=["image"]
|
118 |
)
|
119 |
-
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=
|
120 |
with gr.Column(visible=False) as clear_button:
|
121 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
122 |
prompt = gr.Textbox(label="Prompt",
|
@@ -125,28 +122,26 @@ with gr.Blocks(css=css) as demo:
|
|
125 |
# style = gr.Radio(label="Generation type", info="For stylized try prompts like 'a watercolor painting of a woman'", choices=["Photorealistic", "Stylized"], value="Photorealistic")
|
126 |
submit = gr.Button("Submit")
|
127 |
with gr.Accordion(open=False, label="Advanced Options"):
|
128 |
-
|
129 |
-
width = gr.Slider(label="Width", info="This will be adaptively resized", value=1024, step=64, minimum=896, maximum=1280)
|
130 |
-
scale = gr.Slider(label="Scale", info="Scale for reference images", value=1.0, step=0.1, minimum=0.5, maximum=1.5)
|
131 |
num_inference_steps = gr.Slider(label="Number of inference steps", value=30, step=1, minimum=1, maximum=60)
|
132 |
seed = gr.Slider(label="Seed", value=24, step=1, minimum=0, maximum=MAX_SEED)
|
133 |
with gr.Column():
|
134 |
gallery = gr.Gallery(label="Generated Images")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
# style.change(fn=change_style,
|
136 |
# inputs=style,
|
137 |
# outputs=[preserve, face_strength, likeness_strength])
|
138 |
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
139 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
140 |
submit.click(fn=generate_image,
|
141 |
-
inputs=[files,prompt,negative_prompt,
|
142 |
outputs=gallery)
|
143 |
-
gr.Examples(
|
144 |
-
examples=get_example(),
|
145 |
-
inputs=[files, prompt, negative_prompt],
|
146 |
-
run_on_click=True,
|
147 |
-
fn=upload_example_to_gallery,
|
148 |
-
outputs=[uploaded_files, clear_button, files],
|
149 |
-
)
|
150 |
|
151 |
gr.Markdown("We release our checkpoints for research purposes only. Users are granted the freedom to create images using this tool, but they are expected to comply with local laws and utilize it in a responsible manner. The developers do not assume any responsibility for potential misuse by users.")
|
152 |
|
|
|
36 |
[
|
37 |
get_image_path_list('./assets/aragaki_identity'),
|
38 |
"An oil painting of a smiling woman.",
|
39 |
+
"A collage of images, naked, monochrome, lowres, bad anatomy, worst quality, low quality",
|
40 |
],
|
41 |
[
|
42 |
get_image_path_list('./assets/blindbox_style'),
|
43 |
"Donald Trump",
|
44 |
+
"A collage of images, naked, monochrome, lowres, bad anatomy, worst quality, low quality",
|
45 |
],
|
46 |
]
|
47 |
return case
|
|
|
72 |
cv2.setNumThreads(1)
|
73 |
|
74 |
@spaces.GPU(enable_queue=True)
|
75 |
+
def generate_image(images, prompt, negative_prompt, scale, num_inference_steps, seed, progress=gr.Progress(track_tqdm=True)):
|
76 |
print("Generating")
|
|
|
|
|
77 |
template = "Visualize a scene that closely resembles the provided images, capturing the essence and details described in this prompt:\n"
|
78 |
system_prompt = [template + prompt, template]
|
79 |
image = easyref.generate(
|
|
|
81 |
system_prompt=system_prompt,
|
82 |
prompt=prompt,
|
83 |
negative_prompt=negative_prompt,
|
84 |
+
scale=scale,
|
85 |
num_samples=1,
|
86 |
num_inference_steps=num_inference_steps,
|
87 |
+
seed=seed)
|
|
|
|
|
88 |
print(image)
|
89 |
return image
|
90 |
|
|
|
113 |
label="Upload several reference images",
|
114 |
file_types=["image"]
|
115 |
)
|
116 |
+
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=6, rows=1, height=125)
|
117 |
with gr.Column(visible=False) as clear_button:
|
118 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
119 |
prompt = gr.Textbox(label="Prompt",
|
|
|
122 |
# style = gr.Radio(label="Generation type", info="For stylized try prompts like 'a watercolor painting of a woman'", choices=["Photorealistic", "Stylized"], value="Photorealistic")
|
123 |
submit = gr.Button("Submit")
|
124 |
with gr.Accordion(open=False, label="Advanced Options"):
|
125 |
+
scale = gr.Slider(label="Scale", info="Scale for image reference", value=1.0, step=0.1, minimum=0.5, maximum=1.5)
|
|
|
|
|
126 |
num_inference_steps = gr.Slider(label="Number of inference steps", value=30, step=1, minimum=1, maximum=60)
|
127 |
seed = gr.Slider(label="Seed", value=24, step=1, minimum=0, maximum=MAX_SEED)
|
128 |
with gr.Column():
|
129 |
gallery = gr.Gallery(label="Generated Images")
|
130 |
+
gr.Examples(
|
131 |
+
examples=get_example(),
|
132 |
+
inputs=[files, prompt, negative_prompt],
|
133 |
+
run_on_click=True,
|
134 |
+
fn=upload_example_to_gallery,
|
135 |
+
outputs=[uploaded_files, clear_button, files],
|
136 |
+
)
|
137 |
# style.change(fn=change_style,
|
138 |
# inputs=style,
|
139 |
# outputs=[preserve, face_strength, likeness_strength])
|
140 |
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
141 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
142 |
submit.click(fn=generate_image,
|
143 |
+
inputs=[files, prompt, negative_prompt, scale, num_inference_steps, seed],
|
144 |
outputs=gallery)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
gr.Markdown("We release our checkpoints for research purposes only. Users are granted the freedom to create images using this tool, but they are expected to comply with local laws and utilize it in a responsible manner. The developers do not assume any responsibility for potential misuse by users.")
|
147 |
|