Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,6 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
13 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
14 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
15 |
|
16 |
-
# ์ ์ญ ๋ณ์๋ก ์ ํ๋ space ์ ๋ณด ์ ์ฅ
|
17 |
-
selected_space_info = None
|
18 |
-
|
19 |
def get_headers():
|
20 |
if not HF_TOKEN:
|
21 |
raise ValueError("Hugging Face token not found in environment variables")
|
@@ -111,14 +108,16 @@ def create_ui():
|
|
111 |
formatted_spaces = format_spaces(spaces_list)
|
112 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
113 |
|
|
|
|
|
114 |
with gr.Blocks() as demo:
|
115 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
116 |
|
117 |
with gr.Row():
|
118 |
with gr.Column(scale=1):
|
119 |
-
|
120 |
-
|
121 |
-
label="
|
122 |
)
|
123 |
summarize_btn = gr.Button("์์ฝ")
|
124 |
|
@@ -126,14 +125,12 @@ def create_ui():
|
|
126 |
output = gr.Textbox(label="Space ์ ๋ณด", lines=10)
|
127 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
128 |
|
129 |
-
def on_select(
|
130 |
-
global selected_space_info
|
131 |
try:
|
132 |
-
print(f"
|
133 |
-
selected_id =
|
134 |
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
135 |
if selected_space:
|
136 |
-
selected_space_info = selected_space
|
137 |
app_content = get_app_py_content(selected_id)
|
138 |
print(f"Selected space: {selected_space['name']} (ID: {selected_id})") # ๋๋ฒ๊น
์ถ๋ ฅ
|
139 |
return f"์ ํ๋ Space: {selected_space['name']} (ID: {selected_id})\nURL: {selected_space['url']}", app_content
|
@@ -145,13 +142,15 @@ def create_ui():
|
|
145 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
146 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
147 |
|
148 |
-
def on_summarize():
|
149 |
-
global selected_space_info
|
150 |
try:
|
151 |
-
if
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
155 |
print("No space selected for summarization") # ๋๋ฒ๊น
์ถ๋ ฅ
|
156 |
return "์ ํ๋ space๊ฐ ์์ต๋๋ค. ๋จผ์ ๋ฆฌ์คํธ์์ space๋ฅผ ์ ํํด์ฃผ์ธ์."
|
157 |
except Exception as e:
|
@@ -159,8 +158,8 @@ def create_ui():
|
|
159 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
160 |
return f"์์ฝ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
161 |
|
162 |
-
|
163 |
-
summarize_btn.click(on_summarize,
|
164 |
|
165 |
return demo
|
166 |
|
|
|
13 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
14 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
15 |
|
|
|
|
|
|
|
16 |
def get_headers():
|
17 |
if not HF_TOKEN:
|
18 |
raise ValueError("Hugging Face token not found in environment variables")
|
|
|
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']})": space['id'] 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_radio = gr.Radio(
|
119 |
+
choices=list(space_choices.keys()),
|
120 |
+
label="Select a Space"
|
121 |
)
|
122 |
summarize_btn = gr.Button("์์ฝ")
|
123 |
|
|
|
125 |
output = gr.Textbox(label="Space ์ ๋ณด", lines=10)
|
126 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
127 |
|
128 |
+
def on_select(choice):
|
|
|
129 |
try:
|
130 |
+
print(f"Selected: {choice}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
131 |
+
selected_id = space_choices[choice]
|
132 |
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
133 |
if selected_space:
|
|
|
134 |
app_content = get_app_py_content(selected_id)
|
135 |
print(f"Selected space: {selected_space['name']} (ID: {selected_id})") # ๋๋ฒ๊น
์ถ๋ ฅ
|
136 |
return f"์ ํ๋ Space: {selected_space['name']} (ID: {selected_id})\nURL: {selected_space['url']}", app_content
|
|
|
142 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
143 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
144 |
|
145 |
+
def on_summarize(choice):
|
|
|
146 |
try:
|
147 |
+
if choice:
|
148 |
+
selected_id = space_choices[choice]
|
149 |
+
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
150 |
+
if selected_space:
|
151 |
+
summary = summarize_space(selected_space)
|
152 |
+
print(f"Summarizing space: {selected_space['name']}") # ๋๋ฒ๊น
์ถ๋ ฅ
|
153 |
+
return summary
|
154 |
print("No space selected for summarization") # ๋๋ฒ๊น
์ถ๋ ฅ
|
155 |
return "์ ํ๋ space๊ฐ ์์ต๋๋ค. ๋จผ์ ๋ฆฌ์คํธ์์ space๋ฅผ ์ ํํด์ฃผ์ธ์."
|
156 |
except Exception as e:
|
|
|
158 |
print(traceback.format_exc()) # ์์ธํ ์ค๋ฅ ์ ๋ณด ์ถ๋ ฅ
|
159 |
return f"์์ฝ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
160 |
|
161 |
+
space_radio.change(on_select, space_radio, [output, app_py_content])
|
162 |
+
summarize_btn.click(on_summarize, space_radio, output)
|
163 |
|
164 |
return demo
|
165 |
|