Spaces:
Building
Building
File size: 1,877 Bytes
1eb130f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import streamlit as st
class StateManager:
def __init__(self):
self.reset_state()
def reset_state(self):
"""Resets the state to its initial values."""
self.current_image = None
self.qa_history = []
self.analysis_done = False
self.answer_in_progress = False
self.caption = ""
self.detected_objects_str = ""
def set_current_image(self, image):
"""Sets the current image and resets relevant state variables."""
try:
self.current_image = image
self.qa_history = []
self.analysis_done = False
self.answer_in_progress = False
self.caption = ""
self.detected_objects_str = ""
except Exception as e:
print(f"Error setting current image: {e}")
def add_to_qa_history(self, question, answer):
"""Adds a question-answer pair to the history."""
if question and answer:
self.qa_history.append((question, answer))
else:
print("Invalid question or answer. Cannot add to history.")
def set_analysis_done(self, status=True):
"""Sets the analysis status."""
self.analysis_done = status
def set_answer_in_progress(self, status=True):
"""Sets the answer in progress status."""
self.answer_in_progress = status
def set_caption(self, caption):
"""Sets the image caption."""
if caption:
self.caption = caption
else:
print("Invalid caption. Cannot set caption.")
def set_detected_objects_str(self, detected_objects_str):
"""Sets the detected objects string."""
if detected_objects_str:
self.detected_objects_str = detected_objects_str
else:
print("Invalid detected objects string. Cannot set detected objects.")
|