Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import os
|
|
4 |
import requests
|
5 |
from typing import List, Dict, Union, Tuple
|
6 |
import concurrent.futures
|
|
|
7 |
|
8 |
# 환경 변수에서 토큰 가져오기
|
9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
@@ -110,7 +111,7 @@ def create_ui():
|
|
110 |
with gr.Row():
|
111 |
with gr.Column(scale=1):
|
112 |
space_list = gr.List(
|
113 |
-
[f"{space['name']} by {space['author']} (Likes: {space['likes']})" for space in formatted_spaces],
|
114 |
label="Most Liked Spaces"
|
115 |
)
|
116 |
summarize_btn = gr.Button("요약")
|
@@ -120,17 +121,23 @@ def create_ui():
|
|
120 |
app_py_content = gr.Code(language="python", label="app.py 내용")
|
121 |
|
122 |
def on_select(evt: gr.SelectData):
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
126 |
|
127 |
def on_summarize(evt: gr.SelectData):
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
131 |
|
132 |
space_list.select(on_select, None, [output, app_py_content])
|
133 |
-
summarize_btn.click(on_summarize,
|
134 |
|
135 |
return demo
|
136 |
|
|
|
4 |
import requests
|
5 |
from typing import List, Dict, Union, Tuple
|
6 |
import concurrent.futures
|
7 |
+
import base64
|
8 |
|
9 |
# 환경 변수에서 토큰 가져오기
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
111 |
with gr.Row():
|
112 |
with gr.Column(scale=1):
|
113 |
space_list = gr.List(
|
114 |
+
[(f"{space['name']} by {space['author']} (Likes: {space['likes']})", space['id']) for space in formatted_spaces],
|
115 |
label="Most Liked Spaces"
|
116 |
)
|
117 |
summarize_btn = gr.Button("요약")
|
|
|
121 |
app_py_content = gr.Code(language="python", label="app.py 내용")
|
122 |
|
123 |
def on_select(evt: gr.SelectData):
|
124 |
+
selected_space_id = evt.value[1] # tuple의 두 번째 요소가 space_id입니다.
|
125 |
+
selected_space = next((space for space in formatted_spaces if space['id'] == selected_space_id), None)
|
126 |
+
if selected_space:
|
127 |
+
app_content = get_app_py_content(selected_space['id'])
|
128 |
+
return selected_space['url'], app_content
|
129 |
+
return "선택된 space를 찾을 수 없습니다.", ""
|
130 |
|
131 |
def on_summarize(evt: gr.SelectData):
|
132 |
+
selected_space_id = evt.value[1]
|
133 |
+
selected_space = next((space for space in formatted_spaces if space['id'] == selected_space_id), None)
|
134 |
+
if selected_space:
|
135 |
+
summary = summarize_space(selected_space)
|
136 |
+
return summary
|
137 |
+
return "선택된 space를 찾을 수 없습니다."
|
138 |
|
139 |
space_list.select(on_select, None, [output, app_py_content])
|
140 |
+
summarize_btn.click(on_summarize, space_list, output)
|
141 |
|
142 |
return demo
|
143 |
|