|
import streamlit as st |
|
from huggingface_hub import HfApi |
|
import pandas as pd |
|
import asyncio |
|
import base64 |
|
from io import BytesIO |
|
|
|
|
|
api = HfApi() |
|
|
|
|
|
default_users = { |
|
"users": [ |
|
"awacke1", "rogerxavier", "jonatasgrosman", "kenshinn", "Csplk", "DavidVivancos", |
|
"cdminix", "Jaward", "TuringsSolutions", "Severian", "Wauplin", |
|
"phosseini", "Malikeh1375", "gokaygokay", "MoritzLaurer", "mrm8488", |
|
"TheBloke", "lhoestq", "xw-eric", "Paul", "Muennighoff", |
|
"ccdv", "haonan-li", "chansung", "lukaemon", "hails", |
|
"pharmapsychotic", "KingNish", "merve", "ameerazam08", "ashleykleynhans" |
|
] |
|
} |
|
|
|
|
|
async def fetch_user_content(username): |
|
try: |
|
|
|
models = await asyncio.to_thread(api.list_models, author=username) |
|
datasets = await asyncio.to_thread(api.list_datasets, author=username) |
|
|
|
return { |
|
"username": username, |
|
"models": models, |
|
"datasets": datasets |
|
} |
|
except Exception as e: |
|
|
|
return {"username": username, "error": str(e)} |
|
|
|
|
|
async def fetch_all_users(usernames): |
|
tasks = [fetch_user_content(username) for username in usernames] |
|
return await asyncio.gather(*tasks) |
|
|
|
|
|
def generate_html_page(username, models, datasets): |
|
html_content = f""" |
|
<html> |
|
<head> |
|
<title>{username}'s Hugging Face Content</title> |
|
</head> |
|
<body> |
|
<h1>{username}'s Hugging Face Profile</h1> |
|
<p><a href="https://huggingface.co/{username}">π Profile Link</a></p> |
|
<h2>π§ Models</h2> |
|
<ul> |
|
""" |
|
for model in models: |
|
model_name = model.modelId.split("/")[-1] |
|
html_content += f'<li><a href="https://huggingface.co/{model.modelId}">{model_name}</a></li>' |
|
|
|
html_content += """ |
|
</ul> |
|
<h2>π Datasets</h2> |
|
<ul> |
|
""" |
|
for dataset in datasets: |
|
dataset_name = dataset.id.split("/")[-1] |
|
html_content += f'<li><a href="https://huggingface.co/datasets/{dataset.id}">{dataset_name}</a></li>' |
|
|
|
html_content += """ |
|
</ul> |
|
</body> |
|
</html> |
|
""" |
|
|
|
return base64.b64encode(html_content.encode()).decode() |
|
|
|
|
|
st.title("Hugging Face User Content Display - Let's Automate Some Fun! π") |
|
|
|
|
|
default_users_str = "\n".join(default_users["users"]) |
|
|
|
|
|
usernames = st.text_area("Enter Hugging Face usernames (one per line):", value=default_users_str, height=300) |
|
|
|
|
|
if st.button("Show User Content"): |
|
if usernames: |
|
username_list = [username.strip() for username in usernames.split('\n') if username.strip()] |
|
|
|
|
|
results = asyncio.run(fetch_all_users(username_list)) |
|
|
|
st.markdown("### User Content Overview") |
|
for result in results: |
|
username = result["username"] |
|
if "error" not in result: |
|
with st.container(): |
|
|
|
st.markdown(f"**{username}** [π Profile](https://huggingface.co/{username})") |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
st.markdown("**Models:** π§ ") |
|
if result['models']: |
|
for model in result['models']: |
|
model_name = model.modelId.split("/")[-1] |
|
st.markdown(f"- [{model_name}](https://huggingface.co/{model.modelId})") |
|
else: |
|
st.markdown("No models found. Did you check under the rug? π΅οΈββοΈ") |
|
|
|
|
|
with col2: |
|
st.markdown("**Datasets:** π") |
|
if result['datasets']: |
|
for dataset in result['datasets']: |
|
dataset_name = dataset.id.split("/")[-1] |
|
st.markdown(f"- [{dataset_name}](https://huggingface.co/datasets/{dataset.id})") |
|
else: |
|
st.markdown("No datasets found. Maybe theyβre still baking in the oven? πͺ") |
|
|
|
|
|
html_page = generate_html_page(username, result['models'], result['datasets']) |
|
st.markdown(f"[π Download {username}'s HTML Page](data:text/html;base64,{html_page})") |
|
|
|
st.markdown("---") |
|
else: |
|
st.warning(f"{username}: {result['error']} - Looks like the AI needs a coffee break β") |
|
|
|
else: |
|
st.warning("Please enter at least one username. Don't be shy! π
") |
|
|
|
|
|
st.sidebar.markdown(""" |
|
## How to use: |
|
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames. |
|
2. Click 'Show User Content'. |
|
3. View the user's models and datasets along with a link to their Hugging Face profile. |
|
4. Download an HTML page for each user to use the absolute links offline! |
|
""") |
|
|