Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import time
|
6 |
+
import threading
|
7 |
+
from huggingface_hub import HfApi
|
8 |
+
api = HfApi()
|
9 |
+
|
10 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
11 |
+
repo_url = "https://huggingface.co/datasets/Weyaxi/followers-leaderboard"
|
12 |
+
os.system(f"git clone --bare --filter=blob:none {repo_url}")
|
13 |
+
|
14 |
+
os.chdir("followers-leaderboard.git")
|
15 |
+
|
16 |
+
result = subprocess.check_output("git log -1 --pretty=%B", shell=True, universal_newlines=True).replace("Upload", "").replace("/data.csv with huggingface_hub", "").strip().replace(" ", "%20")
|
17 |
+
|
18 |
+
os.system(f"wget -Odata.csv https://huggingface.co/datasets/Weyaxi/followers-leaderboard/resolve/main/{result}/data.csv?download=true")
|
19 |
+
|
20 |
+
|
21 |
+
def clickable(x):
|
22 |
+
return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
|
23 |
+
|
24 |
+
def apply_headers(df, headers):
|
25 |
+
tmp = df.copy()
|
26 |
+
tmp.columns = headers
|
27 |
+
|
28 |
+
return tmp
|
29 |
+
|
30 |
+
|
31 |
+
def search(search_text):
|
32 |
+
if not search_text:
|
33 |
+
return df
|
34 |
+
|
35 |
+
return df[df['👤 Author'].str.contains(search_text, case=False, na=False)]
|
36 |
+
|
37 |
+
|
38 |
+
def restart_space():
|
39 |
+
time.sleep(1880)
|
40 |
+
api.restart_space(repo_id="Weyaxi/followers-leaderboard", token=HF_TOKEN)
|
41 |
+
|
42 |
+
|
43 |
+
df = pd.read_csv("data.csv").drop("Followers", axis=1)
|
44 |
+
|
45 |
+
df_author_copy = df.copy()
|
46 |
+
|
47 |
+
df["Author"] = df["Author"].apply(lambda x: clickable(x))
|
48 |
+
df = df.sort_values(by='Number of Followers', ascending=False)
|
49 |
+
df['Serial Number'] = [i for i in range(1, len(df)+1)]
|
50 |
+
df = df[['Serial Number', "Author", "Number of Followers"]]
|
51 |
+
|
52 |
+
df = apply_headers(df, ["🔢 Serial Number", "👤 Author", "🌟 Number of Followers"])
|
53 |
+
|
54 |
+
|
55 |
+
desc = f"""
|
56 |
+
🎯 The Leaderboard aims to track users follower counts.
|
57 |
+
|
58 |
+
## 📄 Information
|
59 |
+
|
60 |
+
🛠️ This leaderboard consists of 4000 users scraped from [🤗 Huggingface Leaderboard](https://huggingface.co/spaces/PulsarAI/huggingface-leaderboard).
|
61 |
+
|
62 |
+
These 4000 users have been selected based on their [🤗 Huggingface Leaderboard](https://huggingface.co/spaces/PulsarAI/huggingface-leaderboard) positions:
|
63 |
+
|
64 |
+
- 🤖 Top 2250 authors in the models category
|
65 |
+
|
66 |
+
- 📊 Top 1100 authors in the datasets category
|
67 |
+
|
68 |
+
- 🚀 Top 1100 authors in the spaces category
|
69 |
+
|
70 |
+
|
71 |
+
## 🤝 I want to see someone here
|
72 |
+
|
73 |
+
No problem, you can request to add a user [here](https://huggingface.co/spaces/Weyaxi/followers-leaderboard/discussions/1).
|
74 |
+
|
75 |
+
There is no critique; please request anyone. The number of users in this leaderboard is limited because scraping 250k user's follower count is challenging. 🙂
|
76 |
+
|
77 |
+
## Last Update
|
78 |
+
|
79 |
+
⌛ This space information is last updated in **{result.replace("%20", " ")}**.
|
80 |
+
"""
|
81 |
+
|
82 |
+
title = """
|
83 |
+
<div style="text-align:center">
|
84 |
+
<h1 id="space-title">🌟 Follower Leaderboard 🌟</h1>
|
85 |
+
</div>
|
86 |
+
"""
|
87 |
+
|
88 |
+
with gr.Blocks() as demo:
|
89 |
+
gr.Markdown("""<h1 align="center" id="space-title">🌟 Follower Leaderboard 🌟</h1>""")
|
90 |
+
gr.Markdown(desc)
|
91 |
+
with gr.Column(min_width=320):
|
92 |
+
search_bar = gr.Textbox(placeholder="🔍 Search for a author", show_label=False)
|
93 |
+
|
94 |
+
gr_followers = gr.Dataframe(df, interactive=False, datatype=["number", 'markdown', 'number'])
|
95 |
+
|
96 |
+
search_bar.submit(fn=search, inputs=search_bar, outputs=gr_followers)
|
97 |
+
|
98 |
+
|
99 |
+
threading.Thread(target=restart_space).start()
|
100 |
+
demo.launch()
|