Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,24 +15,24 @@ def format_timestamp(timestamp):
|
|
15 |
|
16 |
def get_space_card(space):
|
17 |
"""Generate HTML card for a space"""
|
|
|
18 |
return f"""
|
19 |
<div style='border: 1px solid #ddd; padding: 15px; margin: 10px; border-radius: 8px;
|
20 |
background-color: white; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
|
21 |
<h3 style='color: #2d2d2d; margin: 0 0 10px 0;'>
|
22 |
-
<a href='https://huggingface.co/spaces/{USERNAME}/{
|
23 |
style='text-decoration: none; color: #2d2d2d;'>
|
24 |
-
{
|
25 |
</a>
|
26 |
</h3>
|
27 |
-
<p style='margin: 5px 0;'><strong>Space ID:</strong> {
|
28 |
-
<p style='margin: 5px 0;'><strong>
|
29 |
-
<p style='margin: 5px 0;'><strong>Hardware:</strong> {space.get("runtime", {}).get("hardware", "N/A")}</p>
|
30 |
<p style='margin: 5px 0;'><strong>Status:</strong>
|
31 |
-
<span style='color: {"green" if space.get("
|
32 |
-
{space.get(
|
33 |
</p>
|
34 |
<p style='margin: 5px 0;'><strong>Created:</strong> {format_timestamp(space.get("createdAt"))}</p>
|
35 |
-
<p style='margin: 5px 0;'><strong>Updated:</strong> {format_timestamp(space.get("
|
36 |
</div>
|
37 |
"""
|
38 |
|
@@ -42,19 +42,23 @@ def get_user_spaces():
|
|
42 |
|
43 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
44 |
|
45 |
-
# Get
|
46 |
response = requests.get(
|
47 |
-
|
48 |
-
headers=headers
|
|
|
49 |
)
|
50 |
|
51 |
if response.status_code != 200:
|
52 |
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
53 |
|
54 |
spaces = response.json()
|
|
|
|
|
|
|
55 |
|
56 |
-
if not
|
57 |
-
return "No Spaces found."
|
58 |
|
59 |
# Create HTML grid layout
|
60 |
html_content = f"""
|
@@ -65,7 +69,7 @@ def get_user_spaces():
|
|
65 |
padding: 20px;
|
66 |
background-color: #f5f5f5;
|
67 |
'>
|
68 |
-
{"".join(get_space_card(space) for space in
|
69 |
</div>
|
70 |
"""
|
71 |
|
|
|
15 |
|
16 |
def get_space_card(space):
|
17 |
"""Generate HTML card for a space"""
|
18 |
+
space_id = space.get('id', '').split('/')[-1]
|
19 |
return f"""
|
20 |
<div style='border: 1px solid #ddd; padding: 15px; margin: 10px; border-radius: 8px;
|
21 |
background-color: white; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);'>
|
22 |
<h3 style='color: #2d2d2d; margin: 0 0 10px 0;'>
|
23 |
+
<a href='https://huggingface.co/spaces/{USERNAME}/{space_id}' target='_blank'
|
24 |
style='text-decoration: none; color: #2d2d2d;'>
|
25 |
+
{space_id}
|
26 |
</a>
|
27 |
</h3>
|
28 |
+
<p style='margin: 5px 0;'><strong>Space ID:</strong> {space_id}</p>
|
29 |
+
<p style='margin: 5px 0;'><strong>SDK:</strong> {space.get('sdk', 'N/A')}</p>
|
|
|
30 |
<p style='margin: 5px 0;'><strong>Status:</strong>
|
31 |
+
<span style='color: {"green" if space.get("status") == "running" else "red"}'>
|
32 |
+
{space.get('status', 'N/A')}</span>
|
33 |
</p>
|
34 |
<p style='margin: 5px 0;'><strong>Created:</strong> {format_timestamp(space.get("createdAt"))}</p>
|
35 |
+
<p style='margin: 5px 0;'><strong>Updated:</strong> {format_timestamp(space.get("updatedAt"))}</p>
|
36 |
</div>
|
37 |
"""
|
38 |
|
|
|
42 |
|
43 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
44 |
|
45 |
+
# Get all spaces and filter by username
|
46 |
response = requests.get(
|
47 |
+
"https://huggingface.co/api/spaces",
|
48 |
+
headers=headers,
|
49 |
+
params={"author": USERNAME} # Filter by author
|
50 |
)
|
51 |
|
52 |
if response.status_code != 200:
|
53 |
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
54 |
|
55 |
spaces = response.json()
|
56 |
+
|
57 |
+
# Filter spaces for the specific user
|
58 |
+
user_spaces = [space for space in spaces if space.get('author', '') == USERNAME]
|
59 |
|
60 |
+
if not user_spaces:
|
61 |
+
return "No Spaces found for this user."
|
62 |
|
63 |
# Create HTML grid layout
|
64 |
html_content = f"""
|
|
|
69 |
padding: 20px;
|
70 |
background-color: #f5f5f5;
|
71 |
'>
|
72 |
+
{"".join(get_space_card(space) for space in user_spaces)}
|
73 |
</div>
|
74 |
"""
|
75 |
|