Cicici1109 commited on
Commit
5fb32e4
ยท
verified ยท
1 Parent(s): f965c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -19,17 +19,18 @@ def process_image(api_key, seed, image, prompt):
19
  input_path = f"input_{image_id}.png"
20
  image.save(input_path)
21
 
 
 
 
22
  try:
23
  uri = encode_image_to_datauri(input_path)
24
  categories, instructions = cot_with_gpt(uri, prompt)
25
- # categories = ['Tone Transfer', 'Style Change']
26
- # instructions = ['Change the time to night', 'Change the style to watercolor']
27
 
28
  if not categories or not instructions:
29
  raise gr.Error("No editing steps returned by GPT. Try a more specific instruction.")
30
 
31
- intermediate_images = []
32
- current_image_path = input_path
33
 
34
  for i, (category, instruction) in enumerate(zip(categories, instructions)):
35
  print(f"[Step {i}] Category: {category} | Instruction: {instruction}")
@@ -67,9 +68,8 @@ def process_image(api_key, seed, image, prompt):
67
  current_image_path = f"{step_prefix}.png"
68
  edited_image.save(current_image_path)
69
  intermediate_images.append(edited_image.copy())
70
-
71
- final_result = intermediate_images[-1] if intermediate_images else image
72
- return intermediate_images, final_result
73
 
74
  except Exception as e:
75
  raise gr.Error(f"Processing failed: {str(e)}")
@@ -77,7 +77,7 @@ def process_image(api_key, seed, image, prompt):
77
 
78
  # Gradio UI
79
  with gr.Blocks() as demo:
80
- gr.Markdown("## ๐Ÿ–ผ๏ธ IEAP: Image Editing As Programs")
81
 
82
  with gr.Row():
83
  api_key_input = gr.Textbox(label="๐Ÿ”‘ OpenAI API Key", type="password", placeholder="sk-...")
@@ -108,5 +108,4 @@ with gr.Blocks() as demo:
108
  )
109
 
110
  if __name__ == "__main__":
111
- demo.launch(
112
- )
 
19
  input_path = f"input_{image_id}.png"
20
  image.save(input_path)
21
 
22
+ intermediate_images = []
23
+ current_image_path = input_path
24
+
25
  try:
26
  uri = encode_image_to_datauri(input_path)
27
  categories, instructions = cot_with_gpt(uri, prompt)
 
 
28
 
29
  if not categories or not instructions:
30
  raise gr.Error("No editing steps returned by GPT. Try a more specific instruction.")
31
 
32
+ intermediate_images.append(image)
33
+ yield intermediate_images, image
34
 
35
  for i, (category, instruction) in enumerate(zip(categories, instructions)):
36
  print(f"[Step {i}] Category: {category} | Instruction: {instruction}")
 
68
  current_image_path = f"{step_prefix}.png"
69
  edited_image.save(current_image_path)
70
  intermediate_images.append(edited_image.copy())
71
+
72
+ yield intermediate_images, edited_image
 
73
 
74
  except Exception as e:
75
  raise gr.Error(f"Processing failed: {str(e)}")
 
77
 
78
  # Gradio UI
79
  with gr.Blocks() as demo:
80
+ gr.Markdown("## ๐Ÿ–ผ๏ธ IEAP: Image Editing As Programs (Streaming Version)")
81
 
82
  with gr.Row():
83
  api_key_input = gr.Textbox(label="๐Ÿ”‘ OpenAI API Key", type="password", placeholder="sk-...")
 
108
  )
109
 
110
  if __name__ == "__main__":
111
+ demo.launch()