Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
3ea8d63
1
Parent(s):
79378ee
update: batch mode
Browse files
app.py
CHANGED
@@ -73,7 +73,15 @@ def _normalize_batch_inputs(source_images, characters, reference_images) -> Tupl
|
|
73 |
if isinstance(source_images, Image.Image):
|
74 |
content_inputs = [source_images]
|
75 |
elif isinstance(source_images, list):
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
else:
|
78 |
return [], [], [], 0
|
79 |
|
@@ -96,8 +104,9 @@ def _normalize_batch_inputs(source_images, characters, reference_images) -> Tupl
|
|
96 |
|
97 |
@spaces.GPU()
|
98 |
def run_fontdiffuer_batch(source_images: Union[List[Image.Image], Image.Image, None],
|
99 |
-
|
100 |
-
|
|
|
101 |
sampling_step: int = 50,
|
102 |
guidance_scale: float = 7.5,
|
103 |
batch_size: int = 4,
|
@@ -118,6 +127,10 @@ def run_fontdiffuer_batch(source_images: Union[List[Image.Image], Image.Image, N
|
|
118 |
List of generated images
|
119 |
"""
|
120 |
|
|
|
|
|
|
|
|
|
121 |
# Normalize inputs to lists
|
122 |
content_inputs, style_inputs, char_inputs, total_samples = _normalize_batch_inputs(
|
123 |
source_images, characters, reference_images
|
@@ -284,5 +297,28 @@ if __name__ == '__main__':
|
|
284 |
guidance_scale,
|
285 |
batch_size],
|
286 |
outputs=fontdiffuer_output_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
demo.launch(debug=True)
|
288 |
-
demo.queue(default_concurrency_limit=16)
|
|
|
73 |
if isinstance(source_images, Image.Image):
|
74 |
content_inputs = [source_images]
|
75 |
elif isinstance(source_images, list):
|
76 |
+
# Handle Gradio Gallery format: list of tuples (image, caption)
|
77 |
+
content_inputs = []
|
78 |
+
for item in source_images:
|
79 |
+
if isinstance(item, tuple) and len(item) >= 1:
|
80 |
+
# Extract the image from tuple (image, caption)
|
81 |
+
content_inputs.append(item[0])
|
82 |
+
elif isinstance(item, Image.Image):
|
83 |
+
# Direct image
|
84 |
+
content_inputs.append(item)
|
85 |
else:
|
86 |
return [], [], [], 0
|
87 |
|
|
|
104 |
|
105 |
@spaces.GPU()
|
106 |
def run_fontdiffuer_batch(source_images: Union[List[Image.Image], Image.Image, None],
|
107 |
+
# characters: Union[List[str], str, None],
|
108 |
+
# reference_images: Union[List[Image.Image], Image.Image],
|
109 |
+
reference_image: Image.Image,
|
110 |
sampling_step: int = 50,
|
111 |
guidance_scale: float = 7.5,
|
112 |
batch_size: int = 4,
|
|
|
127 |
List of generated images
|
128 |
"""
|
129 |
|
130 |
+
args.adaptive_batch_size = True
|
131 |
+
characters = None
|
132 |
+
reference_images = [reference_image]
|
133 |
+
|
134 |
# Normalize inputs to lists
|
135 |
content_inputs, style_inputs, char_inputs, total_samples = _normalize_batch_inputs(
|
136 |
source_images, characters, reference_images
|
|
|
297 |
guidance_scale,
|
298 |
batch_size],
|
299 |
outputs=fontdiffuer_output_image)
|
300 |
+
|
301 |
+
# Batch Mode
|
302 |
+
gr.Markdown("## Batch Mode")
|
303 |
+
with gr.Row():
|
304 |
+
input_images = gr.Gallery(
|
305 |
+
format='png',
|
306 |
+
file_types=['image'],
|
307 |
+
type='pil',
|
308 |
+
)
|
309 |
+
|
310 |
+
reference_image = gr.Image(label='Reference Image', image_mode='RGB', type='pil')
|
311 |
+
|
312 |
+
output_images = gr.Gallery(
|
313 |
+
format='png',
|
314 |
+
type='pil'
|
315 |
+
)
|
316 |
+
|
317 |
+
RunFontDiffuserBatch = gr.Button('Run FontDiffuser Batch Mode')
|
318 |
+
RunFontDiffuserBatch.click(
|
319 |
+
fn=run_fontdiffuer_batch,
|
320 |
+
inputs=[input_images, reference_image],
|
321 |
+
outputs=output_images
|
322 |
+
)
|
323 |
+
|
324 |
demo.launch(debug=True)
|
|