Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -161,6 +161,39 @@ def caption_image(image, model_name='gokaygokay/Florence-2-Flux-Large'):
|
|
161 |
)
|
162 |
return parsed_answer["<DESCRIPTION>"]
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
# ----------------------------- Gradio UI --------------------------------------
|
165 |
with gr.Blocks(analytics_enabled=False) as demo:
|
166 |
with gr.Tabs():
|
@@ -264,7 +297,122 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
264 |
inputs=[input_img, model_selector],
|
265 |
outputs=[caption_output]
|
266 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
-
demo.launch(debug=True)
|
|
|
161 |
)
|
162 |
return parsed_answer["<DESCRIPTION>"]
|
163 |
|
164 |
+
# --------- NEW FUNCTION: Process uploaded image and generate Ghibli style image ---------
|
165 |
+
@spaces.GPU(duration=120)
|
166 |
+
def process_uploaded_image(
|
167 |
+
image,
|
168 |
+
model_name,
|
169 |
+
seed,
|
170 |
+
randomize_seed,
|
171 |
+
width,
|
172 |
+
height,
|
173 |
+
guidance_scale,
|
174 |
+
num_inference_steps,
|
175 |
+
lora_scale
|
176 |
+
):
|
177 |
+
# Step 1: Generate caption from the uploaded image
|
178 |
+
caption = caption_image(image, model_name)
|
179 |
+
|
180 |
+
# Step 2: Append "ghibli style" to the caption
|
181 |
+
ghibli_prompt = f"{caption}, ghibli style"
|
182 |
+
|
183 |
+
# Step 3: Generate Ghibli-style image based on the caption
|
184 |
+
generated_image, used_seed = inference(
|
185 |
+
prompt=ghibli_prompt,
|
186 |
+
seed=seed,
|
187 |
+
randomize_seed=randomize_seed,
|
188 |
+
width=width,
|
189 |
+
height=height,
|
190 |
+
guidance_scale=guidance_scale,
|
191 |
+
num_inference_steps=num_inference_steps,
|
192 |
+
lora_scale=lora_scale
|
193 |
+
)
|
194 |
+
|
195 |
+
return generated_image, used_seed, caption, ghibli_prompt
|
196 |
+
|
197 |
# ----------------------------- Gradio UI --------------------------------------
|
198 |
with gr.Blocks(analytics_enabled=False) as demo:
|
199 |
with gr.Tabs():
|
|
|
297 |
inputs=[input_img, model_selector],
|
298 |
outputs=[caption_output]
|
299 |
)
|
300 |
+
|
301 |
+
# ------------------ NEW TAB 3: Image to Ghibli Style ---------------------------
|
302 |
+
with gr.TabItem("이미지 to 지브리 스타일"):
|
303 |
+
gr.Markdown("## Upload an image and transform it to Ghibli style")
|
304 |
+
|
305 |
+
with gr.Row():
|
306 |
+
with gr.Column():
|
307 |
+
upload_img = gr.Image(label="Upload an Image")
|
308 |
+
caption_model_selector = gr.Dropdown(
|
309 |
+
choices=list(models.keys()),
|
310 |
+
value='gokaygokay/Florence-2-Flux-Large',
|
311 |
+
label="Caption Model",
|
312 |
+
visible=False # Hidden as requested
|
313 |
+
)
|
314 |
+
with gr.Row():
|
315 |
+
img2img_seed = gr.Slider(
|
316 |
+
label="Seed",
|
317 |
+
minimum=0,
|
318 |
+
maximum=MAX_SEED,
|
319 |
+
step=1,
|
320 |
+
value=42
|
321 |
+
)
|
322 |
+
img2img_randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
323 |
+
with gr.Row():
|
324 |
+
img2img_width = gr.Slider(
|
325 |
+
label="Width",
|
326 |
+
minimum=256,
|
327 |
+
maximum=MAX_IMAGE_SIZE,
|
328 |
+
step=32,
|
329 |
+
value=512
|
330 |
+
)
|
331 |
+
img2img_height = gr.Slider(
|
332 |
+
label="Height",
|
333 |
+
minimum=256,
|
334 |
+
maximum=MAX_IMAGE_SIZE,
|
335 |
+
step=32,
|
336 |
+
value=512
|
337 |
+
)
|
338 |
+
with gr.Row():
|
339 |
+
img2img_guidance_scale = gr.Slider(
|
340 |
+
label="Guidance scale",
|
341 |
+
minimum=0.0,
|
342 |
+
maximum=10.0,
|
343 |
+
step=0.1,
|
344 |
+
value=3.5
|
345 |
+
)
|
346 |
+
img2img_steps = gr.Slider(
|
347 |
+
label="Steps",
|
348 |
+
minimum=1,
|
349 |
+
maximum=50,
|
350 |
+
step=1,
|
351 |
+
value=30
|
352 |
+
)
|
353 |
+
img2img_lora_scale = gr.Slider(
|
354 |
+
label="LoRA scale",
|
355 |
+
minimum=0.0,
|
356 |
+
maximum=1.0,
|
357 |
+
step=0.1,
|
358 |
+
value=1.0
|
359 |
+
)
|
360 |
+
transform_button = gr.Button("Transform to Ghibli Style")
|
361 |
+
|
362 |
+
with gr.Column():
|
363 |
+
ghibli_output_image = gr.Image(label="Generated Ghibli Image")
|
364 |
+
ghibli_output_seed = gr.Number(label="Seed Used")
|
365 |
+
extracted_caption = gr.Textbox(
|
366 |
+
label="Extracted Description",
|
367 |
+
visible=False # Hidden as requested
|
368 |
+
)
|
369 |
+
ghibli_prompt = gr.Textbox(
|
370 |
+
label="Generated Prompt",
|
371 |
+
visible=False # Hidden as requested
|
372 |
+
)
|
373 |
|
374 |
+
# Auto-process when image is uploaded
|
375 |
+
upload_img.upload(
|
376 |
+
process_uploaded_image,
|
377 |
+
inputs=[
|
378 |
+
upload_img,
|
379 |
+
caption_model_selector,
|
380 |
+
img2img_seed,
|
381 |
+
img2img_randomize_seed,
|
382 |
+
img2img_width,
|
383 |
+
img2img_height,
|
384 |
+
img2img_guidance_scale,
|
385 |
+
img2img_steps,
|
386 |
+
img2img_lora_scale,
|
387 |
+
],
|
388 |
+
outputs=[
|
389 |
+
ghibli_output_image,
|
390 |
+
ghibli_output_seed,
|
391 |
+
extracted_caption,
|
392 |
+
ghibli_prompt,
|
393 |
+
]
|
394 |
+
)
|
395 |
+
|
396 |
+
# Manual process button
|
397 |
+
transform_button.click(
|
398 |
+
process_uploaded_image,
|
399 |
+
inputs=[
|
400 |
+
upload_img,
|
401 |
+
caption_model_selector,
|
402 |
+
img2img_seed,
|
403 |
+
img2img_randomize_seed,
|
404 |
+
img2img_width,
|
405 |
+
img2img_height,
|
406 |
+
img2img_guidance_scale,
|
407 |
+
img2img_steps,
|
408 |
+
img2img_lora_scale,
|
409 |
+
],
|
410 |
+
outputs=[
|
411 |
+
ghibli_output_image,
|
412 |
+
ghibli_output_seed,
|
413 |
+
extracted_caption,
|
414 |
+
ghibli_prompt,
|
415 |
+
]
|
416 |
+
)
|
417 |
|
418 |
+
demo.launch(debug=True)
|