sandz7 commited on
Commit
3c218b1
Β·
verified Β·
1 Parent(s): c6a3b9e

set ModeManager class

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -56,6 +56,18 @@ refiner = DiffusionPipeline.from_pretrained(
56
  )
57
  refiner.to('cuda')
58
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def multimodal_and_generation(message, history):
60
  """
61
  Generates a response based on the input message and optionally an image.
@@ -127,7 +139,7 @@ def bot_comms(message, history):
127
  Handles communication between Gradio and the models.
128
  """
129
  # global mode
130
- mode = spaces.get("mode", default="")
131
  logger.debug(f"bot_comms called with message: {message} and mode: {mode}")
132
 
133
  if message == "check cuda":
@@ -137,13 +149,13 @@ def bot_comms(message, history):
137
 
138
  if message == "imagery":
139
  logger.debug("Switching to imagery mode.")
140
- spaces.set("mode", "imagery")
141
  yield "Imagery On! Type your prompt to make the image πŸ–ΌοΈ"
142
  return
143
 
144
  if message == "chatting":
145
  logger.debug("Switching to chatting mode.")
146
- spaces.set("mode", "chatting")
147
  yield "Imagery Off. Ask me any questions. β˜„οΈ"
148
  return
149
 
 
56
  )
57
  refiner.to('cuda')
58
 
59
+ class ModeManager:
60
+ def __init__(self):
61
+ self.mode = ""
62
+
63
+ def set_mode(self, mode):
64
+ self.mode = mode
65
+
66
+ def get_mode(self):
67
+ return self.mode
68
+
69
+ mode_manager = ModeManager()
70
+
71
  def multimodal_and_generation(message, history):
72
  """
73
  Generates a response based on the input message and optionally an image.
 
139
  Handles communication between Gradio and the models.
140
  """
141
  # global mode
142
+ mode = mode_manager.get_mode()
143
  logger.debug(f"bot_comms called with message: {message} and mode: {mode}")
144
 
145
  if message == "check cuda":
 
149
 
150
  if message == "imagery":
151
  logger.debug("Switching to imagery mode.")
152
+ mode_manager.set_mode("imagery")
153
  yield "Imagery On! Type your prompt to make the image πŸ–ΌοΈ"
154
  return
155
 
156
  if message == "chatting":
157
  logger.debug("Switching to chatting mode.")
158
+ mode_manager.set_mode("chatting")
159
  yield "Imagery Off. Ask me any questions. β˜„οΈ"
160
  return
161