File size: 1,925 Bytes
90a367f
 
 
5406cd8
90a367f
 
 
 
 
5fa4073
90a367f
 
94bbb76
90a367f
 
94bbb76
90a367f
9b232e0
 
 
 
 
90a367f
1434c10
99bc28a
1434c10
b4bce46
6894106
1434c10
6894106
5406cd8
5fa4073
90a367f
5fa4073
 
1434c10
 
 
90a367f
5fa4073
90a367f
 
 
5fa4073
90a367f
 
94bbb76
1434c10
6894106
90a367f
 
 
1434c10
90a367f
5406cd8
5fa4073
 
5406cd8
6894106
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
56
57
58
59
60
import os
import tempfile

import gradio as gr
from PIL import Image

from agents import run_photo_enchancement_agent


def process_image_with_agents(image: Image.Image, prompt: str):
    temp_dir = tempfile.mkdtemp(prefix="gradio_aiart_")
    input_path = os.path.join(temp_dir, "input.jpg")
    output_directory = temp_dir
    image.save(input_path)

    yield [image], "Original image uploaded. Starting enhancement…"

    run_photo_enchancement_agent(
        prompt,
        image_path=input_path,
        output_directory=output_directory,
    )

    image_files = sorted(
        [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".jpeg")], key=os.path.getmtime
    )
    images = [(Image.open(p), os.path.basename(p)) for p in image_files]

    yield images, "✅ Enhancement finished."


with gr.Blocks(title="AI Art Director • Agent Workflow") as demo:
    gr.Markdown(
        "# AI Art Director\n"
        "Upload an image and describe the vibe you want.\n"
        "The agent will propose, apply, and critique edits to match your vision.\n"
        "🕒 Disclaimer: The agent takes a LONG time (around 10 minutes).\n"
        "📜 You can follow the activity through logs."
    )

    with gr.Row():
        with gr.Column():
            image_input = gr.Image(type="pil", label="Upload Image")
            prompt_input = gr.Textbox(label="Describe the vibe you want", placeholder="e.g. dreamy, vintage, vibrant…")
            submit_btn = gr.Button("Go!")
        with gr.Column():
            gallery = gr.Gallery(label="Image Progress", show_label=True)
            status_box = gr.Textbox(label="Status", lines=2, interactive=False)

    submit_btn.click(
        process_image_with_agents,
        inputs=[image_input, prompt_input],
        outputs=[gallery, status_box],  # ✅ Fixed: include both outputs
    )

    demo.queue()

if __name__ == "__main__":
    demo.launch()