Alexandros Popov commited on
Commit
94bbb76
·
1 Parent(s): 95e7fc9

wip gallery function.

Browse files
Files changed (1) hide show
  1. app.py +10 -17
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
- output_path = os.path.join(temp_dir, "output.jpg")
18
-
19
- # 💾 2. Persist original upload
20
  image.save(input_path)
21
 
22
- # 🖼️ 3. Yield the original image immediately
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
- output_path=output_path,
32
  )
33
 
34
- # 🧾 All logs produced by the agent
35
- logs = log_buffer.getvalue()
 
36
 
37
- # 🖼️ 5. Yield the final image plus the complete logs
38
- final_image = Image.open(output_path)
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
- streamed_image = gr.Image(label="Image Progress")
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=[streamed_image, agent_logs],
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__":