m7mdal7aj commited on
Commit
1eb130f
1 Parent(s): 0fe1170

Update my_model/utilities/st_utils.py

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