Spaces:
Sleeping
Sleeping
Commit ·
cdedd76
1
Parent(s): 70dc6b0
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import os
|
|
| 5 |
|
| 6 |
MODEL = "Qwen/Qwen-Image-Edit-2511"
|
| 7 |
PROVIDER = "fal-ai"
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def image_to_data_uri(image_path):
|
|
@@ -15,13 +16,14 @@ def image_to_data_uri(image_path):
|
|
| 15 |
return f"data:{mime};base64,{data}"
|
| 16 |
|
| 17 |
|
| 18 |
-
def edit_images(
|
|
|
|
| 19 |
if not token:
|
| 20 |
raise gr.Error("Please sign in with your Hugging Face account first.")
|
| 21 |
if not prompt or prompt.strip() == "":
|
| 22 |
raise gr.Error("Please enter a prompt.")
|
| 23 |
|
| 24 |
-
images = [img for img in
|
| 25 |
if len(images) == 0:
|
| 26 |
raise gr.Error("Please upload at least one image.")
|
| 27 |
|
|
@@ -39,6 +41,14 @@ def edit_images(img1, img2, img3, prompt, token: gr.OAuthToken | None = None):
|
|
| 39 |
return result
|
| 40 |
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
with gr.Blocks(fill_height=True) as demo:
|
| 43 |
with gr.Sidebar():
|
| 44 |
gr.Markdown("# Qwen Image Edit")
|
|
@@ -49,11 +59,19 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 49 |
login_btn = gr.LoginButton("Sign in with Hugging Face")
|
| 50 |
|
| 51 |
with gr.Row():
|
| 52 |
-
with gr.Column():
|
| 53 |
with gr.Row():
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
prompt = gr.Textbox(
|
| 58 |
label="Edit Prompt",
|
| 59 |
placeholder="Describe how you want the image(s) edited...",
|
|
@@ -61,12 +79,26 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 61 |
)
|
| 62 |
submit_btn = gr.Button("Edit", variant="primary")
|
| 63 |
|
| 64 |
-
with gr.Column():
|
| 65 |
-
output_image = gr.Image(label="Result", type="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
|
|
|
| 67 |
submit_btn.click(
|
| 68 |
fn=edit_images,
|
| 69 |
-
inputs=[
|
| 70 |
outputs=[output_image],
|
| 71 |
)
|
| 72 |
|
|
|
|
| 5 |
|
| 6 |
MODEL = "Qwen/Qwen-Image-Edit-2511"
|
| 7 |
PROVIDER = "fal-ai"
|
| 8 |
+
NUM_IMAGES = 5
|
| 9 |
|
| 10 |
|
| 11 |
def image_to_data_uri(image_path):
|
|
|
|
| 16 |
return f"data:{mime};base64,{data}"
|
| 17 |
|
| 18 |
|
| 19 |
+
def edit_images(*args):
|
| 20 |
+
*imgs, prompt, token = args
|
| 21 |
if not token:
|
| 22 |
raise gr.Error("Please sign in with your Hugging Face account first.")
|
| 23 |
if not prompt or prompt.strip() == "":
|
| 24 |
raise gr.Error("Please enter a prompt.")
|
| 25 |
|
| 26 |
+
images = [img for img in imgs if img is not None]
|
| 27 |
if len(images) == 0:
|
| 28 |
raise gr.Error("Please upload at least one image.")
|
| 29 |
|
|
|
|
| 41 |
return result
|
| 42 |
|
| 43 |
|
| 44 |
+
def swap(a, b):
|
| 45 |
+
return b, a
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def send_to(output_img):
|
| 49 |
+
return output_img
|
| 50 |
+
|
| 51 |
+
|
| 52 |
with gr.Blocks(fill_height=True) as demo:
|
| 53 |
with gr.Sidebar():
|
| 54 |
gr.Markdown("# Qwen Image Edit")
|
|
|
|
| 59 |
login_btn = gr.LoginButton("Sign in with Hugging Face")
|
| 60 |
|
| 61 |
with gr.Row():
|
| 62 |
+
with gr.Column(scale=3):
|
| 63 |
with gr.Row():
|
| 64 |
+
img = [
|
| 65 |
+
gr.Image(
|
| 66 |
+
label=f"Image {i+1}" if i == 0 else f"Image {i+1} (optional)",
|
| 67 |
+
type="filepath",
|
| 68 |
+
)
|
| 69 |
+
for i in range(NUM_IMAGES)
|
| 70 |
+
]
|
| 71 |
+
with gr.Row():
|
| 72 |
+
swap_btns = []
|
| 73 |
+
for i in range(NUM_IMAGES - 1):
|
| 74 |
+
swap_btns.append(gr.Button(f"{i+1} ↔ {i+2}", size="sm"))
|
| 75 |
prompt = gr.Textbox(
|
| 76 |
label="Edit Prompt",
|
| 77 |
placeholder="Describe how you want the image(s) edited...",
|
|
|
|
| 79 |
)
|
| 80 |
submit_btn = gr.Button("Edit", variant="primary")
|
| 81 |
|
| 82 |
+
with gr.Column(scale=2):
|
| 83 |
+
output_image = gr.Image(label="Result", type="filepath")
|
| 84 |
+
gr.Markdown("**Send result to input:**")
|
| 85 |
+
with gr.Row():
|
| 86 |
+
to_btns = [
|
| 87 |
+
gr.Button(f"→ {i+1}", size="sm") for i in range(NUM_IMAGES)
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
# Swap buttons
|
| 91 |
+
for idx, btn in enumerate(swap_btns):
|
| 92 |
+
btn.click(fn=swap, inputs=[img[idx], img[idx + 1]], outputs=[img[idx], img[idx + 1]])
|
| 93 |
+
|
| 94 |
+
# Send output to input
|
| 95 |
+
for idx, btn in enumerate(to_btns):
|
| 96 |
+
btn.click(fn=send_to, inputs=[output_image], outputs=[img[idx]])
|
| 97 |
|
| 98 |
+
# Edit
|
| 99 |
submit_btn.click(
|
| 100 |
fn=edit_images,
|
| 101 |
+
inputs=[*img, prompt],
|
| 102 |
outputs=[output_image],
|
| 103 |
)
|
| 104 |
|