ginipick commited on
Commit
b74fbff
·
verified ·
1 Parent(s): f90e879

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -16,11 +16,32 @@ HF_TOKEN = os.getenv("HF_TOKEN")
16
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
17
  hf_api = HfApi(token=HF_TOKEN)
18
 
 
 
19
  def get_headers():
20
  if not HF_TOKEN:
21
  raise ValueError("Hugging Face token not found in environment variables")
22
  return {"Authorization": f"Bearer {HF_TOKEN}"}
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def get_most_liked_spaces(limit: int = 300) -> Union[List[Dict], str]:
25
  url = "https://huggingface.co/api/spaces"
26
  params = {
@@ -213,9 +234,9 @@ def generate_usage_guide(app_content):
213
 
214
  def create_ui():
215
  try:
216
- spaces_list = get_most_liked_spaces()
217
  formatted_spaces = format_spaces(spaces_list)
218
- print(f"Total spaces loaded: {len(formatted_spaces)}")
219
 
220
  css = """
221
  footer {visibility: hidden;}
@@ -250,9 +271,9 @@ def create_ui():
250
  max-height: none !important;
251
  }
252
  """
253
-
254
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
255
- gr.Markdown("# 300: HuggingFace Most Liked Spaces")
256
 
257
  with gr.Row():
258
  with gr.Column(scale=1):
@@ -260,7 +281,7 @@ def create_ui():
260
  for space in formatted_spaces:
261
  with gr.Row(elem_classes="space-row") as space_row:
262
  with gr.Column():
263
- gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})", elem_classes="space-info")
264
  button = gr.Button("클릭", elem_classes="minimal-button")
265
  space_rows.append((space_row, button, space))
266
 
 
16
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=HF_TOKEN)
17
  hf_api = HfApi(token=HF_TOKEN)
18
 
19
+
20
+
21
  def get_headers():
22
  if not HF_TOKEN:
23
  raise ValueError("Hugging Face token not found in environment variables")
24
  return {"Authorization": f"Bearer {HF_TOKEN}"}
25
 
26
+ def get_trending_spaces(limit: int = 300) -> Union[List[Dict], str]:
27
+ url = "https://huggingface.co/api/spaces"
28
+ params = {
29
+ "sort": "trending",
30
+ "direction": -1,
31
+ "limit": limit,
32
+ "full": "true"
33
+ }
34
+
35
+ try:
36
+ response = requests.get(url, params=params, headers=get_headers())
37
+ response.raise_for_status()
38
+ return response.json()
39
+ except requests.RequestException as e:
40
+ return f"API request error: {str(e)}"
41
+ except ValueError as e:
42
+ return f"JSON decoding error: {str(e)}"
43
+
44
+
45
  def get_most_liked_spaces(limit: int = 300) -> Union[List[Dict], str]:
46
  url = "https://huggingface.co/api/spaces"
47
  params = {
 
234
 
235
  def create_ui():
236
  try:
237
+ spaces_list = get_trending_spaces()
238
  formatted_spaces = format_spaces(spaces_list)
239
+ print(f"Total trending spaces loaded: {len(formatted_spaces)}")
240
 
241
  css = """
242
  footer {visibility: hidden;}
 
271
  max-height: none !important;
272
  }
273
  """
274
+
275
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
276
+ gr.Markdown("# 300: HuggingFace Trending Spaces")
277
 
278
  with gr.Row():
279
  with gr.Column(scale=1):
 
281
  for space in formatted_spaces:
282
  with gr.Row(elem_classes="space-row") as space_row:
283
  with gr.Column():
284
+ gr.Markdown(f"{space['name']} by {space['author']}", elem_classes="space-info")
285
  button = gr.Button("클릭", elem_classes="minimal-button")
286
  space_rows.append((space_row, button, space))
287