Update app.py
Browse files12345677 unmodified lines15161718192021222324252627284 unmodified lines3334353637385 unmodified lines44454647484950515253545556575859606162636465666725 unmodified lines9394959697import streamlit as stfrom huggingface_hub import HfApiimport pandas as pdfrom concurrent.futures import ThreadPoolExecutor, as_completed# Default list of Hugging Face usernamesdefault_users = {7 unmodified lines]}api = HfApi()def get_user_content(username):try:# Fetch models, datasets, and spaces associated with the usermodels = api.list_models(author=username)datasets = api.list_datasets(author=username)spaces = api.list_spaces(author=username)return {"username": username,4 unmodified linesexcept Exception as e:return {"username": username, "error": str(e)}st.title("Hugging Face User Content Display")# Convert the default users list to a string5 unmodified linesif st.button("Show User Content"):if usernames:username_list = [username.strip() for username in usernames.split('\n') if username.strip()]results = []status_bars = {}# Set up the progress bars for each userfor username in username_list:status_bars[username] = st.progress(0, text=f"Fetching data for {username}...")def fetch_and_display(username):content = get_user_content(username)status_bars[username].progress(100, text=f"Data fetched for {username}")return content# Use ThreadPoolExecutor for concurrent executionwith ThreadPoolExecutor(max_workers=len(username_list)) as executor:future_to_username = {executor.submit(fetch_and_display, username): username for username in username_list}for future in as_completed(future_to_username):result = future.result()results.append(result)st.markdown("### User Content Overview")for result in results:25 unmodified lines1. 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, datasets, and spaces along with a link to their Hugging Face profile.4. The progress bars show the status of content retrieval for each user.""")1234567897 unmodified lines17181920212223242526274 unmodified lines323334353637383940415 unmodified lines474849505152535425 unmodified lines80818283import streamlit as stfrom huggingface_hub import HfApiimport pandas as pdimport asyncioapi = HfApi()# Default list of Hugging Face usernamesdefault_users = {7 unmodified lines]}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)spaces = await asyncio.to_thread(api.list_spaces, author=username)return {"username": username,4 unmodified linesexcept 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)st.title("Hugging Face User Content Display")# Convert the default users list to a string5 unmodified linesif 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:25 unmodified lines1. 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, datasets, and spaces along with a link to their Hugging Face profile.""")
app.py+12-26