|
import subprocess |
|
import os |
|
import gradio as gr |
|
import pandas as pd |
|
import time |
|
import threading |
|
from huggingface_hub import HfApi |
|
from plot_graph import gr_plot_follower_comparison |
|
|
|
api = HfApi() |
|
|
|
HF_TOKEN = os.getenv('HF_TOKEN') |
|
repo_url = "https://huggingface.co/datasets/Weyaxi/followers-leaderboard" |
|
os.system(f"git clone --bare --filter=blob:none {repo_url}") |
|
|
|
os.chdir("followers-leaderboard.git") |
|
|
|
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") |
|
|
|
os.system(f"wget -Odata.csv https://huggingface.co/datasets/Weyaxi/followers-leaderboard/resolve/main/{result}/data.csv?download=true") |
|
|
|
|
|
def clickable(x): |
|
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>' |
|
|
|
def apply_headers(df, headers): |
|
tmp = df.copy() |
|
tmp.columns = headers |
|
|
|
return tmp |
|
|
|
|
|
def search(search_text): |
|
if not search_text: |
|
return df |
|
|
|
return df[df['👤 Author'].str.contains(search_text, case=False, na=False)] |
|
|
|
|
|
def restart_space(): |
|
time.sleep(36000) |
|
api.restart_space(repo_id="Weyaxi/followers-leaderboard", token=HF_TOKEN) |
|
|
|
|
|
df = pd.read_csv("data.csv").drop("Followers", axis=1) |
|
|
|
df_author_copy = df.copy() |
|
|
|
df["Author"] = df["Author"].apply(lambda x: clickable(x)) |
|
df = df.sort_values(by='Number of Followers', ascending=False) |
|
df['Serial Number'] = [i for i in range(1, len(df)+1)] |
|
df = df[['Serial Number', "Author", "Number of Followers"]] |
|
|
|
df = apply_headers(df, ["🔢 Serial Number", "👤 Author", "🌟 Number of Followers"]) |
|
|
|
|
|
desc = f""" |
|
🎯 The Leaderboard aims to track users follower counts. |
|
|
|
## 📄 Information |
|
|
|
🛠️ This leaderboard consists of 4000 users scraped from [🤗 Huggingface Leaderboard](https://huggingface.co/spaces/Weyaxi/huggingface-leaderboard). |
|
|
|
These 4000 users have been selected based on their [🤗 Huggingface Leaderboard](https://huggingface.co/spaces/Weyaxi/huggingface-leaderboard) positions: |
|
|
|
- 🤖 Top 2250 authors in the models category |
|
|
|
- 📊 Top 1100 authors in the datasets category |
|
|
|
- 🚀 Top 1100 authors in the spaces category |
|
|
|
|
|
## 🤝 I want to see someone here |
|
|
|
No problem, you can request to add a user [here](https://huggingface.co/spaces/Weyaxi/followers-leaderboard/discussions/1). |
|
|
|
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. 🙂 |
|
|
|
## Last Update |
|
|
|
⌛ This space information is last updated in **{result.replace("%20", " ")}**. |
|
""" |
|
|
|
title = """ |
|
<div style="text-align:center"> |
|
<h1 id="space-title">🌟 Follower Leaderboard 🌟</h1> |
|
</div> |
|
""" |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("""<h1 align="center" id="space-title">🌟 Follower Leaderboard 🌟</h1>""") |
|
gr.Markdown(desc) |
|
|
|
with gr.TabItem("📊 Dataframe", id=1): |
|
with gr.Column(min_width=320): |
|
search_bar = gr.Textbox(placeholder="🔍 Search for an author", show_label=False) |
|
|
|
gr_followers = gr.Dataframe(df, interactive=False, datatype=["number", 'markdown', 'number']) |
|
|
|
with gr.TabItem("📈 Graphic", id=2): |
|
with gr.Column(min_width=320): |
|
search_bar_graph = gr.Textbox(placeholder="🔍 Search for an author or authors separated by comma", show_label=False) |
|
|
|
output_plot = gr.LinePlot( |
|
x="x", |
|
y="y", |
|
color="author", |
|
tooltip=["x", "y", "author"], |
|
title="Follower Growth Over Time", |
|
x_title="Date", |
|
y_title="Number of Followers", |
|
width=700, |
|
height=500 |
|
) |
|
|
|
search_bar.submit(fn=search, inputs=search_bar, outputs=gr_followers) |
|
search_bar_graph.submit(fn=lambda names: gr_plot_follower_comparison(names.split(",")), inputs=search_bar_graph, outputs=output_plot) |
|
|
|
threading.Thread(target=restart_space).start() |
|
demo.launch() |