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:
|
@@ -13,7 +13,6 @@ def format_timestamp(timestamp):
|
|
13 |
|
14 |
def get_space_card(space):
|
15 |
"""Generate HTML card for a space"""
|
16 |
-
space_name = space["id"].split('/')[-1] if 'id' in space else space.get('name', 'Unknown')
|
17 |
return f"""
|
18 |
<div style='border: 1px solid #ddd; padding: 15px; margin: 10px; border-radius: 8px;
|
19 |
background-color: white; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
|
@@ -21,68 +20,83 @@ def get_space_card(space):
|
|
21 |
onmouseover='this.style.transform="scale(1.02)"'
|
22 |
onmouseout='this.style.transform="scale(1)"'>
|
23 |
<h3 style='color: #2d2d2d; margin: 0 0 10px 0;'>
|
24 |
-
<a href='
|
25 |
style='text-decoration: none; color: #2d2d2d;'>
|
26 |
-
{
|
27 |
</a>
|
28 |
</h3>
|
29 |
-
<p style='margin: 5px 0;'
|
30 |
-
|
31 |
-
|
32 |
-
</p>
|
33 |
-
<p style='margin: 5px 0;'><strong>SDK:</strong> {space.get("sdk", "N/A")}</p>
|
34 |
-
<div style='margin-top: 10px;'>
|
35 |
-
<a href='https://huggingface.co/spaces/{USERNAME}/{space_name}' target='_blank'
|
36 |
style='background-color: #0084ff; color: white; padding: 5px 10px;
|
37 |
-
border-radius: 5px; text-decoration: none;
|
38 |
View Space
|
39 |
</a>
|
|
|
|
|
|
|
40 |
</div>
|
41 |
</div>
|
42 |
"""
|
43 |
|
44 |
def get_user_spaces():
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
print(f"Response: {response.text[:500]}...") # ์๋ต์ ์ฒ์ 500์๋ง ์ถ๋ ฅ
|
55 |
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
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 |
-
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
</div>
|
82 |
-
|
83 |
-
"""
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# Creating the Gradio interface
|
88 |
app = gr.Interface(
|
|
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
|
5 |
+
# ํ
์คํธ๋ฅผ ์ํด Gradio ๊ณต์ ๊ณ์ ์ผ๋ก ๋ณ๊ฒฝ
|
6 |
+
USERNAME = "gradio"
|
7 |
|
8 |
def format_timestamp(timestamp):
|
9 |
if timestamp:
|
|
|
13 |
|
14 |
def get_space_card(space):
|
15 |
"""Generate HTML card for a space"""
|
|
|
16 |
return f"""
|
17 |
<div style='border: 1px solid #ddd; padding: 15px; margin: 10px; border-radius: 8px;
|
18 |
background-color: white; box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
|
|
|
20 |
onmouseover='this.style.transform="scale(1.02)"'
|
21 |
onmouseout='this.style.transform="scale(1)"'>
|
22 |
<h3 style='color: #2d2d2d; margin: 0 0 10px 0;'>
|
23 |
+
<a href='{space.get("url", "#")}' target='_blank'
|
24 |
style='text-decoration: none; color: #2d2d2d;'>
|
25 |
+
{space.get('title', 'Unnamed Space')}
|
26 |
</a>
|
27 |
</h3>
|
28 |
+
<p style='margin: 5px 0; color: #666;'>{space.get('description', 'No description available')}</p>
|
29 |
+
<div style='margin-top: 10px; display: flex; justify-content: space-between; align-items: center;'>
|
30 |
+
<a href='{space.get("url", "#")}' target='_blank'
|
|
|
|
|
|
|
|
|
31 |
style='background-color: #0084ff; color: white; padding: 5px 10px;
|
32 |
+
border-radius: 5px; text-decoration: none;'>
|
33 |
View Space
|
34 |
</a>
|
35 |
+
<span style='color: #666;'>
|
36 |
+
โค๏ธ {space.get('likes', 0)}
|
37 |
+
</span>
|
38 |
</div>
|
39 |
</div>
|
40 |
"""
|
41 |
|
42 |
def get_user_spaces():
|
43 |
+
# Hugging Face search API ์ฌ์ฉ
|
44 |
+
url = "https://huggingface.co/api/spaces"
|
45 |
+
params = {
|
46 |
+
"author": USERNAME,
|
47 |
+
"limit": 100,
|
48 |
+
"full": True
|
49 |
+
}
|
50 |
+
|
51 |
+
try:
|
52 |
+
response = requests.get(url, params=params)
|
53 |
+
print(f"Status Code: {response.status_code}") # ๋๋ฒ๊น
์ฉ
|
54 |
+
print(f"URL: {response.url}") # ๋๋ฒ๊น
์ฉ
|
55 |
+
print(f"Response: {response.text[:500]}...") # ๋๋ฒ๊น
์ฉ
|
56 |
|
57 |
+
if response.status_code != 200:
|
58 |
+
return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"
|
|
|
59 |
|
60 |
+
spaces = response.json()
|
61 |
+
|
62 |
+
if not spaces:
|
63 |
+
# ๋ค๋ฅธ API ์๋ํฌ์ธํธ ์๋
|
64 |
+
alternate_url = f"https://huggingface.co/api/spaces/{USERNAME}"
|
65 |
+
response = requests.get(alternate_url)
|
66 |
+
spaces = response.json() if response.status_code == 200 else []
|
67 |
|
68 |
+
if not spaces:
|
69 |
+
return "No public Spaces found for this user."
|
|
|
|
|
|
|
|
|
70 |
|
71 |
+
if not isinstance(spaces, list):
|
72 |
+
spaces = [spaces]
|
73 |
|
74 |
+
# Create HTML grid layout
|
75 |
+
html_content = f"""
|
76 |
+
<div style='padding: 20px; background-color: #f5f5f5;'>
|
77 |
+
<div style='margin-bottom: 20px;'>
|
78 |
+
<p style='color: #666; margin: 0;'>Found {len(spaces)} public spaces for {USERNAME}</p>
|
79 |
+
</div>
|
80 |
+
<div style='
|
81 |
+
display: grid;
|
82 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
83 |
+
gap: 20px;
|
84 |
+
'>
|
85 |
+
{"".join(get_space_card({
|
86 |
+
'title': space.get('id', '').split('/')[-1],
|
87 |
+
'description': space.get('description', ''),
|
88 |
+
'url': f"https://huggingface.co/spaces/{space.get('id', '')}",
|
89 |
+
'likes': space.get('likes', 0)
|
90 |
+
}) for space in spaces)}
|
91 |
+
</div>
|
92 |
</div>
|
93 |
+
"""
|
|
|
94 |
|
95 |
+
return html_content
|
96 |
+
|
97 |
+
except Exception as e:
|
98 |
+
print(f"Error: {str(e)}") # ๋๋ฒ๊น
์ฉ
|
99 |
+
return f"Error occurred: {str(e)}"
|
100 |
|
101 |
# Creating the Gradio interface
|
102 |
app = gr.Interface(
|