File size: 9,873 Bytes
f61429a
 
514cd38
8c9d551
f61429a
4bd3dc3
059f849
514cd38
 
 
 
 
 
86994a7
 
 
 
 
 
 
 
 
 
 
8c9d551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e40f7e
c5437a5
 
 
 
 
 
3e40f7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9d551
3e40f7e
8c9d551
3e40f7e
 
 
 
 
 
 
 
 
 
 
 
 
 
514cd38
3e40f7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5437a5
059f849
c5437a5
059f849
3e40f7e
059f849
3e40f7e
 
 
 
 
 
 
 
 
 
 
c5437a5
3e40f7e
 
 
 
c5437a5
3e40f7e
 
 
 
 
 
 
 
 
 
 
 
 
 
d51b0b3
3e40f7e
 
c5437a5
d51b0b3
514cd38
 
 
6d77ca6
49340e2
6d77ca6
 
 
 
a7a154b
6d77ca6
 
 
 
a7a154b
6d77ca6
 
a7a154b
6d77ca6
86994a7
 
 
 
 
 
bf508de
 
 
 
 
 
 
 
 
 
c5437a5
 
bf508de
 
 
c5437a5
 
bf508de
 
 
 
 
 
8c9d551
bf508de
d51b0b3
060cebe
514cd38
bf508de
060cebe
bf508de
c5437a5
bf508de
 
 
 
c5437a5
bf508de
 
f61429a
49340e2
 
 
 
 
f61429a
514cd38
49340e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import requests
import gradio as gr
from datetime import datetime
import random

USERNAME = "openfree"

def format_timestamp(timestamp):
    if timestamp:
        dt = datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
        return dt.strftime('%Y-%m-%d %H:%M')
    return 'N/A'

def should_exclude_space(space_name):
    """νŠΉμ • 슀페이슀λ₯Ό μ œμ™Έν•˜λŠ” ν•„ν„° ν•¨μˆ˜"""
    exclude_keywords = [
        'mixgen3', 'ginid', 'mouse', 'flxtrainlora',
        'vidslicegpu', 'stickimg', 'ultpixgen', 'SORA',
        'badassgi', 'newsplus', 'chargen', 'news',
        'testhtml'
    ]
    
    return any(keyword.lower() in space_name.lower() for keyword in exclude_keywords)

def get_pastel_color(index):
    """Generate unique pastel colors based on index"""
    pastel_colors = [
        '#FFE6E6',  # μ—°ν•œ 뢄홍
        '#FFE6FF',  # μ—°ν•œ 보라
        '#E6E6FF',  # μ—°ν•œ νŒŒλž‘
        '#E6FFFF',  # μ—°ν•œ ν•˜λŠ˜
        '#E6FFE6',  # μ—°ν•œ 초둝
        '#FFFFE6',  # μ—°ν•œ λ…Έλž‘
        '#FFF0E6',  # μ—°ν•œ μ£Όν™©
        '#F0E6FF',  # μ—°ν•œ 라벀더
        '#FFE6F0',  # μ—°ν•œ 둜즈
        '#E6FFF0',  # μ—°ν•œ 민트
        '#F0FFE6',  # μ—°ν•œ λΌμž„
        '#FFE6EB',  # μ—°ν•œ μ½”λž„
        '#E6EBFF',  # μ—°ν•œ νΌν”ŒλΈ”λ£¨
        '#FFE6F5',  # μ—°ν•œ 핑크
        '#E6FFF5',  # μ—°ν•œ ν„°μ½”μ΄μ¦ˆ
        '#F5E6FF',  # μ—°ν•œ λͺ¨λΈŒ
        '#FFE6EC',  # μ—°ν•œ μ‚΄λͺ¬
        '#E6FFEC',  # μ—°ν•œ μŠ€ν”„λ§κ·Έλ¦°
        '#ECE6FF',  # μ—°ν•œ νŽ˜λ¦¬μœ™ν΄
        '#FFE6F7',  # μ—°ν•œ 맀그놀리아
    ]
    return pastel_colors[index % len(pastel_colors)]

