ginipick commited on
Commit
383b3b6
ยท
verified ยท
1 Parent(s): b74fbff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -35,12 +35,15 @@ def get_trending_spaces(limit: int = 300) -> Union[List[Dict], str]:
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"
@@ -61,8 +64,11 @@ def get_most_liked_spaces(limit: int = 300) -> Union[List[Dict], str]:
61
  return f"JSON decoding error: {str(e)}"
62
 
63
  def format_space(space: Dict) -> Dict:
 
 
 
64
  space_id = space.get('id', 'Unknown')
65
- space_name = space_id.split('/')[-1] if '/' in space_id else space_id
66
 
67
  space_author = space.get('author', 'Unknown')
68
  if isinstance(space_author, dict):
@@ -83,7 +89,16 @@ def format_spaces(spaces: Union[List[Dict], str]) -> List[Dict]:
83
  if isinstance(spaces, str):
84
  return [{"error": spaces}]
85
 
86
- return [format_space(space) for space in spaces if isinstance(space, dict)]
 
 
 
 
 
 
 
 
 
87
 
88
  def summarize_space(space: Dict) -> str:
89
  system_message = "๋‹น์‹ ์€ Hugging Face Space์˜ ๋‚ด์šฉ์„ ์š”์•ฝํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๊ฐ„๊ฒฐํ•˜๊ณ  ๋ช…ํ™•ํ•œ ์š”์•ฝ์„ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”."
@@ -271,7 +286,7 @@ def create_ui():
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
 
@@ -281,10 +296,12 @@ def create_ui():
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
 
 
288
  with gr.Column(scale=2):
289
  with gr.Tabs():
290
  with gr.TabItem("๊ธฐ๋ณธ ์ •๋ณด"):
 
35
  try:
36
  response = requests.get(url, params=params, headers=get_headers())
37
  response.raise_for_status()
38
+ data = response.json()
39
+ print(f"API Response: {json.dumps(data[:2], indent=2)}") # ์ฒ˜์Œ ๋‘ ํ•ญ๋ชฉ๋งŒ ์ถœ๋ ฅ
40
+ return data
41
  except requests.RequestException as e:
42
  return f"API request error: {str(e)}"
43
  except ValueError as e:
44
  return f"JSON decoding error: {str(e)}"
45
 
46
+
47
 
48
  def get_most_liked_spaces(limit: int = 300) -> Union[List[Dict], str]:
49
  url = "https://huggingface.co/api/spaces"
 
64
  return f"JSON decoding error: {str(e)}"
65
 
66
  def format_space(space: Dict) -> Dict:
67
+ # ๋””๋ฒ„๊น…์„ ์œ„ํ•ด ์›๋ณธ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
68
+ print(f"Original space data: {json.dumps(space, indent=2)}")
69
+
70
  space_id = space.get('id', 'Unknown')
71
+ space_name = space.get('title', space_id.split('/')[-1] if '/' in space_id else space_id)
72
 
73
  space_author = space.get('author', 'Unknown')
74
  if isinstance(space_author, dict):
 
89
  if isinstance(spaces, str):
90
  return [{"error": spaces}]
91
 
92
+ formatted = []
93
+ for space in spaces:
94
+ if isinstance(space, dict):
95
+ try:
96
+ formatted.append(format_space(space))
97
+ except Exception as e:
98
+ print(f"Error formatting space: {str(e)}")
99
+ print(f"Problematic space data: {json.dumps(space, indent=2)}")
100
+ return formatted
101
+
102
 
103
  def summarize_space(space: Dict) -> str:
104
  system_message = "๋‹น์‹ ์€ Hugging Face Space์˜ ๋‚ด์šฉ์„ ์š”์•ฝํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๊ฐ„๊ฒฐํ•˜๊ณ  ๋ช…ํ™•ํ•œ ์š”์•ฝ์„ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”."
 
286
  max-height: none !important;
287
  }
288
  """
289
+
290
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
291
  gr.Markdown("# 300: HuggingFace Trending Spaces")
292
 
 
296
  for space in formatted_spaces:
297
  with gr.Row(elem_classes="space-row") as space_row:
298
  with gr.Column():
299
+ space_info = f"{space.get('name', 'Unknown')} by {space.get('author', 'Unknown')}"
300
+ gr.Markdown(space_info, elem_classes="space-info")
301
  button = gr.Button("ํด๋ฆญ", elem_classes="minimal-button")
302
  space_rows.append((space_row, button, space))
303
 
304
+
305
  with gr.Column(scale=2):
306
  with gr.Tabs():
307
  with gr.TabItem("๊ธฐ๋ณธ ์ •๋ณด"):