Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import gradio as gr
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
USERNAME = "openfree"
|
| 6 |
-
LIMIT = 100 # ํ ๋ฒ์ ๊ฐ์ ธ์ฌ ์ต๋ spaces ์
|
| 7 |
|
| 8 |
def format_timestamp(timestamp):
|
| 9 |
if timestamp:
|
|
@@ -52,53 +51,25 @@ def get_space_card(space):
|
|
| 52 |
</div>
|
| 53 |
"""
|
| 54 |
|
| 55 |
-
def
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 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 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
|
| 96 |
-
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
#
|
| 101 |
-
user_spaces =
|
| 102 |
|
| 103 |
if not user_spaces:
|
| 104 |
return f"""
|
|
@@ -141,20 +112,16 @@ def get_user_spaces():
|
|
| 141 |
</div>
|
| 142 |
"""
|
| 143 |
|
| 144 |
-
# Creating the Gradio interface
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
max-width: 100% !important;
|
| 155 |
-
}
|
| 156 |
-
"""
|
| 157 |
-
)
|
| 158 |
|
| 159 |
# Launch the Gradio app
|
| 160 |
if __name__ == "__main__":
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
USERNAME = "openfree"
|
|
|
|
| 6 |
|
| 7 |
def format_timestamp(timestamp):
|
| 8 |
if timestamp:
|
|
|
|
| 51 |
</div>
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
def get_user_spaces():
|
| 55 |
+
url = f"https://huggingface.co/api/spaces?author={USERNAME}&limit=500" # API ์ฟผ๋ฆฌ ์์
|
| 56 |
+
headers = {
|
| 57 |
+
"Accept": "application/json",
|
| 58 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
| 59 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
try:
|
| 62 |
+
response = requests.get(url, headers=headers)
|
| 63 |
+
print(f"Status Code: {response.status_code}")
|
| 64 |
+
print(f"Response length: {len(response.json()) if response.status_code == 200 else 'N/A'}")
|
| 65 |
|
| 66 |
+
if response.status_code != 200:
|
| 67 |
+
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
| 68 |
|
| 69 |
+
spaces_data = response.json()
|
| 70 |
+
|
| 71 |
+
# Filter spaces for the specific user (although API should already filter)
|
| 72 |
+
user_spaces = spaces_data
|
| 73 |
|
| 74 |
if not user_spaces:
|
| 75 |
return f"""
|
|
|
|
| 112 |
</div>
|
| 113 |
"""
|
| 114 |
|
| 115 |
+
# Creating the Gradio interface with automatic refresh
|
| 116 |
+
with gr.Blocks() as app:
|
| 117 |
+
html_output = gr.HTML()
|
| 118 |
+
|
| 119 |
+
# ์์ํ ๋ ์๋์ผ๋ก ๋ฐ์ดํฐ ๋ก๋
|
| 120 |
+
gr.on(
|
| 121 |
+
triggers=[], # ๋น triggers๋ ํ์ด์ง ๋ก๋ ์ ์คํ์ ์๋ฏธ
|
| 122 |
+
fn=get_user_spaces,
|
| 123 |
+
outputs=[html_output],
|
| 124 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
# Launch the Gradio app
|
| 127 |
if __name__ == "__main__":
|