Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import requests
|
|
5 |
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import traceback
|
8 |
-
import base64
|
9 |
|
10 |
# 환경 변수에서 토큰 가져오기
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
@@ -126,13 +125,29 @@ def create_ui():
|
|
126 |
}
|
127 |
"""
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
with gr.Blocks(css=css) as demo:
|
130 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
131 |
|
132 |
with gr.Row():
|
133 |
with gr.Column(scale=1):
|
|
|
134 |
for space in formatted_spaces:
|
135 |
-
with gr.Row(elem_classes="space-row"):
|
136 |
if space['thumbnail']:
|
137 |
gr.Image(value=space['thumbnail'], show_label=False, elem_classes="thumbnail")
|
138 |
else:
|
@@ -140,30 +155,18 @@ def create_ui():
|
|
140 |
with gr.Column():
|
141 |
gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})", elem_classes="space-info")
|
142 |
button = gr.Button("클릭", elem_classes="minimal-button")
|
143 |
-
|
144 |
-
lambda s=space: on_select(s),
|
145 |
-
inputs=[],
|
146 |
-
outputs=[info_output, app_py_content]
|
147 |
-
)
|
148 |
|
149 |
with gr.Column(scale=1):
|
150 |
info_output = gr.Textbox(label="Space 정보 및 요약", lines=10)
|
151 |
app_py_content = gr.Code(language="python", label="app.py 내용")
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
info += f"Likes: {space['likes']}\n"
|
160 |
-
info += f"URL: {space['url']}\n\n"
|
161 |
-
info += f"요약:\n{summary}"
|
162 |
-
return info, app_content
|
163 |
-
except Exception as e:
|
164 |
-
print(f"Error in on_select: {str(e)}")
|
165 |
-
print(traceback.format_exc())
|
166 |
-
return f"오류가 발생했습니다: {str(e)}", ""
|
167 |
|
168 |
return demo
|
169 |
|
|
|
5 |
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import traceback
|
|
|
8 |
|
9 |
# 환경 변수에서 토큰 가져오기
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
125 |
}
|
126 |
"""
|
127 |
|
128 |
+
def on_select(space):
|
129 |
+
try:
|
130 |
+
summary = summarize_space(space)
|
131 |
+
app_content = get_app_py_content(space['id'])
|
132 |
+
info = f"선택된 Space: {space['name']} (ID: {space['id']})\n"
|
133 |
+
info += f"Author: {space['author']}\n"
|
134 |
+
info += f"Likes: {space['likes']}\n"
|
135 |
+
info += f"URL: {space['url']}\n\n"
|
136 |
+
info += f"요약:\n{summary}"
|
137 |
+
return info, app_content
|
138 |
+
except Exception as e:
|
139 |
+
print(f"Error in on_select: {str(e)}")
|
140 |
+
print(traceback.format_exc())
|
141 |
+
return f"오류가 발생했습니다: {str(e)}", ""
|
142 |
+
|
143 |
with gr.Blocks(css=css) as demo:
|
144 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
145 |
|
146 |
with gr.Row():
|
147 |
with gr.Column(scale=1):
|
148 |
+
space_rows = []
|
149 |
for space in formatted_spaces:
|
150 |
+
with gr.Row(elem_classes="space-row") as space_row:
|
151 |
if space['thumbnail']:
|
152 |
gr.Image(value=space['thumbnail'], show_label=False, elem_classes="thumbnail")
|
153 |
else:
|
|
|
155 |
with gr.Column():
|
156 |
gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})", elem_classes="space-info")
|
157 |
button = gr.Button("클릭", elem_classes="minimal-button")
|
158 |
+
space_rows.append((space_row, button, space))
|
|
|
|
|
|
|
|
|
159 |
|
160 |
with gr.Column(scale=1):
|
161 |
info_output = gr.Textbox(label="Space 정보 및 요약", lines=10)
|
162 |
app_py_content = gr.Code(language="python", label="app.py 내용")
|
163 |
|
164 |
+
for _, button, space in space_rows:
|
165 |
+
button.click(
|
166 |
+
lambda s=space: on_select(s),
|
167 |
+
inputs=[],
|
168 |
+
outputs=[info_output, app_py_content]
|
169 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
return demo
|
172 |
|