ginipick commited on
Commit
fccd816
ยท
verified ยท
1 Parent(s): d012b58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -269,9 +269,10 @@ def create_ui():
269
  with gr.Column(scale=1):
270
  search_input = gr.Textbox(label="Search Spaces", placeholder="Enter search query...")
271
  space_list = gr.HTML()
 
272
 
273
- def update_space_list(query):
274
- filtered_spaces = search_spaces(query, formatted_spaces) if query else formatted_spaces
275
  html = "<div class='space-list'>"
276
  for i, space in enumerate(filtered_spaces):
277
  html += f"""
@@ -283,7 +284,7 @@ def create_ui():
283
  html += "</div>"
284
  return html, filtered_spaces
285
 
286
- search_input.change(update_space_list, inputs=[search_input], outputs=[space_list, gr.State()])
287
 
288
  with gr.Column(scale=2):
289
  with gr.Tabs():
@@ -313,7 +314,8 @@ def create_ui():
313
 
314
  update_trigger = gr.Button("Update Screenshot", visible=False)
315
 
316
- def on_select_with_link(space):
 
317
  info, app_content, url, tree, list_structure = on_select(space)
318
  info += f"\n\n์„ ํƒํ•œ Space URL: {url}"
319
  return info, app_content, url, tree, list_structure
@@ -353,27 +355,30 @@ def create_ui():
353
  outputs=[screenshot_output, last_url_state]
354
  )
355
 
356
- # JavaScript ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด js ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
357
- demo.load(js="""
358
- function selectSpace(index) {
359
- var spaces = document.querySelector('#space-list-state').textContent;
360
- var spaceData = JSON.parse(spaces)[index];
361
- gradioApp().querySelector('#info-output textarea').value = "๋กœ๋”ฉ ์ค‘...";
362
- gradioApp().querySelector('#app-py-content textarea').value = "๋กœ๋”ฉ ์ค‘...";
363
- gradioApp().querySelector('#tree-view textarea').value = "๋กœ๋”ฉ ์ค‘...";
364
- gradioApp().querySelector('#list-view textarea').value = "๋กœ๋”ฉ ์ค‘...";
365
-
366
- // Gradio ํ•จ์ˆ˜ ํ˜ธ์ถœ
367
- var onSelectWithLink = gradioApp().querySelector('gradio-app').shadowRoot.querySelector('#on_select_with_link');
368
- onSelectWithLink.props.action_fn(spaceData);
369
- }
370
- """)
 
 
 
 
 
 
371
 
372
  demo.queue()
373
 
374
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค์— Python ํ•จ์ˆ˜ ์—ฐ๊ฒฐ
375
- demo.load(on_select_with_link, inputs="state", outputs=[info_output, app_py_content, url_state, tree_view, list_view])
376
-
377
  # Start a background thread to trigger updates
378
  def trigger_updates():
379
  while True:
@@ -395,4 +400,4 @@ if __name__ == "__main__":
395
  demo.launch()
396
  except Exception as e:
397
  print(f"Error in main: {str(e)}")
398
- print(traceback.format_exc())
 
269
  with gr.Column(scale=1):
270
  search_input = gr.Textbox(label="Search Spaces", placeholder="Enter search query...")
271
  space_list = gr.HTML()
272
+ space_state = gr.State(formatted_spaces)
273
 
274
+ def update_space_list(query, spaces):
275
+ filtered_spaces = search_spaces(query, spaces) if query else spaces
276
  html = "<div class='space-list'>"
277
  for i, space in enumerate(filtered_spaces):
278
  html += f"""
 
284
  html += "</div>"
285
  return html, filtered_spaces
286
 
287
+ search_input.change(update_space_list, inputs=[search_input, space_state], outputs=[space_list, space_state])
288
 
289
  with gr.Column(scale=2):
290
  with gr.Tabs():
 
314
 
315
  update_trigger = gr.Button("Update Screenshot", visible=False)
316
 
317
+ def on_select_with_link(space_index, spaces):
318
+ space = spaces[space_index]
319
  info, app_content, url, tree, list_structure = on_select(space)
320
  info += f"\n\n์„ ํƒํ•œ Space URL: {url}"
321
  return info, app_content, url, tree, list_structure
 
355
  outputs=[screenshot_output, last_url_state]
356
  )
357
 
358
+ # JavaScript ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด js ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
359
+ demo.load(js="""
360
+ function selectSpace(index) {
361
+ document.querySelector('#space-index').value = index;
362
+ document.querySelector('#select-space-trigger').click();
363
+ }
364
+ """)
365
+
366
+ # Hidden elements for space selection
367
+ space_index = gr.Textbox(elem_id="space-index", visible=False)
368
+ select_space_trigger = gr.Button("Hidden Select Trigger", visible=False, elem_id="select-space-trigger")
369
+
370
+ select_space_trigger.click(
371
+ on_select_with_link,
372
+ inputs=[space_index, space_state],
373
+ outputs=[info_output, app_py_content, url_state, tree_view, list_view]
374
+ ).then(
375
+ update_screenshot,
376
+ inputs=[url_state, last_url_state],
377
+ outputs=[screenshot_output, last_url_state]
378
+ )
379
 
380
  demo.queue()
381
 
 
 
 
382
  # Start a background thread to trigger updates
383
  def trigger_updates():
384
  while True:
 
400
  demo.launch()
401
  except Exception as e:
402
  print(f"Error in main: {str(e)}")
403
+ print(traceback.format_exc())