def get_space_card(space, index):
    """Generate HTML card for a space with colorful design and lots of emojis"""
    space_id = space.get('id', '')
    space_name = space_id.split('/')[-1]
    likes = space.get('likes', 0)
    created_at = format_timestamp(space.get('createdAt'))
    sdk = space.get('sdk', 'N/A')
    
    # SDK별 이λͺ¨μ§€ 및 κ΄€λ ¨ 이λͺ¨μ§€ μ„ΈνŠΈ
    sdk_emoji_sets = {
        'gradio': {
            'main': '🎨',
            'related': ['πŸ–ΌοΈ', '🎭', 'πŸŽͺ', '🎠', '🎑', '🎒', '🎯', '🎲', '🎰', '🎳']
        },
        'streamlit': {
            'main': '⚑',
            'related': ['πŸ’«', '✨', '⭐', '🌟', 'πŸ’₯', '⚑', 'πŸ”₯', '🌈', 'πŸŽ†', 'πŸŽ‡']
        },
        'docker': {
            'main': '🐳',
            'related': ['πŸ‹', '🌊', '🌍', '🚒', '⛴️', 'πŸ›₯️', '🐠', '🐑', '🦈', '🐬']
        },
        'static': {
            'main': 'πŸ“„',
            'related': ['πŸ“', 'πŸ“°', 'πŸ“‘', 'πŸ—‚οΈ', 'πŸ“', 'πŸ“‚', 'πŸ“š', 'πŸ“–', 'πŸ“’', 'πŸ“”']
        },
        'panel': {
            'main': 'πŸ“Š',
            'related': ['πŸ“ˆ', 'πŸ“‰', 'πŸ’Ή', 'πŸ“‹', 'πŸ“Œ', 'πŸ“', 'πŸ—ΊοΈ', '🎯', 'πŸ“', 'πŸ“']
        },
        'N/A': {
            'main': 'πŸ”§',
            'related': ['πŸ”¨', 'βš’οΈ', 'πŸ› οΈ', 'βš™οΈ', 'πŸ”©', '⛏️', '⚑', 'πŸ”Œ', 'πŸ’‘', 'πŸ”‹']
        }
    }
    
    # SDK에 λ”°λ₯Έ 이λͺ¨μ§€ 선택
    sdk_lower = sdk.lower()
    bg_color = get_pastel_color(index)  # 인덱슀 기반 색상 선택
    emoji_set = sdk_emoji_sets.get(sdk_lower, sdk_emoji_sets['N/A'])
    main_emoji = emoji_set['main']
    
    # λžœλ€ν•˜κ²Œ 3개의 κ΄€λ ¨ 이λͺ¨μ§€ 선택
    decorative_emojis = random.sample(emoji_set['related'], 3)
    
    # μΆ”κ°€ μž₯μ‹μš© 이λͺ¨μ§€
    general_emojis = ['πŸš€', 'πŸ’«', '⭐', '🌟', '✨', 'πŸ’₯', 'πŸ”₯', '🌈', '🎯', '🎨', 
                      '🎭', 'πŸŽͺ', '🎒', '🎑', '🎠', 'πŸŽͺ', '🎭', '🎨', '🎯', '🎲']
    random_emojis = random.sample(general_emojis, 3)
    
    # μ’‹μ•„μš” μˆ˜μ— λ”°λ₯Έ ν•˜νŠΈ 이λͺ¨μ§€
    heart_emoji = '❀️' if likes > 100 else 'πŸ’–' if likes > 50 else 'πŸ’' if likes > 10 else '🀍'
    
    return f"""
    <div style='border: none; 
                padding: 25px; 
                margin: 15px; 
                border-radius: 20px; 
                background-color: {bg_color};
                box-shadow: 0 4px 15px rgba(0,0,0,0.1);
                transition: all 0.3s ease-in-out;
                position: relative;
                overflow: hidden;'
         onmouseover='this.style.transform="translateY(-5px) scale(1.02)"; this.style.boxShadow="0 8px 25px rgba(0,0,0,0.15)"'
         onmouseout='this.style.transform="translateY(0) scale(1)"; this.style.boxShadow="0 4px 15px rgba(0,0,0,0.1)"'>
        <div style='position: absolute; top: -15px; right: -15px; font-size: 100px; opacity: 0.1;'>
            {main_emoji}
        </div>
        <div style='position: absolute; top: 10px; right: 10px; font-size: 20px;'>
            {decorative_emojis[0]}
        </div>
        <div style='position: absolute; bottom: 10px; left: 10px; font-size: 20px;'>
            {decorative_emojis[1]}
        </div>
        <div style='position: absolute; top: 50%; right: 10px; font-size: 20px;'>
            {decorative_emojis[2]}
        </div>
        <h3 style='color: #2d2d2d; 
                   margin: 0 0 20px 0; 
                   font-size: 1.4em;
                   display: flex;
                   align-items: center;
                   gap: 10px;'>
            <span style='font-size: 1.3em'>{random_emojis[0]}</span>
            <a href='https://huggingface.co/spaces/{space_id}' target='_blank' 
               style='text-decoration: none; color: #2d2d2d;'>
                {space_name}
            </a>
            <span style='font-size: 1.3em'>{random_emojis[1]}</span>
        </h3>
        <div style='margin: 15px 0; color: #444; background: rgba(255,255,255,0.5); 
                    padding: 15px; border-radius: 12px;'>
            <p style='margin: 8px 0;'>
                <strong>SDK:</strong> {main_emoji} {sdk} {decorative_emojis[0]}
            </p>
            <p style='margin: 8px 0;'>
                <strong>Created:</strong> πŸ“… {created_at} ⏰
            </p>
            <p style='margin: 8px 0;'>
                <strong>Likes:</strong> {heart_emoji} {likes} {random_emojis[2]}
            </p>
        </div>
        <div style='margin-top: 20px; 
                    display: flex; 
                    justify-content: space-between; 
                    align-items: center;'>
            <a href='https://huggingface.co/spaces/{space_id}' target='_blank' 
               style='background: linear-gradient(45deg, #0084ff, #00a3ff);
                      color: white; 
                      padding: 10px 20px; 
                      border-radius: 15px; 
                      text-decoration: none; 
                      display: inline-flex;
                      align-items: center;
                      gap: 8px;
                      font-weight: 500; 
                      transition: all 0.3s;
                      box-shadow: 0 2px 8px rgba(0,132,255,0.3);'
               onmouseover='this.style.transform="scale(1.05)"; this.style.boxShadow="0 4px 12px rgba(0,132,255,0.4)"'
               onmouseout='this.style.transform="scale(1)"; this.style.boxShadow="0 2px 8px rgba(0,132,255,0.3)"'>
                <span>View Space</span> πŸš€ {random_emojis[0]}
            </a>
            <span style='color: #666; font-size: 0.9em; opacity: 0.7;'>
                πŸ†” {space_id} {decorative_emojis[2]}
            </span>
        </div>
    </div>
    """

