Deddy commited on
Commit
48d98a3
Β·
verified Β·
1 Parent(s): 96a1f4d

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +142 -0
  2. spaces.db +0 -0
  3. themes.py +51 -0
app.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import sqlite3
3
+ import pandas as pd
4
+ from themes import IndonesiaTheme # Tema custom
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
+ conn.close()
13
+
14
+ if status_filter != "All":
15
+ df = df[df['status'].str.contains(status_filter, case=False, na=False)]
16
+
17
+ if keyword.strip():
18
+ df = df[df['name'].str.contains(keyword, case=False, na=False)]
19
+
20
+ df = df.sort_values("likes", ascending=False).head(20)
21
+
22
+ # Kolom Visit tetap
23
+ df["πŸ”— Visit"] = df["link"].apply(lambda url: f"<a href='{url}' target='_blank'>🌐 Visit</a>")
24
+
25
+ # Kolom Name: bold
26
+ df["name"] = df["name"].apply(lambda name: f"<b>{name}</b>")
27
+
28
+ # Kolom Status: warna dinamis
29
+ def format_status(s):
30
+ if "running" in s.lower():
31
+ return f"<span style='color:green;font-weight:bold'>{s}</span>"
32
+ else:
33
+ return f"<span style='color:red;font-weight:bold'>{s}</span>"
34
+
35
+ df["status"] = df["status"].apply(format_status)
36
+
37
+ # Susun ulang kolom
38
+ df = df[["name", "author", "desc", "likes", "updated", "status", "πŸ”— Visit"]]
39
+ df.columns = ["πŸ“› Name", "πŸ‘€ Author", "πŸ“ Description", "❀️ Likes", "πŸ•’ Updated", "βš™οΈ Status", "πŸ”— Visit"]
40
+
41
+
42
+ return df.reset_index(drop=True)
43
+
44
+ def view_leaderboard(status, keyword):
45
+ return load_data(status, keyword)
46
+
47
+ css = """
48
+ table {
49
+ width: 100%;
50
+ border-collapse: collapse;
51
+ margin-top: 1rem;
52
+ font-size: 0.92rem;
53
+ }
54
+
55
+ th {
56
+ background: #f0f0f0;
57
+ padding: 8px;
58
+ text-align: left;
59
+ font-weight: bold;
60
+ border-bottom: 2px solid #ccc;
61
+ }
62
+
63
+ td {
64
+ padding: 8px;
65
+ border-bottom: 1px solid #eee;
66
+ vertical-align: top;
67
+ }
68
+
69
+ tr:hover {
70
+ background-color: #f9f9f9;
71
+ }
72
+
73
+ td a {
74
+ text-decoration: none;
75
+ color: #1e90ff;
76
+ font-weight: bold;
77
+ }
78
+ """
79
+
80
+
81
+ # === Gradio App UI ===
82
+ with gr.Blocks(theme=IndonesiaTheme()) as demo:
83
+ with gr.Column():
84
+ gr.Markdown("## 🌌 HuggingFace Spaces Leaderboard")
85
+ gr.Markdown("🎯 Menampilkan 20 space dengan jumlah like terbanyak + link kunjungan langsung")
86
+
87
+ with gr.Row():
88
+ with gr.Column(elem_id="col-left"):
89
+ status_choice = gr.Dropdown(["All", "Running", "Zero", "Stopped"],
90
+ label="πŸŽ›οΈ Filter Status", value="All")
91
+ with gr.Column(elem_id="col-mid"):
92
+ keyword_input = gr.Textbox(label="πŸ” Search by Name",
93
+ placeholder="e.g. llama, tts, image")
94
+
95
+ with gr.Column(elem_id="col-bott"):
96
+ output_table = gr.HTML(label="Leaderboard Table")
97
+
98
+ def render_html_table(status, keyword):
99
+ df = load_data(status, keyword)
100
+ html_table = df.to_html(escape=False, index=False, classes="styled-table")
101
+ return f"""
102
+ <style>
103
+ .styled-table {{
104
+ width: 100%;
105
+ border-collapse: collapse;
106
+ font-size: 0.9rem;
107
+ font-family: 'Segoe UI', sans-serif;
108
+ background-color: #1e1e1e;
109
+ color: #e0e0e0;
110
+ }}
111
+ .styled-table th {{
112
+ background-color: #2e2e2e;
113
+ text-align: left;
114
+ padding: 10px;
115
+ border-bottom: 2px solid #444;
116
+ }}
117
+ .styled-table td {{
118
+ padding: 10px;
119
+ border-bottom: 1px solid #333;
120
+ vertical-align: top;
121
+ }}
122
+ .styled-table tr:hover td {{
123
+ background-color: #2a2a2a;
124
+ }}
125
+ a {{
126
+ color: #4da6ff;
127
+ text-decoration: none;
128
+ font-weight: bold;
129
+ }}
130
+ </style>
131
+ {html_table}
132
+ """
133
+
134
+
135
+ status_choice.change(fn=render_html_table, inputs=[status_choice, keyword_input], outputs=output_table)
136
+ keyword_input.change(fn=render_html_table, inputs=[status_choice, keyword_input], outputs=output_table)
137
+ gr.Button("πŸ”„ Refresh").click(fn=render_html_table,
138
+ inputs=[status_choice, keyword_input], outputs=output_table)
139
+
140
+ gr.Markdown("#### Made with ❀️ by Deddy | HuggingFace Leaderboard Mirror", elem_id="footer")
141
+
142
+ demo.launch()
spaces.db ADDED
Binary file (81.9 kB). View file
 
themes.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from typing import Iterable
3
+ from gradio.themes.base import Base
4
+ from gradio.themes.utils import colors, fonts, sizes
5
+
6
+ class IndonesiaTheme(Base):
7
+ def __init__(
8
+ self,
9
+ *,
10
+ primary_hue: colors.Color | str = colors.red,
11
+ secondary_hue: colors.Color | str = colors.gray,
12
+ neutral_hue: colors.Color | str = colors.gray,
13
+ spacing_size: sizes.Size | str = sizes.spacing_md,
14
+ radius_size: sizes.Size | str = sizes.radius_md,
15
+ text_size: sizes.Size | str = sizes.text_md,
16
+ font: fonts.Font
17
+ | str
18
+ | Iterable[fonts.Font | str] = (
19
+ fonts.GoogleFont("Quicksand"),
20
+ "ui-sans-serif",
21
+ "sans-serif",
22
+ ),
23
+ font_mono: fonts.Font
24
+ | str
25
+ | Iterable[fonts.Font | str] = (
26
+ fonts.GoogleFont("IBM Plex Mono"),
27
+ "ui-monospace",
28
+ "monospace",
29
+ ),
30
+ ):
31
+ super().__init__(
32
+ primary_hue=primary_hue,
33
+ secondary_hue=secondary_hue,
34
+ neutral_hue=neutral_hue,
35
+ spacing_size=spacing_size,
36
+ radius_size=radius_size,
37
+ text_size=text_size,
38
+ font=font,
39
+ font_mono=font_mono,
40
+ )
41
+
42
+ # Override latar belakang utama body
43
+ self.set(
44
+ body_background_fill="linear-gradient(180deg, #111111 0%, #222222 100%)",
45
+ body_text_color="#e0e0e0",
46
+ block_background_fill="#2a2a2a",
47
+ block_border_width="0px",
48
+ block_shadow="none",
49
+ button_primary_background_fill="#ff4b5c",
50
+ button_primary_text_color="white",
51
+ )