Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
from datetime import datetime
|
4 |
|
5 |
USERNAME = "openfree"
|
|
|
6 |
|
7 |
def format_timestamp(timestamp):
|
8 |
if timestamp:
|
@@ -51,24 +52,53 @@ def get_space_card(space):
|
|
51 |
</div>
|
52 |
"""
|
53 |
|
54 |
-
def
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if not user_spaces:
|
74 |
return f"""
|
|
|
3 |
from datetime import datetime
|
4 |
|
5 |
USERNAME = "openfree"
|
6 |
+
LIMIT = 100 # 한 번에 가져올 최대 spaces 수
|
7 |
|
8 |
def format_timestamp(timestamp):
|
9 |
if timestamp:
|
|
|
52 |
</div>
|
53 |
"""
|
54 |
|
55 |
+
def get_all_user_spaces():
|
56 |
+
"""Get all spaces for a user with pagination"""
|
57 |
+
all_spaces = []
|
58 |
+
offset = 0
|
59 |
+
|
60 |
+
while True:
|
61 |
+
url = f"https://huggingface.co/api/spaces"
|
62 |
+
params = {
|
63 |
+
"limit": LIMIT,
|
64 |
+
"offset": offset,
|
65 |
+
"full": "true"
|
66 |
+
}
|
67 |
+
headers = {
|
68 |
+
"Accept": "application/json",
|
69 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
70 |
+
}
|
71 |
|
72 |
+
try:
|
73 |
+
response = requests.get(url, params=params, headers=headers)
|
74 |
+
if response.status_code != 200:
|
75 |
+
print(f"Error: Status Code {response.status_code}")
|
76 |
+
break
|
77 |
+
|
78 |
+
spaces_data = response.json()
|
79 |
+
if not spaces_data:
|
80 |
+
break
|
81 |
+
|
82 |
+
# Filter spaces for the specific user
|
83 |
+
user_spaces = [space for space in spaces_data if space.get('id', '').startswith(f"{USERNAME}/")]
|
84 |
+
all_spaces.extend(user_spaces)
|
85 |
|
86 |
+
# If we got less than the limit, we've reached the end
|
87 |
+
if len(spaces_data) < LIMIT:
|
88 |
+
break
|
89 |
|
90 |
+
offset += LIMIT
|
91 |
+
|
92 |
+
except Exception as e:
|
93 |
+
print(f"Error fetching spaces: {e}")
|
94 |
+
break
|
95 |
+
|
96 |
+
return all_spaces
|
97 |
+
|
98 |
+
def get_user_spaces():
|
99 |
+
try:
|
100 |
+
# Get all spaces for the user
|
101 |
+
user_spaces = get_all_user_spaces()
|
102 |
|
103 |
if not user_spaces:
|
104 |
return f"""
|