def get_user_spaces():
    url = f"https://huggingface.co/api/spaces?author={USERNAME}&limit=500"
    headers = {
        "Accept": "application/json",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
    }

    try:
        response = requests.get(url, headers=headers)
        print(f"Status Code: {response.status_code}")
        print(f"Response length: {len(response.json()) if response.status_code == 200 else 'N/A'}")

        if response.status_code != 200:
            return f"Error: Failed to fetch spaces (Status Code: {response.status_code})"

        spaces_data = response.json()
        
        # μ œμ™Έν•  슀페이슀 필터링
        user_spaces = [
            space for space in spaces_data 
            if not should_exclude_space(space.get('id', '').split('/')[-1])
        ]

        if not user_spaces:
            return f"""
            <div style='padding: 20px; text-align: center; color: #666;'>
                <h2>No public Spaces found for user: {USERNAME}</h2>
                <p>Try visiting: <a href='https://huggingface.co/{USERNAME}' target='_blank'>
                    https://huggingface.co/{USERNAME}</a></p>
            </div>
            """

        user_spaces.sort(key=lambda x: x.get('likes', 0), reverse=True)

        html_content = f"""
        <div style='padding: 20px; background-color: #f5f5f5;'>
            <div style='margin-bottom: 20px;'>
                <h2 style='color: #333; margin: 0 0 10px 0;'>Spaces by {USERNAME}</h2>
                <p style='color: #666; margin: 0;'>Found {len(user_spaces)} public spaces</p>
            </div>
            <div style='
                display: grid;
                grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
                gap: 20px;
            '>
                {"".join(get_space_card(space, idx) for idx, space in enumerate(user_spaces))}
            </div>
        </div>
        """

        return html_content

    except Exception as e:
        print(f"Error: {str(e)}")
        return f"""
        <div style='padding: 20px; text-align: center; color: #666;'>
            <h2>Error occurred while fetching spaces</h2>
            <p>Error details: {str(e)}</p>
            <p>Please try again later.</p>
        </div>
        """

# Creating the Gradio interface
demo = gr.Blocks()

with demo:
    html_output = gr.HTML(value=get_user_spaces())  # 초기 λ‘œλ“œ μ‹œ 직접 ν•¨μˆ˜ 호좜

if __name__ == "__main__":
    demo.launch()