Spaces:
Sleeping
Sleeping
Alexandros Popov
commited on
Commit
·
94bbb76
1
Parent(s):
95e7fc9
wip gallery function.
Browse files
app.py
CHANGED
|
@@ -10,33 +10,27 @@ from agents import run_photo_enchancement_agent
|
|
| 10 |
|
| 11 |
|
| 12 |
def process_image_with_agents(image: Image.Image, prompt: str):
|
| 13 |
-
"""Stream intermediate steps **and** the agent's stdout / stderr logs."""
|
| 14 |
-
# 🔧 1. Create temp dir & paths
|
| 15 |
temp_dir = tempfile.mkdtemp(prefix="gradio_aiart_")
|
| 16 |
input_path = os.path.join(temp_dir, "input.jpg")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# 💾 2. Persist original upload
|
| 20 |
image.save(input_path)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
yield image, "Original image uploaded. Starting enhancement…"
|
| 24 |
|
| 25 |
-
# 📝 4. Capture logs while the agent runs
|
| 26 |
log_buffer = io.StringIO()
|
| 27 |
with contextlib.redirect_stdout(log_buffer), contextlib.redirect_stderr(log_buffer):
|
| 28 |
_ = run_photo_enchancement_agent(
|
| 29 |
prompt,
|
| 30 |
image_path=input_path,
|
| 31 |
-
|
| 32 |
)
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
yield final_image, f"✅ Enhancement finished.\n\n--- Agent Logs ---\n{logs}"
|
| 40 |
|
| 41 |
|
| 42 |
with gr.Blocks(title="AI Art Director • Agent Workflow") as demo:
|
|
@@ -53,16 +47,15 @@ with gr.Blocks(title="AI Art Director • Agent Workflow") as demo:
|
|
| 53 |
prompt_input = gr.Textbox(label="Describe the vibe you want", placeholder="e.g. dreamy, vintage, vibrant…")
|
| 54 |
submit_btn = gr.Button("Go!")
|
| 55 |
with gr.Column():
|
| 56 |
-
|
| 57 |
agent_logs = gr.Textbox(label="Agent Logs", lines=18, interactive=False)
|
| 58 |
|
| 59 |
submit_btn.click(
|
| 60 |
process_image_with_agents,
|
| 61 |
inputs=[image_input, prompt_input],
|
| 62 |
-
outputs=[
|
| 63 |
)
|
| 64 |
|
| 65 |
-
# Allow multiple users to queue without blocking streaming
|
| 66 |
demo.queue()
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def process_image_with_agents(image: Image.Image, prompt: str):
|
|
|
|
|
|
|
| 13 |
temp_dir = tempfile.mkdtemp(prefix="gradio_aiart_")
|
| 14 |
input_path = os.path.join(temp_dir, "input.jpg")
|
| 15 |
+
output_directory = temp_dir
|
|
|
|
|
|
|
| 16 |
image.save(input_path)
|
| 17 |
|
| 18 |
+
yield [image], "Original image uploaded. Starting enhancement…"
|
|
|
|
| 19 |
|
|
|
|
| 20 |
log_buffer = io.StringIO()
|
| 21 |
with contextlib.redirect_stdout(log_buffer), contextlib.redirect_stderr(log_buffer):
|
| 22 |
_ = run_photo_enchancement_agent(
|
| 23 |
prompt,
|
| 24 |
image_path=input_path,
|
| 25 |
+
output_directory=output_directory,
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Find all images in temp_dir (sorted by name)
|
| 29 |
+
image_files = sorted([os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith((".jpg", ".png"))])
|
| 30 |
+
images = [Image.open(p) for p in image_files]
|
| 31 |
|
| 32 |
+
logs = log_buffer.getvalue()
|
| 33 |
+
yield images, f"✅ Enhancement finished.\n\n--- Agent Logs ---\n{logs}"
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
with gr.Blocks(title="AI Art Director • Agent Workflow") as demo:
|
|
|
|
| 47 |
prompt_input = gr.Textbox(label="Describe the vibe you want", placeholder="e.g. dreamy, vintage, vibrant…")
|
| 48 |
submit_btn = gr.Button("Go!")
|
| 49 |
with gr.Column():
|
| 50 |
+
gallery = gr.Gallery(label="Image Progress", show_label=True)
|
| 51 |
agent_logs = gr.Textbox(label="Agent Logs", lines=18, interactive=False)
|
| 52 |
|
| 53 |
submit_btn.click(
|
| 54 |
process_image_with_agents,
|
| 55 |
inputs=[image_input, prompt_input],
|
| 56 |
+
outputs=[gallery, agent_logs],
|
| 57 |
)
|
| 58 |
|
|
|
|
| 59 |
demo.queue()
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|