Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -50,26 +50,24 @@ def capture_thumbnail(space_id: str) -> bytes:
|
|
50 |
pass
|
51 |
return None
|
52 |
|
53 |
-
def get_hardware_requirements(space: Dict) -> str:
|
54 |
-
sdk_version = space.get('sdk', {}).get('hf', {}).get('version')
|
55 |
-
if sdk_version and int(sdk_version.split('.')[0]) >= 3:
|
56 |
-
return space.get('sdk', {}).get('hardware', 'Unknown')
|
57 |
-
else:
|
58 |
-
return 'CPU' if space.get('host_requirements', {}).get('hardware', {}).get('gpu') is False else 'GPU'
|
59 |
-
|
60 |
def format_spaces(spaces: Union[List[Dict], str]) -> List[Dict]:
|
61 |
if isinstance(spaces, str):
|
62 |
return [{"error": spaces}]
|
63 |
|
64 |
-
valid_spaces = [
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
67 |
return list(executor.map(format_space, valid_spaces))
|
68 |
|
69 |
-
def format_space(space:
|
70 |
if not isinstance(space, dict):
|
71 |
-
return {"error": "Invalid space
|
72 |
-
|
73 |
space_id = space.get('id', 'Unknown')
|
74 |
space_name = space_id.split('/')[-1] if '/' in space_id else space_id
|
75 |
|
@@ -93,6 +91,16 @@ def format_space(space: Union[Dict, str]) -> Dict:
|
|
93 |
"hardware": hardware
|
94 |
}
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
def get_app_py_content(space_id: str) -> str:
|
98 |
app_py_url = f"https://huggingface.co/spaces/{space_id}/raw/main/app.py"
|
|
|
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}]
|
56 |
|
57 |
+
valid_spaces = []
|
58 |
+
for space in spaces:
|
59 |
+
if isinstance(space, dict):
|
60 |
+
valid_spaces.append(space)
|
61 |
+
else:
|
62 |
+
print(f"Skipping invalid space: {space}")
|
63 |
|
64 |
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
65 |
return list(executor.map(format_space, valid_spaces))
|
66 |
|
67 |
+
def format_space(space: Dict) -> Dict:
|
68 |
if not isinstance(space, dict):
|
69 |
+
return {"error": f"Invalid space format: {space}"}
|
70 |
+
|
71 |
space_id = space.get('id', 'Unknown')
|
72 |
space_name = space_id.split('/')[-1] if '/' in space_id else space_id
|
73 |
|
|
|
91 |
"hardware": hardware
|
92 |
}
|
93 |
|
94 |
+
def get_hardware_requirements(space: Dict) -> str:
|
95 |
+
if not isinstance(space, dict):
|
96 |
+
return "Unknown"
|
97 |
+
|
98 |
+
sdk_version = space.get('sdk', {}).get('hf', {}).get('version')
|
99 |
+
if sdk_version and int(sdk_version.split('.')[0]) >= 3:
|
100 |
+
return space.get('sdk', {}).get('hardware', 'Unknown')
|
101 |
+
else:
|
102 |
+
return 'CPU' if space.get('host_requirements', {}).get('hardware', {}).get('gpu') is False else 'GPU'
|
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"
|