Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import requests
|
|
5 |
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import base64
|
|
|
8 |
|
9 |
# 환경 변수에서 토큰 가져오기
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
@@ -116,7 +117,7 @@ def create_ui():
|
|
116 |
with gr.Row():
|
117 |
with gr.Column(scale=1):
|
118 |
space_list = gr.List(
|
119 |
-
[
|
120 |
label="Most Liked Spaces"
|
121 |
)
|
122 |
summarize_btn = gr.Button("요약")
|
@@ -127,24 +128,36 @@ def create_ui():
|
|
127 |
|
128 |
def on_select(evt: gr.SelectData):
|
129 |
global selected_space_info
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
def on_summarize():
|
141 |
global selected_space_info
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
space_list.select(on_select, None, [output, app_py_content])
|
150 |
summarize_btn.click(on_summarize, None, output)
|
|
|
5 |
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import base64
|
8 |
+
import traceback
|
9 |
|
10 |
# 환경 변수에서 토큰 가져오기
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
117 |
with gr.Row():
|
118 |
with gr.Column(scale=1):
|
119 |
space_list = gr.List(
|
120 |
+
[f"{space['name']} by {space['author']} (Likes: {space['likes']})" for space in formatted_spaces],
|
121 |
label="Most Liked Spaces"
|
122 |
)
|
123 |
summarize_btn = gr.Button("요약")
|
|
|
128 |
|
129 |
def on_select(evt: gr.SelectData):
|
130 |
global selected_space_info
|
131 |
+
try:
|
132 |
+
print(f"Selection event: {evt}") # 디버깅 출력
|
133 |
+
selected_index = evt.index
|
134 |
+
if 0 <= selected_index < len(formatted_spaces):
|
135 |
+
selected_space = formatted_spaces[selected_index]
|
136 |
+
selected_space_info = selected_space
|
137 |
+
app_content = get_app_py_content(selected_space['id'])
|
138 |
+
print(f"Selected space: {selected_space['name']} (ID: {selected_space['id']})") # 디버깅 출력
|
139 |
+
return f"선택된 Space: {selected_space['name']} (ID: {selected_space['id']})\nURL: {selected_space['url']}", app_content
|
140 |
+
else:
|
141 |
+
print(f"Invalid selection index: {selected_index}") # 디버깅 출력
|
142 |
+
return "잘못된 선택입니다.", ""
|
143 |
+
except Exception as e:
|
144 |
+
print(f"Error in on_select: {str(e)}")
|
145 |
+
print(traceback.format_exc()) # 상세한 오류 정보 출력
|
146 |
+
return f"오류가 발생했습니다: {str(e)}", ""
|
147 |
|
148 |
def on_summarize():
|
149 |
global selected_space_info
|
150 |
+
try:
|
151 |
+
if selected_space_info:
|
152 |
+
summary = summarize_space(selected_space_info)
|
153 |
+
print(f"Summarizing space: {selected_space_info['name']}") # 디버깅 출력
|
154 |
+
return summary
|
155 |
+
print("No space selected for summarization") # 디버깅 출력
|
156 |
+
return "선택된 space가 없습니다. 먼저 리스트에서 space를 선택해주세요."
|
157 |
+
except Exception as e:
|
158 |
+
print(f"Error in on_summarize: {str(e)}")
|
159 |
+
print(traceback.format_exc()) # 상세한 오류 정보 출력
|
160 |
+
return f"요약 중 오류가 발생했습니다: {str(e)}"
|
161 |
|
162 |
space_list.select(on_select, None, [output, app_py_content])
|
163 |
summarize_btn.click(on_summarize, None, output)
|