Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -220,6 +220,8 @@ def search_spaces(query: str, spaces: List[Dict]) -> List[Dict]:
|
|
220 |
query in space.get('description', '').lower()
|
221 |
]
|
222 |
|
|
|
|
|
223 |
def create_ui():
|
224 |
try:
|
225 |
spaces_list = get_most_liked_spaces()
|
@@ -271,17 +273,17 @@ def create_ui():
|
|
271 |
def update_space_list(query):
|
272 |
filtered_spaces = search_spaces(query, formatted_spaces) if query else formatted_spaces
|
273 |
html = "<div class='space-list'>"
|
274 |
-
for space in filtered_spaces:
|
275 |
html += f"""
|
276 |
<div class='space-row'>
|
277 |
<span>{space['name']} by {space['author']} (Likes: {space['likes']})</span>
|
278 |
-
<button class='select-space'
|
279 |
</div>
|
280 |
"""
|
281 |
html += "</div>"
|
282 |
-
return html
|
283 |
|
284 |
-
search_input.change(update_space_list, inputs=[search_input], outputs=[space_list])
|
285 |
|
286 |
with gr.Column(scale=2):
|
287 |
with gr.Tabs():
|
@@ -311,26 +313,11 @@ def create_ui():
|
|
311 |
|
312 |
update_trigger = gr.Button("Update Screenshot", visible=False)
|
313 |
|
314 |
-
|
315 |
-
space_data = gr.Textbox(elem_id="space-data", visible=False)
|
316 |
-
on_select_trigger = gr.Button("Hidden Select Trigger", visible=False, elem_id="on-select-function")
|
317 |
-
|
318 |
-
def on_select_with_link(space_json):
|
319 |
-
space = json.loads(space_json)
|
320 |
info, app_content, url, tree, list_structure = on_select(space)
|
321 |
info += f"\n\n์ ํํ Space URL: {url}"
|
322 |
return info, app_content, url, tree, list_structure
|
323 |
|
324 |
-
on_select_trigger.click(
|
325 |
-
on_select_with_link,
|
326 |
-
inputs=[space_data],
|
327 |
-
outputs=[info_output, app_py_content, url_state, tree_view, list_view]
|
328 |
-
).then(
|
329 |
-
update_screenshot,
|
330 |
-
inputs=[url_state, last_url_state],
|
331 |
-
outputs=[screenshot_output, last_url_state]
|
332 |
-
)
|
333 |
-
|
334 |
def open_space_in_browser(url):
|
335 |
if url:
|
336 |
import webbrowser
|
@@ -368,17 +355,25 @@ def create_ui():
|
|
368 |
|
369 |
# JavaScript ์ฝ๋๋ฅผ ์ถ๊ฐํ๊ธฐ ์ํด js ํจ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
|
370 |
demo.load(js="""
|
371 |
-
function() {
|
372 |
-
document.
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
|
|
|
|
|
|
379 |
}
|
380 |
""")
|
381 |
|
|
|
|
|
|
|
|
|
|
|
382 |
# Start a background thread to trigger updates
|
383 |
def trigger_updates():
|
384 |
while True:
|
@@ -400,4 +395,4 @@ if __name__ == "__main__":
|
|
400 |
demo.launch()
|
401 |
except Exception as e:
|
402 |
print(f"Error in main: {str(e)}")
|
403 |
-
print(traceback.format_exc())
|
|
|
220 |
query in space.get('description', '').lower()
|
221 |
]
|
222 |
|
223 |
+
|
224 |
+
|
225 |
def create_ui():
|
226 |
try:
|
227 |
spaces_list = get_most_liked_spaces()
|
|
|
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"""
|
278 |
<div class='space-row'>
|
279 |
<span>{space['name']} by {space['author']} (Likes: {space['likes']})</span>
|
280 |
+
<button class='select-space' onclick='selectSpace({i})'>์ ํ</button>
|
281 |
</div>
|
282 |
"""
|
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 |
|
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
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
def open_space_in_browser(url):
|
322 |
if url:
|
323 |
import webbrowser
|
|
|
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 |
demo.launch()
|
396 |
except Exception as e:
|
397 |
print(f"Error in main: {str(e)}")
|
398 |
+
print(traceback.format_exc())
|