File size: 1,688 Bytes
964bace
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e72752e
964bace
 
 
 
e72752e
964bace
e72752e
964bace
 
 
 
 
 
 
 
 
 
 
 
e72752e
 
964bace
 
 
 
 
64a5374
964bace
 
 
 
e72752e
964bace
 
 
 
 
 
e72752e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import gradio as gr
from PIL import Image

# Paths for predefined dipole images
BASE_PATH = "demo_images"
IMAGES_DIR = os.path.join(BASE_PATH, "paths_images")
ORIGINAL_IMAGE = os.path.join(BASE_PATH, "original_image.jpg")

# Predefined dipole options based on folder structure
dipole_options = sorted(
    [f"Path {i}" for i in range(len(os.listdir(IMAGES_DIR)))]
)

# Display edited images based on user-selected dipole and slider strength
def edit_image(attribute: str, slider_value: int):
    index = dipole_options.index(attribute)
    image_dir = os.path.join(IMAGES_DIR, f"path_{index:03d}")

    # Determine frame from slider value
    frame_path = os.path.join(image_dir, f"{slider_value:06d}.jpg")

    # Load and return the image
    frame_image = Image.open(frame_path)
    return frame_image

# Display the original image
def display_original_image():
    return Image.open(ORIGINAL_IMAGE)

# Gradio Interface
def build_interface():
    with gr.Row():
        gr.Markdown("# ContraCLIP Predefined Editing Demo")

    with gr.Row():
        gr.Image(display_original_image(), label="Original Image", type="pil")

    demo = gr.Interface(
        fn=edit_image,
        inputs=[
            gr.Dropdown(dipole_options, label="Select Attribute"),
            gr.Slider(0, 32, step=1, label="Frame Index"),  # Adjust slider range based on actual frames
        ],
        outputs=gr.Image(type="pil"),
        live=True,
        title="Predefined ContraCLIP Image Editing",
        description="Select an attribute and adjust the frame index to view the edited image."
    )

    # Launch the Interface
    demo.launch()

if __name__ == "__main__":
    build_interface()