K00B404 commited on
Commit
7205bda
1 Parent(s): a7a64f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -24
app.py CHANGED
@@ -216,30 +216,7 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
216
  print(f"Error when trying to open the image: {e}")
217
  return None, None, None
218
 
219
- js_code = """
220
- <script>
221
- document.addEventListener("DOMContentLoaded", function() {
222
- const accordion = document.querySelector('.gr.Accordion'); // Adjust selector based on accordion class
223
- const container = document.querySelector('.gradio-container');
224
-
225
- function adjustBackground() {
226
- if (accordion && accordion.hasAttribute('open')) {
227
- container.style.backgroundSize = '900px 2100px'; // When accordion is open
228
- } else {
229
- container.style.backgroundSize = '900px 880px'; // When accordion is closed
230
- }
231
- }
232
 
233
- // Attach event listener to the accordion toggle
234
- accordion.addEventListener('click', function() {
235
- setTimeout(adjustBackground, 100); // Delay to allow accordion to fully open/close
236
- });
237
-
238
- // Initial background size based on initial state
239
- adjustBackground();
240
- });
241
- </script>
242
- """
243
 
244
  title_html="""
245
  <center>
@@ -318,9 +295,36 @@ css = """
318
 
319
 
320
  with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
  gr.HTML(title_html) # title html
323
- gr.HTML(js_code) # Embed the JavaScript in the Gradio app
324
  with gr.Column(elem_id="app-container"):
325
  with gr.Row():
326
  with gr.Column(elem_id="prompt-container"):
 
216
  print(f"Error when trying to open the image: {e}")
217
  return None, None, None
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  title_html="""
222
  <center>
 
295
 
296
 
297
  with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
298
+
299
+ app.load("""
300
+ const accordion = document.querySelector('.gradio-accordion');
301
+ const container = document.querySelector('.gradio-container');
302
+
303
+ function adjustBackground() {
304
+ if (accordion && accordion.classList.contains('open')) {
305
+ container.style.backgroundSize = '900px 2100px'; // When accordion is open
306
+ } else {
307
+ container.style.backgroundSize = '900px 880px'; // When accordion is closed
308
+ }
309
+ }
310
+
311
+ // Initial background size based on initial state
312
+ adjustBackground();
313
+
314
+ // Use MutationObserver to watch for changes in the accordion's class
315
+ const observer = new MutationObserver((mutations) => {
316
+ mutations.forEach((mutation) => {
317
+ if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
318
+ adjustBackground();
319
+ }
320
+ });
321
+ });
322
+
323
+ observer.observe(accordion, { attributes: true });
324
+ """)
325
 
326
  gr.HTML(title_html) # title html
327
+
328
  with gr.Column(elem_id="app-container"):
329
  with gr.Row():
330
  with gr.Column(elem_id="prompt-container"):