Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 5 |
+
|
| 6 |
+
# Default list of Hugging Face usernames
|
| 7 |
+
default_users = {
|
| 8 |
+
"users": [
|
| 9 |
+
"awacke1", "rogerxavier", "jonatasgrosman", "kenshinn", "Csplk", "DavidVivancos",
|
| 10 |
+
"cdminix", "Jaward", "TuringsSolutions", "Severian", "Wauplin",
|
| 11 |
+
"phosseini", "Malikeh1375", "gokaygokay", "MoritzLaurer", "mrm8488",
|
| 12 |
+
"TheBloke", "lhoestq", "xw-eric", "Paul", "Muennighoff",
|
| 13 |
+
"ccdv", "haonan-li", "chansung", "lukaemon", "hails",
|
| 14 |
+
"pharmapsychotic", "KingNish", "merve", "ameerazam08", "ashleykleynhans"
|
| 15 |
+
]
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
api = HfApi()
|
| 19 |
+
|
| 20 |
+
def get_user_content(username):
|
| 21 |
+
try:
|
| 22 |
+
# Fetch models, datasets, and spaces associated with the user
|
| 23 |
+
models = api.list_models(author=username)
|
| 24 |
+
datasets = api.list_datasets(author=username)
|
| 25 |
+
spaces = api.list_spaces(author=username)
|
| 26 |
+
|
| 27 |
+
return {
|
| 28 |
+
"username": username,
|
| 29 |
+
"models": models,
|
| 30 |
+
"datasets": datasets,
|
| 31 |
+
"spaces": spaces
|
| 32 |
+
}
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return {"username": username, "error": str(e)}
|
| 35 |
+
|
| 36 |
+
st.title("Hugging Face User Content Display")
|
| 37 |
+
|
| 38 |
+
# Convert the default users list to a string
|
| 39 |
+
default_users_str = "\n".join(default_users["users"])
|
| 40 |
+
|
| 41 |
+
# Text area with default list of usernames
|
| 42 |
+
usernames = st.text_area("Enter Hugging Face usernames (one per line):", value=default_users_str, height=300)
|
| 43 |
+
|
| 44 |
+
if st.button("Show User Content"):
|
| 45 |
+
if usernames:
|
| 46 |
+
username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
|
| 47 |
+
results = []
|
| 48 |
+
status_bars = {}
|
| 49 |
+
|
| 50 |
+
# Set up the progress bars for each user
|
| 51 |
+
for username in username_list:
|
| 52 |
+
status_bars[username] = st.progress(0, text=f"Fetching data for {username}...")
|
| 53 |
+
|
| 54 |
+
def fetch_and_display(username):
|
| 55 |
+
content = get_user_content(username)
|
| 56 |
+
status_bars[username].progress(100, text=f"Data fetched for {username}")
|
| 57 |
+
return content
|
| 58 |
+
|
| 59 |
+
# Use ThreadPoolExecutor for concurrent execution
|
| 60 |
+
with ThreadPoolExecutor(max_workers=len(username_list)) as executor:
|
| 61 |
+
future_to_username = {executor.submit(fetch_and_display, username): username for username in username_list}
|
| 62 |
+
for future in as_completed(future_to_username):
|
| 63 |
+
result = future.result()
|
| 64 |
+
results.append(result)
|
| 65 |
+
|
| 66 |
+
st.markdown("### User Content Overview")
|
| 67 |
+
for result in results:
|
| 68 |
+
username = result["username"]
|
| 69 |
+
if "error" not in result:
|
| 70 |
+
profile_link = f"https://huggingface.co/{username}"
|
| 71 |
+
profile_emoji = "🔗"
|
| 72 |
+
|
| 73 |
+
models = [f"[{model.modelId}](https://huggingface.co/{model.modelId})" for model in result['models']]
|
| 74 |
+
datasets = [f"[{dataset.id}](https://huggingface.co/datasets/{dataset.id})" for dataset in result['datasets']]
|
| 75 |
+
spaces = [f"[{space.id}](https://huggingface.co/spaces/{space.id})" for space in result['spaces']]
|
| 76 |
+
|
| 77 |
+
st.markdown(f"**{username}** {profile_emoji} [Profile]({profile_link})")
|
| 78 |
+
st.markdown("**Models:**")
|
| 79 |
+
st.markdown("\n".join(models) if models else "No models found")
|
| 80 |
+
st.markdown("**Datasets:**")
|
| 81 |
+
st.markdown("\n".join(datasets) if datasets else "No datasets found")
|
| 82 |
+
st.markdown("**Spaces:**")
|
| 83 |
+
st.markdown("\n".join(spaces) if spaces else "No spaces found")
|
| 84 |
+
st.markdown("---")
|
| 85 |
+
else:
|
| 86 |
+
st.warning(f"{username}: {result['error']}")
|
| 87 |
+
|
| 88 |
+
else:
|
| 89 |
+
st.warning("Please enter at least one username.")
|
| 90 |
+
|
| 91 |
+
st.sidebar.markdown("""
|
| 92 |
+
## How to use:
|
| 93 |
+
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames.
|
| 94 |
+
2. Click 'Show User Content'.
|
| 95 |
+
3. View the user's models, datasets, and spaces along with a link to their Hugging Face profile.
|
| 96 |
+
4. The progress bars show the status of content retrieval for each user.
|
| 97 |
+
""")
|