Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import requests
|
5 |
-
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import base64
|
8 |
|
@@ -12,6 +12,9 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
12 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
13 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
14 |
|
|
|
|
|
|
|
15 |
def get_headers():
|
16 |
if not HF_TOKEN:
|
17 |
raise ValueError("Hugging Face token not found in environment variables")
|
@@ -105,10 +108,10 @@ def summarize_space(space: Dict) -> str:
|
|
105 |
def create_ui():
|
106 |
spaces_list = get_most_liked_spaces()
|
107 |
formatted_spaces = format_spaces(spaces_list)
|
|
|
108 |
|
109 |
with gr.Blocks() as demo:
|
110 |
gr.Markdown("# Hugging Face Most Liked Spaces")
|
111 |
-
selected_space_id = gr.State(None)
|
112 |
|
113 |
with gr.Row():
|
114 |
with gr.Column(scale=1):
|
@@ -123,27 +126,28 @@ def create_ui():
|
|
123 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
124 |
|
125 |
def on_select(evt: gr.SelectData):
|
|
|
126 |
selected_id = evt.value[1] # tuple์ ๋ ๋ฒ์งธ ์์๊ฐ space_id์
๋๋ค.
|
127 |
selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
|
128 |
if selected_space:
|
129 |
app_content = get_app_py_content(selected_id)
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
print("No space selected for summarization") #
|
143 |
return "์ ํ๋ space๊ฐ ์์ต๋๋ค. ๋จผ์ ๋ฆฌ์คํธ์์ space๋ฅผ ์ ํํด์ฃผ์ธ์."
|
144 |
|
145 |
-
space_list.select(on_select, None, [
|
146 |
-
summarize_btn.click(on_summarize,
|
147 |
|
148 |
return demo
|
149 |
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import requests
|
5 |
+
from typing import List, Dict, Union
|
6 |
import concurrent.futures
|
7 |
import base64
|
8 |
|
|
|
12 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
13 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
|
14 |
|
15 |
+
# ์ ์ญ ๋ณ์๋ก ์ ํ๋ space ์ ๋ณด ์ ์ฅ
|
16 |
+
selected_space_info = None
|
17 |
+
|
18 |
def get_headers():
|
19 |
if not HF_TOKEN:
|
20 |
raise ValueError("Hugging Face token not found in environment variables")
|
|
|
108 |
def create_ui():
|
109 |
spaces_list = get_most_liked_spaces()
|
110 |
formatted_spaces = format_spaces(spaces_list)
|
111 |
+
print(f"Total spaces loaded: {len(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):
|
|
|
126 |
app_py_content = gr.Code(language="python", label="app.py ๋ด์ฉ")
|
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)
|
151 |
|
152 |
return demo
|
153 |
|