Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ from PIL import Image
|
|
5 |
# Paths for predefined dipole images
|
6 |
BASE_PATH = "demo_images"
|
7 |
IMAGES_DIR = os.path.join(BASE_PATH, "paths_images")
|
8 |
-
STRIPS_DIR = os.path.join(BASE_PATH, "paths_strips")
|
9 |
ORIGINAL_IMAGE = os.path.join(BASE_PATH, "original_image.jpg")
|
10 |
|
11 |
# Predefined dipole options based on folder structure
|
@@ -14,15 +13,14 @@ dipole_options = sorted(
|
|
14 |
)
|
15 |
|
16 |
# Display edited images based on user-selected dipole and slider strength
|
17 |
-
def edit_image(attribute: str, slider_value:
|
18 |
index = dipole_options.index(attribute)
|
19 |
image_dir = os.path.join(IMAGES_DIR, f"path_{index:03d}")
|
20 |
|
21 |
# Determine frame from slider value
|
22 |
-
|
23 |
-
frame_index = int(slider_value * (num_frames - 1))
|
24 |
-
frame_path = os.path.join(image_dir, f"{frame_index:06d}.jpg")
|
25 |
|
|
|
26 |
frame_image = Image.open(frame_path)
|
27 |
return frame_image
|
28 |
|
@@ -35,25 +33,23 @@ def build_interface():
|
|
35 |
with gr.Row():
|
36 |
gr.Markdown("# ContraCLIP Predefined Editing Demo")
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
original_image_box.update(value=display_original_image())
|
41 |
|
42 |
-
# Demo Interface
|
43 |
demo = gr.Interface(
|
44 |
fn=edit_image,
|
45 |
inputs=[
|
46 |
gr.Dropdown(dipole_options, label="Select Attribute"),
|
47 |
-
gr.Slider(0,
|
48 |
],
|
49 |
outputs=gr.Image(type="pil"),
|
50 |
live=True,
|
51 |
title="Predefined ContraCLIP Image Editing",
|
52 |
-
description="Select an attribute and adjust
|
53 |
)
|
54 |
|
55 |
# Launch the Interface
|
56 |
demo.launch()
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
-
build_interface()
|
|
|
5 |
# Paths for predefined dipole images
|
6 |
BASE_PATH = "demo_images"
|
7 |
IMAGES_DIR = os.path.join(BASE_PATH, "paths_images")
|
|
|
8 |
ORIGINAL_IMAGE = os.path.join(BASE_PATH, "original_image.jpg")
|
9 |
|
10 |
# Predefined dipole options based on folder structure
|
|
|
13 |
)
|
14 |
|
15 |
# Display edited images based on user-selected dipole and slider strength
|
16 |
+
def edit_image(attribute: str, slider_value: int):
|
17 |
index = dipole_options.index(attribute)
|
18 |
image_dir = os.path.join(IMAGES_DIR, f"path_{index:03d}")
|
19 |
|
20 |
# Determine frame from slider value
|
21 |
+
frame_path = os.path.join(image_dir, f"{slider_value:06d}.jpg")
|
|
|
|
|
22 |
|
23 |
+
# Load and return the image
|
24 |
frame_image = Image.open(frame_path)
|
25 |
return frame_image
|
26 |
|
|
|
33 |
with gr.Row():
|
34 |
gr.Markdown("# ContraCLIP Predefined Editing Demo")
|
35 |
|
36 |
+
with gr.Row():
|
37 |
+
gr.Image(display_original_image(), label="Original Image", type="pil")
|
|
|
38 |
|
|
|
39 |
demo = gr.Interface(
|
40 |
fn=edit_image,
|
41 |
inputs=[
|
42 |
gr.Dropdown(dipole_options, label="Select Attribute"),
|
43 |
+
gr.Slider(0, 10, step=1, label="Frame Index"), # Adjust slider range based on actual frames
|
44 |
],
|
45 |
outputs=gr.Image(type="pil"),
|
46 |
live=True,
|
47 |
title="Predefined ContraCLIP Image Editing",
|
48 |
+
description="Select an attribute and adjust the frame index to view the edited image."
|
49 |
)
|
50 |
|
51 |
# Launch the Interface
|
52 |
demo.launch()
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
+
build_interface()
|