Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -108,26 +108,16 @@ def create_ui():
|
|
108 |
formatted_spaces = format_spaces(spaces_list)
|
109 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
110 |
|
111 |
-
space_choices =
|
112 |
|
113 |
-
with gr.Blocks(
|
114 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
115 |
|
116 |
with gr.Row():
|
117 |
with gr.Column(scale=1):
|
118 |
-
|
119 |
-
space_radios = []
|
120 |
-
for space in formatted_spaces:
|
121 |
-
with gr.Row():
|
122 |
-
radio = gr.Radio(
|
123 |
-
choices=[f"{space['name']} by {space['author']} (Likes: {space['likes']})"],
|
124 |
-
label="",
|
125 |
-
value=None,
|
126 |
-
elem_id=f"radio-{space['id']}"
|
127 |
-
)
|
128 |
-
space_radios.append(radio)
|
129 |
-
gr.Button("๐", elem_id=f"link-{space['id']}")
|
130 |
summarize_btn = gr.Button("์์ฝ")
|
|
|
131 |
|
132 |
with gr.Column(scale=2):
|
133 |
output = gr.Textbox(label="Space ์ ๋ณด", lines=10)
|
@@ -136,14 +126,13 @@ def create_ui():
|
|
136 |
def on_select(choice):
|
137 |
try:
|
138 |
print(f"Selected: {choice}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
139 |
-
|
140 |
-
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
141 |
if selected_space:
|
142 |
-
app_content = get_app_py_content(
|
143 |
-
print(f"Selected space: {selected_space['name']} (ID: {
|
144 |
-
return f"์ ํ๋ Space: {selected_space['name']} (ID: {
|
145 |
else:
|
146 |
-
print(f"Space not found for
|
147 |
return "์ ํ๋ space๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", ""
|
148 |
except Exception as e:
|
149 |
print(f"Error in on_select: {str(e)}")
|
@@ -153,8 +142,7 @@ def create_ui():
|
|
153 |
def on_summarize(choice):
|
154 |
try:
|
155 |
if choice:
|
156 |
-
|
157 |
-
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
158 |
if selected_space:
|
159 |
summary = summarize_space(selected_space)
|
160 |
print(f"Summarizing space: {selected_space['name']}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
@@ -166,28 +154,25 @@ def create_ui():
|
|
166 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
167 |
return f"์์ฝ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
setupLinkButtons();
|
186 |
-
} else {
|
187 |
-
document.addEventListener('DOMContentLoaded', setupLinkButtons);
|
188 |
}
|
189 |
-
|
190 |
-
|
191 |
|
192 |
return demo
|
193 |
|
|
|
108 |
formatted_spaces = format_spaces(spaces_list)
|
109 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
110 |
|
111 |
+
space_choices = [f"{space['name']} by {space['author']} (Likes: {space['likes']})" for space in formatted_spaces]
|
112 |
|
113 |
+
with gr.Blocks() as demo:
|
114 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
115 |
|
116 |
with gr.Row():
|
117 |
with gr.Column(scale=1):
|
118 |
+
space_dropdown = gr.Dropdown(choices=space_choices, label="Select a Space")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
summarize_btn = gr.Button("์์ฝ")
|
120 |
+
link_btn = gr.Button("๐ Open Space")
|
121 |
|
122 |
with gr.Column(scale=2):
|
123 |
output = gr.Textbox(label="Space ์ ๋ณด", lines=10)
|
|
|
126 |
def on_select(choice):
|
127 |
try:
|
128 |
print(f"Selected: {choice}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
129 |
+
selected_space = next((space for space in formatted_spaces if f"{space['name']} by {space['author']} (Likes: {space['likes']})" == choice), None)
|
|
|
130 |
if selected_space:
|
131 |
+
app_content = get_app_py_content(selected_space['id'])
|
132 |
+
print(f"Selected space: {selected_space['name']} (ID: {selected_space['id']})") # ๋๋ฒ๊น
์ถ๋ ฅ
|
133 |
+
return f"์ ํ๋ Space: {selected_space['name']} (ID: {selected_space['id']})\nURL: {selected_space['url']}", app_content
|
134 |
else:
|
135 |
+
print(f"Space not found for choice: {choice}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
136 |
return "์ ํ๋ space๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", ""
|
137 |
except Exception as e:
|
138 |
print(f"Error in on_select: {str(e)}")
|
|
|
142 |
def on_summarize(choice):
|
143 |
try:
|
144 |
if choice:
|
145 |
+
selected_space = next((space for space in formatted_spaces if f"{space['name']} by {space['author']} (Likes: {space['likes']})" == choice), None)
|
|
|
146 |
if selected_space:
|
147 |
summary = summarize_space(selected_space)
|
148 |
print(f"Summarizing space: {selected_space['name']}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
|
|
154 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
155 |
return f"์์ฝ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
156 |
|
157 |
+
def open_space_link(choice):
|
158 |
+
if choice:
|
159 |
+
selected_space = next((space for space in formatted_spaces if f"{space['name']} by {space['author']} (Likes: {space['likes']})" == choice), None)
|
160 |
+
if selected_space:
|
161 |
+
return f"<script>window.open('{selected_space['url']}', '_blank');</script>"
|
162 |
+
return ""
|
163 |
+
|
164 |
+
space_dropdown.change(on_select, space_dropdown, [output, app_py_content])
|
165 |
+
summarize_btn.click(on_summarize, inputs=[space_dropdown], outputs=[output])
|
166 |
+
link_btn.click(open_space_link, inputs=[space_dropdown], outputs=[gr.HTML()])
|
167 |
+
|
168 |
+
# Add JavaScript to handle link opening
|
169 |
+
gr.HTML("""
|
170 |
+
<script>
|
171 |
+
function openSpaceLink(url) {
|
172 |
+
window.open(url, '_blank');
|
|
|
|
|
|
|
173 |
}
|
174 |
+
</script>
|
175 |
+
""")
|
176 |
|
177 |
return demo
|
178 |
|