Spaces:
Sleeping
Sleeping
Update agents/image_agent.py
#11
by Muthuraja18 - opened
- agents/image_agent.py +25 -12
agents/image_agent.py
CHANGED
|
@@ -16,6 +16,16 @@ class ImageAgent:
|
|
| 16 |
self.memory.add_files(paths)
|
| 17 |
return paths
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def run(self, user_input: str):
|
| 20 |
|
| 21 |
task = self.router.route(user_input)
|
|
@@ -23,27 +33,30 @@ class ImageAgent:
|
|
| 23 |
|
| 24 |
result = None
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
for step in steps:
|
| 27 |
|
| 28 |
if step == "generate":
|
| 29 |
result = generate_image(user_input)
|
| 30 |
|
| 31 |
elif step == "edit":
|
| 32 |
-
image = self.memory.
|
| 33 |
-
|
| 34 |
-
if not image and self.memory.uploaded_files:
|
| 35 |
-
image = self.memory.uploaded_files[0]
|
| 36 |
-
|
| 37 |
result = edit_image(image, user_input)
|
| 38 |
-
|
| 39 |
-
self.memory.set_last_image(result)
|
| 40 |
|
| 41 |
elif step == "analyze":
|
| 42 |
-
image = self.memory.
|
| 43 |
-
|
| 44 |
-
if not image:
|
| 45 |
-
image = self.memory.uploaded_files[0]
|
| 46 |
-
|
| 47 |
result = analyze_image(image)
|
| 48 |
|
| 49 |
return result
|
|
|
|
| 16 |
self.memory.add_files(paths)
|
| 17 |
return paths
|
| 18 |
|
| 19 |
+
def auto_analyze(self, image_path):
|
| 20 |
+
"""
|
| 21 |
+
STEP 1: Always understand image first
|
| 22 |
+
"""
|
| 23 |
+
if image_path:
|
| 24 |
+
analysis = analyze_image(image_path)
|
| 25 |
+
self.memory.last_used_image = image_path
|
| 26 |
+
return analysis
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
def run(self, user_input: str):
|
| 30 |
|
| 31 |
task = self.router.route(user_input)
|
|
|
|
| 33 |
|
| 34 |
result = None
|
| 35 |
|
| 36 |
+
# 🔥 STEP 0: ALWAYS pick image first
|
| 37 |
+
image = None
|
| 38 |
+
|
| 39 |
+
if self.memory.uploaded_files:
|
| 40 |
+
image = self.memory.uploaded_files[0]
|
| 41 |
+
|
| 42 |
+
# 🔥 STEP 1: ANALYZE FIRST (IMPORTANT)
|
| 43 |
+
if image:
|
| 44 |
+
analysis = self.auto_analyze(image)
|
| 45 |
+
self.memory.analysis = analysis
|
| 46 |
+
|
| 47 |
+
# 🔥 STEP 2: EXECUTE TASK
|
| 48 |
for step in steps:
|
| 49 |
|
| 50 |
if step == "generate":
|
| 51 |
result = generate_image(user_input)
|
| 52 |
|
| 53 |
elif step == "edit":
|
| 54 |
+
image = self.memory.last_used_image or image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
result = edit_image(image, user_input)
|
| 56 |
+
self.memory.last_used_image = image
|
|
|
|
| 57 |
|
| 58 |
elif step == "analyze":
|
| 59 |
+
image = self.memory.last_used_image or image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
result = analyze_image(image)
|
| 61 |
|
| 62 |
return result
|