File size: 6,093 Bytes
48d98a3
 
c0a1716
48d98a3
 
57be5f7
48d98a3
 
 
 
 
 
c0a1716
48d98a3
 
 
 
c0a1716
 
 
 
 
 
aaf6e49
c0a1716
aaf6e49
c0a1716
aaf6e49
c0a1716
 
 
 
 
 
48d98a3
 
 
c0a1716
 
48d98a3
 
 
c0a1716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48d98a3
 
c0a1716
 
 
 
 
 
 
 
 
 
 
 
eec2221
c0a1716
 
 
 
 
 
3f5e181
c0a1716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aaf6e49
c0a1716
 
 
 
 
 
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
import gradio as gr
import pandas as pd
from themes import IndonesiaTheme

def load_data(status_filter="All", keyword=""):
    df = pd.read_csv("https://huggingface.co/datasets/Deddy/leaderboard-dataset/raw/main/leaderboard.csv")

    if status_filter != "All":
        df = df[df['status'].str.contains(status_filter, case=False, na=False)]
    if keyword.strip():
        df = df[df['name'].str.contains(keyword, case=False, na=False)]

    df = df.sort_values("likes", ascending=False).head(100).reset_index(drop=True)

    # Kolom Visit tetap
    df["πŸ”— Visit"] = df["link"].apply(lambda url: f"<a href='{url}' target='_blank'>🌐 Visit</a>")

    # Kolom Name: bold, warna emas untuk top 10, emoji piala untuk top 3
    def decorate_name(row):
        i = row.name + 1  # row.name = index mulai dari 0
        name = f"{row['name']}"
        medal = ""
        if i == 1:
            medal = "πŸ‘‘  "
        elif i == 2:
            medal = "πŸ†  "
        elif i == 3:
            medal = "πŸ…  "
        if i <= 10:
            # Emas (#FFD700)
            return f"<span style='color:#FFD700; font-weight:bold'>{medal}{name}</span>"
        return f"<b>{name}</b>"

    df["decorated_name"] = df.apply(decorate_name, axis=1)

    # Kolom Status: warna dinamis
    def format_status(s):
        if isinstance(s, str) and "running" in s.lower():
            return f"<span style='color:lime;font-weight:bold'>{s}</span>"
        else:
            return f"<span style='color:red;font-weight:bold'>{s}</span>"

    df["status_fmt"] = df["status"].apply(format_status)

    # Susun ulang kolom: No, Name, dst
    df_final = pd.DataFrame()
    df_final["No"] = range(1, len(df) + 1)
    df_final["πŸ“› Name"] = df["decorated_name"]
    df_final["πŸ‘€ Author"] = df["author"]
    df_final["πŸ“ Description"] = df["desc"]
    df_final["❀️ Likes"] = df["likes"]
    df_final["πŸ•’ Updated"] = df["updated"]
    df_final["βš™οΈ Status"] = df["status_fmt"]
    df_final["πŸ”— Visit"] = df["πŸ”— Visit"]

    return df_final

def render_html_table(status, keyword):
    df = load_data(status, keyword)
    html_table = df.to_html(escape=False, index=False, classes="styled-table")
    return f"""
    <style>
    .styled-table {{
        width: 100%;
        border-collapse: collapse;
        font-size: 1.02rem;
        font-family: 'Segoe UI', sans-serif;
        background-color: #191a22;
        color: #e0e0e0;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 4px 24px #00000030;
    }}
    .styled-table th {{
        background: linear-gradient(90deg, #5f0a87 0%, #a4508b 100%);
        text-align: left;
        padding: 12px;
        border-bottom: 3px solid #FFD70080;
        font-size: 1.08rem;
        letter-spacing: 1px;
        color: #ffe29f;
    }}
    .styled-table td {{
        padding: 12px 10px;
        border-bottom: 1px solid #222;
        vertical-align: top;
        font-size: 0.97rem;
    }}
    .styled-table tr:nth-child(even) td {{
        background-color: #1e2030;
    }}
    .styled-table tr:hover td {{
        background-color: #343651;
        transition: background 0.2s;
    }}
    .styled-table td a {{
        color: #FFBF00;
        text-decoration: none;
        font-weight: bold;
        transition: color 0.2s;
    }}
    .styled-table td a:hover {{
        color: #fff700;
    }}
    .styled-table td:first-child {{
        text-align: center;
        font-weight: bold;
        color: #FFD700;
        background: linear-gradient(180deg, #24243e 0%, #191a22 100%);
        border-right: 2px solid #FFD70022;
    }}
    </style>
    {html_table}
    """

css = ""  # CSS sudah di-inject via render_html_table

with gr.Blocks(theme=IndonesiaTheme()) as demo:
    gr.Markdown("""
    <div style='
        background: linear-gradient(90deg, #5f0a87 0%, #a4508b 100%);
        color: #fffde4;
        padding: 36px 8px 22px 8px;
        border-radius: 20px;
        text-align:center;
        font-size:2.0rem;
        font-weight:bold;
        letter-spacing: 1.5px;
        margin-bottom: 16px;
        box-shadow: 0 6px 48px #00000044;'>
    πŸš€ <span style='color:#FFD700'>100 SPACES TERPOPULER HUGGING FACE! - ⏰ HOURLY UPDATE!!</span> πŸš€<br>
    <span style='font-size:1.16rem; font-weight:500; letter-spacing:1px;'>Tersaring dari ribuan aplikasi, hanya yang terbaik, terfavorit, dan paling inovatif yang masuk leaderboard ini!<br>
    Siapkah kamu menemukan Space AI idamanmu hari ini? <span style='color:#ffe29f'>✨</span></span>
    </div>
    """)
    with gr.Row():
        with gr.Column(elem_id="col-left"):
            status_choice = gr.Dropdown(["All", "Running", "Runtime", "Build", "Sleeping"],
                                        label="πŸŽ›οΈ Filter Status", value="All")
        with gr.Column(elem_id="col-mid"):
            keyword_input = gr.Textbox(label="πŸ” Search by Name",
                                       placeholder="e.g. llama, tts, image")

    with gr.Column(elem_id="col-bott"):
        output_table = gr.HTML(label="Leaderboard Table")
        gr.Markdown("""
        <div style='
            color:#693f00;
            padding: 24px 6px 18px 6px;
            border-radius: 18px;
            font-size: 1.12rem;
            text-align:center;
            margin-top:18px;
            box-shadow: 0 3px 24px #FFD70033;
            font-weight:bold;
        '>
        πŸŽ‰ <b>Selamat untuk seluruh Space yang masuk 100 besar! Kalian membanggakan komunitas AI Dunia! πŸš€πŸ”₯</b><br>
        <span style='font-size:1.55rem;'>Terus berkarya, jangan berhenti berinovasi! πŸ’ͺ🌟πŸ₯³</span>
        </div>
        """)
    gr.Button("πŸ”„ Refresh").click(fn=render_html_table,
                                  inputs=[status_choice, keyword_input], outputs=output_table)

    gr.Markdown("#### Made with ❀️ by Deddy | ⏰ HF Most Popular Space Leaderboard", elem_id="footer")

    # Inisialisasi tampilan awal
    output_table.value = render_html_table("All", "")

# Jalankan aplikasi Gradio (local/web)
demo.queue(api_open=False).launch(show_api=False)