Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
|
|
3 |
from typing import List, Dict, Union
|
4 |
|
5 |
def get_most_liked_spaces(limit: int = 10) -> Union[List[Dict], str]:
|
@@ -16,6 +17,10 @@ def get_most_liked_spaces(limit: int = 10) -> Union[List[Dict], str]:
|
|
16 |
response.raise_for_status()
|
17 |
data = response.json()
|
18 |
|
|
|
|
|
|
|
|
|
19 |
if isinstance(data, list):
|
20 |
return data
|
21 |
else:
|
@@ -32,13 +37,20 @@ def format_spaces(spaces: Union[List[Dict], str]) -> str:
|
|
32 |
output = ""
|
33 |
for idx, space in enumerate(spaces, 1):
|
34 |
if not isinstance(space, dict):
|
35 |
-
output += f"{idx}. Unexpected space data format: {type(space)}\n
|
|
|
36 |
continue
|
37 |
|
38 |
-
#
|
39 |
space_id = space.get('id', 'Unknown')
|
40 |
-
space_name = space.get('title', 'Unknown')
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
space_likes = space.get('likes', 'N/A')
|
43 |
|
44 |
output += f"{idx}. {space_name} by {space_author}\n"
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
+
import json
|
4 |
from typing import List, Dict, Union
|
5 |
|
6 |
def get_most_liked_spaces(limit: int = 10) -> Union[List[Dict], str]:
|
|
|
17 |
response.raise_for_status()
|
18 |
data = response.json()
|
19 |
|
20 |
+
# 디버깅: 전체 응답 구조 출력
|
21 |
+
print("API Response Structure:")
|
22 |
+
print(json.dumps(data[:2], indent=2)) # 처음 두 개의 항목만 출력
|
23 |
+
|
24 |
if isinstance(data, list):
|
25 |
return data
|
26 |
else:
|
|
|
37 |
output = ""
|
38 |
for idx, space in enumerate(spaces, 1):
|
39 |
if not isinstance(space, dict):
|
40 |
+
output += f"{idx}. Unexpected space data format: {type(space)}\n"
|
41 |
+
output += f" Content: {space}\n\n"
|
42 |
continue
|
43 |
|
44 |
+
# 안전한 데이터 접근
|
45 |
space_id = space.get('id', 'Unknown')
|
46 |
+
space_name = space.get('title', space.get('name', 'Unknown'))
|
47 |
+
|
48 |
+
author_info = space.get('author', {})
|
49 |
+
if isinstance(author_info, dict):
|
50 |
+
space_author = author_info.get('user', author_info.get('name', 'Unknown'))
|
51 |
+
else:
|
52 |
+
space_author = str(author_info)
|
53 |
+
|
54 |
space_likes = space.get('likes', 'N/A')
|
55 |
|
56 |
output += f"{idx}. {space_name} by {space_author}\n"
|