Update app.py
Browse files
app.py
CHANGED
|
@@ -1,145 +1,170 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import sqlite3
|
| 3 |
import pandas as pd
|
| 4 |
-
from themes import IndonesiaTheme
|
| 5 |
-
|
| 6 |
-
DB_PATH = "spaces.db"
|
| 7 |
|
| 8 |
def load_data(status_filter="All", keyword=""):
|
| 9 |
-
# conn = sqlite3.connect(DB_PATH)
|
| 10 |
-
# query = "SELECT name, author, desc, likes, updated, status, link FROM spaces"
|
| 11 |
-
# df = pd.read_sql_query(query, conn)
|
| 12 |
-
# df = pd.read_csv("https://huggingface.co/datasets/username/leaderboard-dataset/raw/main/leaderboard.csv")
|
| 13 |
-
# conn.close()
|
| 14 |
-
|
| 15 |
df = pd.read_csv("https://huggingface.co/datasets/Deddy/leaderboard-dataset/raw/main/leaderboard.csv")
|
| 16 |
|
| 17 |
if status_filter != "All":
|
| 18 |
df = df[df['status'].str.contains(status_filter, case=False, na=False)]
|
| 19 |
-
|
| 20 |
if keyword.strip():
|
| 21 |
df = df[df['name'].str.contains(keyword, case=False, na=False)]
|
| 22 |
|
| 23 |
-
df = df.sort_values("likes", ascending=False).head(
|
| 24 |
|
| 25 |
# Kolom Visit tetap
|
| 26 |
df["π Visit"] = df["link"].apply(lambda url: f"<a href='{url}' target='_blank'>π Visit</a>")
|
| 27 |
|
| 28 |
-
# Kolom Name: bold
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Kolom Status: warna dinamis
|
| 32 |
def format_status(s):
|
| 33 |
-
if "running" in s.lower():
|
| 34 |
-
return f"<span style='color:
|
| 35 |
else:
|
| 36 |
return f"<span style='color:red;font-weight:bold'>{s}</span>"
|
| 37 |
|
| 38 |
-
df["
|
| 39 |
-
|
| 40 |
-
# Susun ulang kolom
|
| 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 |
-
# === Gradio App UI ===
|
| 85 |
with gr.Blocks(theme=IndonesiaTheme()) as demo:
|
| 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 |
-
status_choice.change(fn=render_html_table, inputs=[status_choice, keyword_input], outputs=output_table)
|
| 139 |
-
keyword_input.change(fn=render_html_table, inputs=[status_choice, keyword_input], outputs=output_table)
|
| 140 |
-
gr.Button("π Refresh").click(fn=render_html_table,
|
| 141 |
-
inputs=[status_choice, keyword_input], outputs=output_table)
|
| 142 |
-
|
| 143 |
-
gr.Markdown("#### Made with β€οΈ by Deddy | HuggingFace Leaderboard Mirror", elem_id="footer")
|
| 144 |
-
|
| 145 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
from themes import IndonesiaTheme
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def load_data(status_filter="All", keyword=""):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
df = pd.read_csv("https://huggingface.co/datasets/Deddy/leaderboard-dataset/raw/main/leaderboard.csv")
|
| 7 |
|
| 8 |
if status_filter != "All":
|
| 9 |
df = df[df['status'].str.contains(status_filter, case=False, na=False)]
|
|
|
|
| 10 |
if keyword.strip():
|
| 11 |
df = df[df['name'].str.contains(keyword, case=False, na=False)]
|
| 12 |
|
| 13 |
+
df = df.sort_values("likes", ascending=False).head(100).reset_index(drop=True)
|
| 14 |
|
| 15 |
# Kolom Visit tetap
|
| 16 |
df["π Visit"] = df["link"].apply(lambda url: f"<a href='{url}' target='_blank'>π Visit</a>")
|
| 17 |
|
| 18 |
+
# Kolom Name: bold, warna emas untuk top 10, emoji piala untuk top 3
|
| 19 |
+
def decorate_name(row):
|
| 20 |
+
i = row.name + 1 # row.name = index mulai dari 0
|
| 21 |
+
name = f"{row['name']}"
|
| 22 |
+
medal = ""
|
| 23 |
+
if i == 1:
|
| 24 |
+
medal = "π "
|
| 25 |
+
elif i == 2:
|
| 26 |
+
medal = "π "
|
| 27 |
+
elif i == 3:
|
| 28 |
+
medal = "π
"
|
| 29 |
+
if i <= 10:
|
| 30 |
+
# Emas (#FFD700)
|
| 31 |
+
return f"<span style='color:#FFD700; font-weight:bold'>{medal}{name}</span>"
|
| 32 |
+
return f"<b>{name}</b>"
|
| 33 |
+
|
| 34 |
+
df["decorated_name"] = df.apply(decorate_name, axis=1)
|
| 35 |
|
| 36 |
# Kolom Status: warna dinamis
|
| 37 |
def format_status(s):
|
| 38 |
+
if isinstance(s, str) and "running" in s.lower():
|
| 39 |
+
return f"<span style='color:lime;font-weight:bold'>{s}</span>"
|
| 40 |
else:
|
| 41 |
return f"<span style='color:red;font-weight:bold'>{s}</span>"
|
| 42 |
|
| 43 |
+
df["status_fmt"] = df["status"].apply(format_status)
|
| 44 |
+
|
| 45 |
+
# Susun ulang kolom: No, Name, dst
|
| 46 |
+
df_final = pd.DataFrame()
|
| 47 |
+
df_final["No"] = range(1, len(df) + 1)
|
| 48 |
+
df_final["π Name"] = df["decorated_name"]
|
| 49 |
+
df_final["π€ Author"] = df["author"]
|
| 50 |
+
df_final["π Description"] = df["desc"]
|
| 51 |
+
df_final["β€οΈ Likes"] = df["likes"]
|
| 52 |
+
df_final["π Updated"] = df["updated"]
|
| 53 |
+
df_final["βοΈ Status"] = df["status_fmt"]
|
| 54 |
+
df_final["π Visit"] = df["π Visit"]
|
| 55 |
+
|
| 56 |
+
return df_final
|
| 57 |
+
|
| 58 |
+
def render_html_table(status, keyword):
|
| 59 |
+
df = load_data(status, keyword)
|
| 60 |
+
html_table = df.to_html(escape=False, index=False, classes="styled-table")
|
| 61 |
+
return f"""
|
| 62 |
+
<style>
|
| 63 |
+
.styled-table {{
|
| 64 |
+
width: 100%;
|
| 65 |
+
border-collapse: collapse;
|
| 66 |
+
font-size: 1.02rem;
|
| 67 |
+
font-family: 'Segoe UI', sans-serif;
|
| 68 |
+
background-color: #191a22;
|
| 69 |
+
color: #e0e0e0;
|
| 70 |
+
border-radius: 16px;
|
| 71 |
+
overflow: hidden;
|
| 72 |
+
box-shadow: 0 4px 24px #00000030;
|
| 73 |
+
}}
|
| 74 |
+
.styled-table th {{
|
| 75 |
+
background: linear-gradient(90deg, #5f0a87 0%, #a4508b 100%);
|
| 76 |
+
text-align: left;
|
| 77 |
+
padding: 12px;
|
| 78 |
+
border-bottom: 3px solid #FFD70080;
|
| 79 |
+
font-size: 1.08rem;
|
| 80 |
+
letter-spacing: 1px;
|
| 81 |
+
color: #ffe29f;
|
| 82 |
+
}}
|
| 83 |
+
.styled-table td {{
|
| 84 |
+
padding: 12px 10px;
|
| 85 |
+
border-bottom: 1px solid #222;
|
| 86 |
+
vertical-align: top;
|
| 87 |
+
font-size: 0.97rem;
|
| 88 |
+
}}
|
| 89 |
+
.styled-table tr:nth-child(even) td {{
|
| 90 |
+
background-color: #1e2030;
|
| 91 |
+
}}
|
| 92 |
+
.styled-table tr:hover td {{
|
| 93 |
+
background-color: #343651;
|
| 94 |
+
transition: background 0.2s;
|
| 95 |
+
}}
|
| 96 |
+
.styled-table td a {{
|
| 97 |
+
color: #FFBF00;
|
| 98 |
+
text-decoration: none;
|
| 99 |
+
font-weight: bold;
|
| 100 |
+
transition: color 0.2s;
|
| 101 |
+
}}
|
| 102 |
+
.styled-table td a:hover {{
|
| 103 |
+
color: #fff700;
|
| 104 |
+
}}
|
| 105 |
+
.styled-table td:first-child {{
|
| 106 |
+
text-align: center;
|
| 107 |
+
font-weight: bold;
|
| 108 |
+
color: #FFD700;
|
| 109 |
+
background: linear-gradient(180deg, #24243e 0%, #191a22 100%);
|
| 110 |
+
border-right: 2px solid #FFD70022;
|
| 111 |
+
}}
|
| 112 |
+
</style>
|
| 113 |
+
{html_table}
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
css = "" # CSS sudah di-inject via render_html_table
|
| 117 |
|
|
|
|
| 118 |
with gr.Blocks(theme=IndonesiaTheme()) as demo:
|
| 119 |
+
gr.Markdown("""
|
| 120 |
+
<div style='
|
| 121 |
+
background: linear-gradient(90deg, #5f0a87 0%, #a4508b 100%);
|
| 122 |
+
color: #fffde4;
|
| 123 |
+
padding: 36px 8px 22px 8px;
|
| 124 |
+
border-radius: 20px;
|
| 125 |
+
text-align:center;
|
| 126 |
+
font-size:2.0rem;
|
| 127 |
+
font-weight:bold;
|
| 128 |
+
letter-spacing: 1.5px;
|
| 129 |
+
margin-bottom: 16px;
|
| 130 |
+
box-shadow: 0 6px 48px #00000044;'>
|
| 131 |
+
π <span style='color:#FFD700'>100 SPACES TERPOPULER HUGGING FACE! - HOURLY UPDATE!!π₯</span> π<br>
|
| 132 |
+
<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>
|
| 133 |
+
Siapkah kamu menemukan Space AI idamanmu hari ini? <span style='color:#ffe29f'>β¨</span></span>
|
| 134 |
+
</div>
|
| 135 |
+
""")
|
| 136 |
+
with gr.Row():
|
| 137 |
+
with gr.Column(elem_id="col-left"):
|
| 138 |
+
status_choice = gr.Dropdown(["All", "Running", "Zero", "Stopped"],
|
| 139 |
+
label="ποΈ Filter Status", value="All")
|
| 140 |
+
with gr.Column(elem_id="col-mid"):
|
| 141 |
+
keyword_input = gr.Textbox(label="π Search by Name",
|
| 142 |
+
placeholder="e.g. llama, tts, image")
|
| 143 |
+
|
| 144 |
+
with gr.Column(elem_id="col-bott"):
|
| 145 |
+
output_table = gr.HTML(label="Leaderboard Table")
|
| 146 |
+
gr.Markdown("""
|
| 147 |
+
<div style='
|
| 148 |
+
color:#693f00;
|
| 149 |
+
padding: 24px 6px 18px 6px;
|
| 150 |
+
border-radius: 18px;
|
| 151 |
+
font-size: 1.12rem;
|
| 152 |
+
text-align:center;
|
| 153 |
+
margin-top:18px;
|
| 154 |
+
box-shadow: 0 3px 24px #FFD70033;
|
| 155 |
+
font-weight:bold;
|
| 156 |
+
'>
|
| 157 |
+
π <b>Selamat untuk seluruh Space yang masuk 100 besar! Kalian membanggakan komunitas AI Dunia! ππ₯</b><br>
|
| 158 |
+
<span style='font-size:1.55rem;'>Terus berkarya, jangan berhenti berinovasi! πͺππ₯³</span>
|
| 159 |
+
</div>
|
| 160 |
+
""")
|
| 161 |
+
gr.Button("π Refresh").click(fn=render_html_table,
|
| 162 |
+
inputs=[status_choice, keyword_input], outputs=output_table)
|
| 163 |
+
|
| 164 |
+
gr.Markdown("#### Made with β€οΈ by Deddy | HuggingFace Popular Space Leaderboard - Update Every Hour π₯", elem_id="footer")
|
| 165 |
+
|
| 166 |
+
# Inisialisasi tampilan awal
|
| 167 |
+
output_table.value = render_html_table("All", "")
|
| 168 |
+
|
| 169 |
+
# Jalankan aplikasi Gradio (local/web)
|
| 170 |
+
demo.queue(api_open=False).launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|