Spaces:
Sleeping
Sleeping
| class Memory: | |
| """ | |
| Stores conversation history and image context for one user session. | |
| """ | |
| def __init__(self): | |
| # Conversation | |
| self.chat_history = [] | |
| # Uploaded image paths | |
| self.uploaded_files = [] | |
| # Current working image | |
| self.current_image = None | |
| # Latest edited image | |
| self.last_used_image = None | |
| # Full image analysis | |
| self.analysis = None | |
| # Natural language description | |
| self.image_context = "" | |
| # ===================================================== | |
| # CHAT | |
| # ===================================================== | |
| def add_message(self, role, content): | |
| self.chat_history.append({ | |
| "role": role, | |
| "content": content | |
| }) | |
| def get_history(self): | |
| return self.chat_history | |
| # ===================================================== | |
| # FILES | |
| # ===================================================== | |
| def add_files(self, files): | |
| self.uploaded_files = files | |
| if files: | |
| self.current_image = files[0] | |
| self.last_used_image = files[0] | |
| def get_files(self): | |
| return self.uploaded_files | |
| # ===================================================== | |
| # IMAGE | |
| # ===================================================== | |
| def set_current_image(self, image_path): | |
| self.current_image = image_path | |
| def get_current_image(self): | |
| return self.current_image | |
| def set_last_image(self, image_path): | |
| self.last_used_image = image_path | |
| self.current_image = image_path | |
| def get_last_image(self): | |
| return self.last_used_image | |
| # ===================================================== | |
| # ANALYSIS | |
| # ===================================================== | |
| def set_analysis(self, analysis): | |
| self.analysis = analysis | |
| if isinstance(analysis, dict): | |
| self.image_context = analysis.get( | |
| "description", | |
| "" | |
| ) | |
| def get_analysis(self): | |
| return self.analysis | |
| def get_image_context(self): | |
| return self.image_context | |
| # ===================================================== | |
| # CLEAR | |
| # ===================================================== | |
| def clear(self): | |
| self.chat_history = [] | |
| self.uploaded_files = [] | |
| self.current_image = None | |
| self.last_used_image = None | |
| self.analysis = None | |
| self.image_context = "" |