Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,8 @@ import requests
|
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
|
5 |
-
#
|
6 |
-
USERNAME = "
|
7 |
|
8 |
def format_timestamp(timestamp):
|
9 |
if timestamp:
|
@@ -42,41 +42,42 @@ def get_space_card(space):
|
|
42 |
"""
|
43 |
|
44 |
def get_user_spaces():
|
45 |
-
#
|
46 |
response = requests.get(
|
47 |
-
|
|
|
48 |
headers={"Accept": "application/json"}
|
49 |
)
|
50 |
|
51 |
# ๋๋ฒ๊น
์ ์ํ ์ถ๋ ฅ
|
52 |
print(f"Status Code: {response.status_code}")
|
53 |
-
print(f"Response: {response.text}")
|
54 |
|
55 |
if response.status_code != 200:
|
56 |
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
57 |
|
58 |
try:
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
except Exception as e:
|
63 |
return f"Error parsing response: {str(e)}"
|
64 |
|
65 |
-
if not
|
66 |
return "No public Spaces found for this user."
|
67 |
|
68 |
# Create HTML grid layout with title and count
|
69 |
html_content = f"""
|
70 |
<div style='padding: 20px; background-color: #f5f5f5;'>
|
71 |
<div style='margin-bottom: 20px;'>
|
72 |
-
<p style='color: #666; margin: 0;'>Found {len(
|
73 |
</div>
|
74 |
<div style='
|
75 |
display: grid;
|
76 |
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
77 |
gap: 20px;
|
78 |
'>
|
79 |
-
{"".join(get_space_card(space) for space in
|
80 |
</div>
|
81 |
</div>
|
82 |
"""
|
|
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
|
5 |
+
# ํ
์คํธ๋ฅผ ์ํด ์๋ ค์ง ์ฌ์ฉ์๋ก ๋ณ๊ฒฝ
|
6 |
+
USERNAME = "multimodalart" # ๋ง์ public spaces๋ฅผ ๊ฐ์ง ์ฌ์ฉ์
|
7 |
|
8 |
def format_timestamp(timestamp):
|
9 |
if timestamp:
|
|
|
42 |
"""
|
43 |
|
44 |
def get_user_spaces():
|
45 |
+
# spaces ๊ฒ์ API ์ฌ์ฉ
|
46 |
response = requests.get(
|
47 |
+
"https://huggingface.co/api/spaces",
|
48 |
+
params={"search": USERNAME},
|
49 |
headers={"Accept": "application/json"}
|
50 |
)
|
51 |
|
52 |
# ๋๋ฒ๊น
์ ์ํ ์ถ๋ ฅ
|
53 |
print(f"Status Code: {response.status_code}")
|
54 |
+
print(f"Response: {response.text[:500]}...") # ์๋ต์ ์ฒ์ 500์๋ง ์ถ๋ ฅ
|
55 |
|
56 |
if response.status_code != 200:
|
57 |
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
58 |
|
59 |
try:
|
60 |
+
all_spaces = response.json()
|
61 |
+
# ํด๋น ์ฌ์ฉ์์ spaces๋ง ํํฐ๋ง
|
62 |
+
user_spaces = [space for space in all_spaces if space.get('author', '') == USERNAME]
|
63 |
except Exception as e:
|
64 |
return f"Error parsing response: {str(e)}"
|
65 |
|
66 |
+
if not user_spaces:
|
67 |
return "No public Spaces found for this user."
|
68 |
|
69 |
# Create HTML grid layout with title and count
|
70 |
html_content = f"""
|
71 |
<div style='padding: 20px; background-color: #f5f5f5;'>
|
72 |
<div style='margin-bottom: 20px;'>
|
73 |
+
<p style='color: #666; margin: 0;'>Found {len(user_spaces)} public spaces for {USERNAME}</p>
|
74 |
</div>
|
75 |
<div style='
|
76 |
display: grid;
|
77 |
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
78 |
gap: 20px;
|
79 |
'>
|
80 |
+
{"".join(get_space_card(space) for space in user_spaces)}
|
81 |
</div>
|
82 |
</div>
|
83 |
"""
|