Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files- hf_demo.py +16 -10
- hf_demo_test.ipynb +1 -1
hf_demo.py
CHANGED
@@ -45,7 +45,7 @@ def demo_inference_gen_artistic(adapter_choice:str, prompt:str, seed:int=0, step
|
|
45 |
style_prompt=None
|
46 |
prompts = [prompt]
|
47 |
infer_loader = get_validation_dataloader(prompts,num_workers=0)
|
48 |
-
network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype)["network"]
|
49 |
|
50 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
51 |
height=512, width=512, scales=[adapter_scale],
|
@@ -59,7 +59,7 @@ def demo_inference_gen_ori( prompt:str, seed:int=0, steps=50, guidance_scale=7.5
|
|
59 |
style_prompt=None
|
60 |
prompts = [prompt]
|
61 |
infer_loader = get_validation_dataloader(prompts,num_workers=0)
|
62 |
-
network = get_lora_network(pipe.unet, "None", weight_dtype=dtype)["network"]
|
63 |
|
64 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
65 |
height=512, width=512, scales=[0.0],
|
@@ -75,7 +75,7 @@ def demo_inference_stylization_ori(ref_image, prompt:str, seed:int=0, steps=50,
|
|
75 |
prompts = [prompt]
|
76 |
# convert np to pil
|
77 |
ref_image = [Image.fromarray(ref_image)]
|
78 |
-
network = get_lora_network(pipe.unet, "None", weight_dtype=dtype)["network"]
|
79 |
infer_loader = get_validation_dataloader(prompts, ref_image,num_workers=0)
|
80 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
81 |
height=512, width=512, scales=[0.0],
|
@@ -95,7 +95,7 @@ def demo_inference_stylization_artistic(ref_image, adapter_choice:str, prompt:st
|
|
95 |
prompts = [prompt]
|
96 |
# convert np to pil
|
97 |
ref_image = [Image.fromarray(ref_image)]
|
98 |
-
network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype)["network"]
|
99 |
infer_loader = get_validation_dataloader(prompts, ref_image,num_workers=0)
|
100 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
101 |
height=512, width=512, scales=[adapter_scale],
|
@@ -105,7 +105,7 @@ def demo_inference_stylization_artistic(ref_image, adapter_choice:str, prompt:st
|
|
105 |
return pred_images
|
106 |
|
107 |
@spaces.GPU
|
108 |
-
def demo_inference_all(prompt:str, ref_image, adapter_choice="Andre Derain (fauvism)",
|
109 |
results = []
|
110 |
results.append(demo_inference_gen_ori(prompt, seed, steps, guidance_scale))
|
111 |
results.append(demo_inference_gen_artistic(adapter_choice, prompt, seed, steps, guidance_scale, adapter_scale))
|
@@ -126,7 +126,7 @@ with block:
|
|
126 |
max_lines=10,
|
127 |
placeholder="Enter your prompt (long and detailed would be better)",
|
128 |
container=True,
|
129 |
-
value="a
|
130 |
)
|
131 |
|
132 |
with gr.Tab('Generation'):
|
@@ -242,27 +242,32 @@ with block:
|
|
242 |
examples=[
|
243 |
["Snow-covered trees with sunlight shining through",
|
244 |
"data/Snow-covered_trees_with_sunlight_shining_through.jpg",
|
|
|
245 |
],
|
246 |
["A picturesque landscape showcasing a winding river cutting through a lush green valley, surrounded by rugged mountains under a clear blue sky. The mix of red and brown tones in the rocky hills adds to the region's natural beauty and diversity.",
|
247 |
"data/0011772.jpg",
|
|
|
248 |
],
|
249 |
-
["
|
250 |
"data/a_black_SUV_driving_down_a_highway_with_a_scenic_view_of_mountains_and_water_in_the_background._The_.jpg",
|
|
|
251 |
],
|
252 |
-
["
|
253 |
-
"data/a_beautiful_garden_with_a_large_pond._The_pond_is_surrounded_by_a_wooden_deck,_and_there_are_several.jpg"
|
|
|
254 |
],
|
255 |
[
|
256 |
"A blue bench situated in a park, surrounded by trees and leaves. The bench is positioned under a tree, providing shade and a peaceful atmosphere. There are several benches in the park, with one being closer to the foreground and the others further in the background. A person can be seen in the distance, possibly enjoying the park or taking a walk. The overall scene is serene and inviting, with the bench serving as a focal point in the park's landscape.",
|
257 |
"data/003904765.jpg",
|
|
|
258 |
]
|
259 |
|
260 |
],
|
261 |
inputs=[
|
262 |
text,
|
263 |
gallery_stylization_ref,
|
264 |
-
adapter_choice,
|
265 |
seed,
|
|
|
266 |
steps,
|
267 |
scale,
|
268 |
adapter_scale,
|
@@ -272,5 +277,6 @@ with block:
|
|
272 |
outputs=[gallery_gen_ori, gallery_gen_art, gallery_stylization_ori, gallery_stylization_art],
|
273 |
cache_examples=True,
|
274 |
)
|
|
|
275 |
block.launch()
|
276 |
# block.launch(sharing=True)
|
|
|
45 |
style_prompt=None
|
46 |
prompts = [prompt]
|
47 |
infer_loader = get_validation_dataloader(prompts,num_workers=0)
|
48 |
+
network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype, device=device)["network"]
|
49 |
|
50 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
51 |
height=512, width=512, scales=[adapter_scale],
|
|
|
59 |
style_prompt=None
|
60 |
prompts = [prompt]
|
61 |
infer_loader = get_validation_dataloader(prompts,num_workers=0)
|
62 |
+
network = get_lora_network(pipe.unet, "None", weight_dtype=dtype, device=device)["network"]
|
63 |
|
64 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
65 |
height=512, width=512, scales=[0.0],
|
|
|
75 |
prompts = [prompt]
|
76 |
# convert np to pil
|
77 |
ref_image = [Image.fromarray(ref_image)]
|
78 |
+
network = get_lora_network(pipe.unet, "None", weight_dtype=dtype, device=device)["network"]
|
79 |
infer_loader = get_validation_dataloader(prompts, ref_image,num_workers=0)
|
80 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
81 |
height=512, width=512, scales=[0.0],
|
|
|
95 |
prompts = [prompt]
|
96 |
# convert np to pil
|
97 |
ref_image = [Image.fromarray(ref_image)]
|
98 |
+
network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype, device=device)["network"]
|
99 |
infer_loader = get_validation_dataloader(prompts, ref_image,num_workers=0)
|
100 |
pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,
|
101 |
height=512, width=512, scales=[adapter_scale],
|
|
|
105 |
return pred_images
|
106 |
|
107 |
@spaces.GPU
|
108 |
+
def demo_inference_all(prompt:str, ref_image, seed:int=0, adapter_choice="Andre Derain (fauvism)", steps=20, guidance_scale=7.5, adapter_scale=1.0,start_noise=800):
|
109 |
results = []
|
110 |
results.append(demo_inference_gen_ori(prompt, seed, steps, guidance_scale))
|
111 |
results.append(demo_inference_gen_artistic(adapter_choice, prompt, seed, steps, guidance_scale, adapter_scale))
|
|
|
126 |
max_lines=10,
|
127 |
placeholder="Enter your prompt (long and detailed would be better)",
|
128 |
container=True,
|
129 |
+
value="A beautiful garden with a large pond. The pond is surrounded by a wooden deck, and there are several chairs placed around the area. A stone fountain is present in the middle of the pond, adding to the serene atmosphere. The garden is decorated with a variety of potted plants, creating a lush and inviting environment. The scene is captured in a vibrant and colorful style, highlighting the natural beauty of the garden.",
|
130 |
)
|
131 |
|
132 |
with gr.Tab('Generation'):
|
|
|
242 |
examples=[
|
243 |
["Snow-covered trees with sunlight shining through",
|
244 |
"data/Snow-covered_trees_with_sunlight_shining_through.jpg",
|
245 |
+
0,
|
246 |
],
|
247 |
["A picturesque landscape showcasing a winding river cutting through a lush green valley, surrounded by rugged mountains under a clear blue sky. The mix of red and brown tones in the rocky hills adds to the region's natural beauty and diversity.",
|
248 |
"data/0011772.jpg",
|
249 |
+
528741066,
|
250 |
],
|
251 |
+
["A black SUV driving down a highway with a scenic view of mountains and water in the background. The SUV is the main focus of the image, and it appears to be traveling at a moderate speed. The road is well-maintained and provides a smooth driving experience. The mountains and water create a picturesque backdrop, adding to the overall beauty of the scene. The image captures the essence of a leisurely road trip, with the SUV as the primary subject, highlighting the sense of adventure and exploration that comes with such journeys.",
|
252 |
"data/a_black_SUV_driving_down_a_highway_with_a_scenic_view_of_mountains_and_water_in_the_background._The_.jpg",
|
253 |
+
98762568,
|
254 |
],
|
255 |
+
["A beautiful garden with a large pond. The pond is surrounded by a wooden deck, and there are several chairs placed around the area. A stone fountain is present in the middle of the pond, adding to the serene atmosphere. The garden is decorated with a variety of potted plants, creating a lush and inviting environment. The scene is captured in a vibrant and colorful style, highlighting the natural beauty of the garden.",
|
256 |
+
"data/a_beautiful_garden_with_a_large_pond._The_pond_is_surrounded_by_a_wooden_deck,_and_there_are_several.jpg",
|
257 |
+
76265772,
|
258 |
],
|
259 |
[
|
260 |
"A blue bench situated in a park, surrounded by trees and leaves. The bench is positioned under a tree, providing shade and a peaceful atmosphere. There are several benches in the park, with one being closer to the foreground and the others further in the background. A person can be seen in the distance, possibly enjoying the park or taking a walk. The overall scene is serene and inviting, with the bench serving as a focal point in the park's landscape.",
|
261 |
"data/003904765.jpg",
|
262 |
+
3904764,
|
263 |
]
|
264 |
|
265 |
],
|
266 |
inputs=[
|
267 |
text,
|
268 |
gallery_stylization_ref,
|
|
|
269 |
seed,
|
270 |
+
adapter_choice,
|
271 |
steps,
|
272 |
scale,
|
273 |
adapter_scale,
|
|
|
277 |
outputs=[gallery_gen_ori, gallery_gen_art, gallery_stylization_ori, gallery_stylization_art],
|
278 |
cache_examples=True,
|
279 |
)
|
280 |
+
|
281 |
block.launch()
|
282 |
# block.launch(sharing=True)
|
hf_demo_test.ipynb
CHANGED
@@ -134,7 +134,7 @@
|
|
134 |
" style_prompt=None\n",
|
135 |
" prompts = [prompt]\n",
|
136 |
" infer_loader = get_validation_dataloader(prompts,num_workers=0)\n",
|
137 |
-
" network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype)[\"network\"]\n",
|
138 |
"\n",
|
139 |
" pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,\n",
|
140 |
" height=512, width=512, scales=[adapter_scale],\n",
|
|
|
134 |
" style_prompt=None\n",
|
135 |
" prompts = [prompt]\n",
|
136 |
" infer_loader = get_validation_dataloader(prompts,num_workers=0)\n",
|
137 |
+
" network = get_lora_network(pipe.unet, adapter_path, weight_dtype=dtype, device=device)[\"network\"]\n",
|
138 |
"\n",
|
139 |
" pred_images = inference(network, pipe.tokenizer, pipe.text_encoder, pipe.vae, pipe.unet, pipe.scheduler, infer_loader,\n",
|
140 |
" height=512, width=512, scales=[adapter_scale],\n",
|