Uthar commited on
Commit
9f8e032
·
verified ·
1 Parent(s): 8927873

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -113,6 +113,31 @@ def add_gallery(image, model_str, gallery):
113
  if image is not None: gallery.insert(0, (image, model_str))
114
  return gallery
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  js="""
117
  <script>console.log("BOOOOOOOOOOOOOOOOBS");</script>
118
  """
@@ -128,12 +153,7 @@ css="""
128
  }
129
  """
130
 
131
- def toggle_button(butState):
132
- if butState == "Running":
133
- return "Off", gr.Button(variant="secondary", value="Off", elem_classes=["off"])
134
- else:
135
- return "Running", gr.Button(variant="primary", value="Running", elem_classes=["Running"])
136
-
137
 
138
  with gr.Blocks(fill_width=True, head=js, css=css) as demo:
139
  with gr.Tab(str(num_models) + ' Models'):
@@ -227,4 +247,6 @@ with gr.Blocks(fill_width=True, head=js, css=css) as demo:
227
  concurrency_limit=None, queue=False)
228
  o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
229
 
 
 
230
  demo.launch(show_api=False, max_threads=400)
 
113
  if image is not None: gallery.insert(0, (image, model_str))
114
  return gallery
115
 
116
+ button_state=False
117
+
118
+ async def buttonChecker():
119
+ """Continuously check the button state and perform an action."""
120
+ while True:
121
+ if button_state:
122
+ print("Button is ON - Triggering Event")
123
+ # Here, you can define what happens when the button is ON.
124
+ await asyncio.sleep(1) # Check every second
125
+
126
+ def start_event_loop():
127
+ """Start the event loop for the asynchronous task."""
128
+ asyncio.create_task(buttonChecker())
129
+
130
+ def toggle_button(butState):
131
+ global button_state
132
+ if butState == "Running":
133
+ button_state=False
134
+ return "Off", gr.Button(variant="secondary", value="Off", elem_classes=["off"])
135
+ else:
136
+ button_state=True
137
+ return "Running", gr.Button(variant="primary", value="Running", elem_classes=["Running"])
138
+
139
+
140
+
141
  js="""
142
  <script>console.log("BOOOOOOOOOOOOOOOOBS");</script>
143
  """
 
153
  }
154
  """
155
 
156
+
 
 
 
 
 
157
 
158
  with gr.Blocks(fill_width=True, head=js, css=css) as demo:
159
  with gr.Tab(str(num_models) + ' Models'):
 
247
  concurrency_limit=None, queue=False)
248
  o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
249
 
250
+ demo.load(start_event_loop)
251
+
252
  demo.launch(show_api=False, max_threads=400)