ginipick commited on
Commit
5348754
ยท
verified ยท
1 Parent(s): 2631941

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
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, Tuple
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
- print(f"Selected space: {selected_space['name']}") # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
131
- return selected_id, selected_space['url'], app_content
132
- print("Selected space not found") # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
133
- return None, "์„ ํƒ๋œ space๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", ""
134
-
135
- def on_summarize(space_id):
136
- if space_id:
137
- selected_space = next((space for space in formatted_spaces if space['id'] == space_id), None)
138
- if selected_space:
139
- summary = summarize_space(selected_space)
140
- print(f"Summarizing space: {selected_space['name']}") # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
141
- return summary
142
- print("No space selected for summarization") # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
143
  return "์„ ํƒ๋œ space๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋จผ์ € ๋ฆฌ์ŠคํŠธ์—์„œ space๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
144
 
145
- space_list.select(on_select, None, [selected_space_id, output, app_py_content])
146
- summarize_btn.click(on_summarize, inputs=[selected_space_id], outputs=[output])
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