Spaces:
Sleeping
Sleeping
| class Memory: | |
| def __init__(self): | |
| # Conversation history | |
| self.chat_history = [] | |
| # Uploaded files | |
| self.uploaded_files = [] | |
| # Current image (original or latest edited) | |
| self.last_used_image = None | |
| # Full analysis dictionary | |
| self.image_context = None | |
| # Current analysis | |
| self.analysis = None | |
| # -------------------------- | |
| # Chat History | |
| # -------------------------- | |
| def add_message(self, role, content): | |
| self.chat_history.append({ | |
| "role": role, | |
| "content": content | |
| }) | |
| def get_history(self): | |
| return self.chat_history | |
| # -------------------------- | |
| # Uploaded Files | |
| # -------------------------- | |
| def add_files(self, files): | |
| self.uploaded_files.extend(files) | |
| # -------------------------- | |
| # Image Context | |
| # -------------------------- | |
| def set_image_context(self, analysis): | |
| """ | |
| Store the complete image analysis. | |
| """ | |
| self.image_context = analysis | |
| self.analysis = analysis | |
| def get_image_context(self): | |
| return self.image_context | |
| # -------------------------- | |
| # Current Image | |
| # -------------------------- | |
| def set_last_image(self, image_path): | |
| self.last_used_image = image_path | |
| def get_last_image(self): | |
| return self.last_used_image | |
| # -------------------------- | |
| # Clear Memory | |
| # -------------------------- | |
| def clear(self): | |
| self.chat_history.clear() | |
| self.uploaded_files.clear() | |
| self.last_used_image = None | |
| self.image_context = None | |
| self.analysis = None |