Spaces:
Running
Running
Update app.py
Browse files
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,
|
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,
|
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(
|
|
|
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 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
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())
|