Update app.py
Browse files
app.py
CHANGED
|
@@ -50,6 +50,7 @@ def capture_thumbnail(space_id: str) -> bytes:
|
|
| 50 |
pass
|
| 51 |
return None
|
| 52 |
|
|
|
|
| 53 |
def format_spaces(spaces: Union[List[Dict], str]) -> List[Dict]:
|
| 54 |
if isinstance(spaces, str):
|
| 55 |
return [{"error": spaces}]
|
|
@@ -61,12 +62,18 @@ def format_spaces(spaces: Union[List[Dict], str]) -> List[Dict]:
|
|
| 61 |
else:
|
| 62 |
print(f"Skipping invalid space: {space}")
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
def format_space(space: Dict) -> Dict:
|
| 68 |
if not isinstance(space, dict):
|
| 69 |
-
|
| 70 |
|
| 71 |
space_id = space.get('id', 'Unknown')
|
| 72 |
space_name = space_id.split('/')[-1] if '/' in space_id else space_id
|
|
@@ -95,12 +102,24 @@ def get_hardware_requirements(space: Dict) -> str:
|
|
| 95 |
if not isinstance(space, dict):
|
| 96 |
return "Unknown"
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if sdk_version and int(sdk_version.split('.')[0]) >= 3:
|
| 100 |
-
return
|
| 101 |
else:
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
def get_app_py_content(space_id: str) -> str:
|
| 106 |
app_py_url = f"https://huggingface.co/spaces/{space_id}/raw/main/app.py"
|
|
@@ -127,8 +146,14 @@ def summarize_space(space: Dict) -> str:
|
|
| 127 |
|
| 128 |
def create_ui():
|
| 129 |
spaces_list = get_most_liked_spaces()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
formatted_spaces = format_spaces(spaces_list)
|
| 131 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # 디버깅 출력
|
|
|
|
| 132 |
|
| 133 |
css = """
|
| 134 |
footer {
|
|
|
|
| 50 |
pass
|
| 51 |
return None
|
| 52 |
|
| 53 |
+
|
| 54 |
def format_spaces(spaces: Union[List[Dict], str]) -> List[Dict]:
|
| 55 |
if isinstance(spaces, str):
|
| 56 |
return [{"error": spaces}]
|
|
|
|
| 62 |
else:
|
| 63 |
print(f"Skipping invalid space: {space}")
|
| 64 |
|
| 65 |
+
formatted = []
|
| 66 |
+
for space in valid_spaces:
|
| 67 |
+
try:
|
| 68 |
+
formatted.append(format_space(space))
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f"Error formatting space: {space.get('id', 'Unknown')}. Error: {str(e)}")
|
| 71 |
+
|
| 72 |
+
return formatted
|
| 73 |
|
| 74 |
def format_space(space: Dict) -> Dict:
|
| 75 |
if not isinstance(space, dict):
|
| 76 |
+
raise ValueError(f"Invalid space format: {space}")
|
| 77 |
|
| 78 |
space_id = space.get('id', 'Unknown')
|
| 79 |
space_name = space_id.split('/')[-1] if '/' in space_id else space_id
|
|
|
|
| 102 |
if not isinstance(space, dict):
|
| 103 |
return "Unknown"
|
| 104 |
|
| 105 |
+
sdk = space.get('sdk', {})
|
| 106 |
+
if not isinstance(sdk, dict):
|
| 107 |
+
return "Unknown"
|
| 108 |
+
|
| 109 |
+
hf = sdk.get('hf', {})
|
| 110 |
+
if not isinstance(hf, dict):
|
| 111 |
+
return "Unknown"
|
| 112 |
+
|
| 113 |
+
sdk_version = hf.get('version')
|
| 114 |
if sdk_version and int(sdk_version.split('.')[0]) >= 3:
|
| 115 |
+
return sdk.get('hardware', 'Unknown')
|
| 116 |
else:
|
| 117 |
+
host_requirements = space.get('host_requirements', {})
|
| 118 |
+
if isinstance(host_requirements, dict):
|
| 119 |
+
hardware = host_requirements.get('hardware', {})
|
| 120 |
+
if isinstance(hardware, dict):
|
| 121 |
+
return 'CPU' if hardware.get('gpu') is False else 'GPU'
|
| 122 |
+
return 'Unknown'
|
| 123 |
|
| 124 |
def get_app_py_content(space_id: str) -> str:
|
| 125 |
app_py_url = f"https://huggingface.co/spaces/{space_id}/raw/main/app.py"
|
|
|
|
| 146 |
|
| 147 |
def create_ui():
|
| 148 |
spaces_list = get_most_liked_spaces()
|
| 149 |
+
print(f"Type of spaces_list: {type(spaces_list)}")
|
| 150 |
+
if isinstance(spaces_list, str):
|
| 151 |
+
print(f"Error in get_most_liked_spaces: {spaces_list}")
|
| 152 |
+
return gr.Blocks().launch()
|
| 153 |
+
|
| 154 |
formatted_spaces = format_spaces(spaces_list)
|
| 155 |
print(f"Total spaces loaded: {len(formatted_spaces)}") # 디버깅 출력
|
| 156 |
+
|
| 157 |
|
| 158 |
css = """
|
| 159 |
footer {
|