ginipick commited on
Commit
5cfddce
·
verified ·
1 Parent(s): 5348754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
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
- [(f"{space['name']} by {space['author']} (Likes: {space['likes']})", space['id']) for space in formatted_spaces],
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
- selected_id = evt.value[1] # tuple의 두 번째 요소가 space_id입니다.
131
- selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
132
- if selected_space:
133
- app_content = get_app_py_content(selected_id)
134
- selected_space_info = selected_space
135
- print(f"Selected space: {selected_space['name']}") # 디버깅 출력
136
- return f"선택된 Space: {selected_space['name']} (ID: {selected_id})\nURL: {selected_space['url']}", app_content
137
- print(f"Selected space not found for ID: {selected_id}") # 디버깅 출력
138
- return "선택된 space를 찾을 없습니다.", ""
 
 
 
 
 
 
 
139
 
140
  def on_summarize():
141
  global selected_space_info
142
- if selected_space_info:
143
- summary = summarize_space(selected_space_info)
144
- print(f"Summarizing space: {selected_space_info['name']}") # 디버깅 출력
145
- return summary
146
- print("No space selected for summarization") # 디버깅 출력
147
- return "선택된 space 없습니다. 먼저 리스트에서 space를 선택해주세요."
 
 
 
 
 
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)