Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -94,41 +94,30 @@ def create_ui():
|
|
94 |
formatted_spaces = format_spaces(spaces_list)
|
95 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
96 |
|
97 |
-
def create_table_html(spaces):
|
98 |
-
html = "<table><tr><th>Title</th><th>Author</th><th>Likes</th><th>Action</th></tr>"
|
99 |
-
for i, space in enumerate(spaces):
|
100 |
-
html += f"""
|
101 |
-
<tr>
|
102 |
-
<td>{space['name']}</td>
|
103 |
-
<td>{space['author']}</td>
|
104 |
-
<td>{space['likes']}</td>
|
105 |
-
<td><button onclick="selectSpace({i})">ํด๋ฆญ</button></td>
|
106 |
-
</tr>
|
107 |
-
"""
|
108 |
-
html += "</table>"
|
109 |
-
return html
|
110 |
-
|
111 |
with gr.Blocks() as demo:
|
112 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
113 |
|
114 |
with gr.Row():
|
115 |
with gr.Column(scale=1):
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
118 |
|
119 |
with gr.Column(scale=1):
|
120 |
info_output = gr.Textbox(label="Space ์ ๋ณด ๋ฐ ์์ฝ", lines=10)
|
121 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
122 |
|
123 |
-
def on_select(
|
124 |
try:
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
info
|
129 |
-
info += f"
|
130 |
-
info += f"
|
131 |
-
info += f"URL: {selected_space['url']}\n\n"
|
132 |
info += f"์์ฝ:\n{summary}"
|
133 |
return info, app_content
|
134 |
except Exception as e:
|
@@ -136,18 +125,8 @@ def create_ui():
|
|
136 |
print(traceback.format_exc())
|
137 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
function selectSpace(index) {
|
142 |
-
document.querySelectorAll('button').forEach(btn => btn.classList.remove('selected'));
|
143 |
-
event.target.classList.add('selected');
|
144 |
-
selectedIndex.update(index);
|
145 |
-
}
|
146 |
-
"""
|
147 |
-
demo.load(None, None, None)
|
148 |
-
gr.HTML(f"<script>{js_code}</script>")
|
149 |
-
|
150 |
-
selected_index.change(on_select, inputs=[selected_index], outputs=[info_output, app_py_content])
|
151 |
|
152 |
return demo
|
153 |
|
|
|
94 |
formatted_spaces = format_spaces(spaces_list)
|
95 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
with gr.Blocks() as demo:
|
98 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
99 |
|
100 |
with gr.Row():
|
101 |
with gr.Column(scale=1):
|
102 |
+
space_buttons = []
|
103 |
+
for space in formatted_spaces:
|
104 |
+
with gr.Row():
|
105 |
+
gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})")
|
106 |
+
button = gr.Button("ํด๋ฆญ", elem_id=f"btn-{space['id']}")
|
107 |
+
space_buttons.append(button)
|
108 |
|
109 |
with gr.Column(scale=1):
|
110 |
info_output = gr.Textbox(label="Space ์ ๋ณด ๋ฐ ์์ฝ", lines=10)
|
111 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
112 |
|
113 |
+
def on_select(space):
|
114 |
try:
|
115 |
+
summary = summarize_space(space)
|
116 |
+
app_content = get_app_py_content(space['id'])
|
117 |
+
info = f"์ ํ๋ Space: {space['name']} (ID: {space['id']})\n"
|
118 |
+
info += f"Author: {space['author']}\n"
|
119 |
+
info += f"Likes: {space['likes']}\n"
|
120 |
+
info += f"URL: {space['url']}\n\n"
|
|
|
121 |
info += f"์์ฝ:\n{summary}"
|
122 |
return info, app_content
|
123 |
except Exception as e:
|
|
|
125 |
print(traceback.format_exc())
|
126 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
127 |
|
128 |
+
for button, space in zip(space_buttons, formatted_spaces):
|
129 |
+
button.click(on_select, inputs=[gr.State(space)], outputs=[info_output, app_py_content])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
return demo
|
132 |
|