Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import pandas as pd
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Default list of Hugging Face usernames
|
| 7 |
default_users = {
|
|
@@ -15,14 +17,11 @@ default_users = {
|
|
| 15 |
]
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def get_user_content(username):
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
spaces = api.list_spaces(author=username)
|
| 26 |
|
| 27 |
return {
|
| 28 |
"username": username,
|
|
@@ -33,6 +32,10 @@ def get_user_content(username):
|
|
| 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
|
|
@@ -44,24 +47,8 @@ usernames = st.text_area("Enter Hugging Face usernames (one per line):", value=d
|
|
| 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 |
-
|
| 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:
|
|
@@ -93,5 +80,4 @@ st.sidebar.markdown("""
|
|
| 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 |
""")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import pandas as pd
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
api = HfApi()
|
| 7 |
|
| 8 |
# Default list of Hugging Face usernames
|
| 9 |
default_users = {
|
|
|
|
| 17 |
]
|
| 18 |
}
|
| 19 |
|
| 20 |
+
async def fetch_user_content(username):
|
|
|
|
|
|
|
| 21 |
try:
|
| 22 |
+
models = await asyncio.to_thread(api.list_models, author=username)
|
| 23 |
+
datasets = await asyncio.to_thread(api.list_datasets, author=username)
|
| 24 |
+
spaces = await asyncio.to_thread(api.list_spaces, author=username)
|
|
|
|
| 25 |
|
| 26 |
return {
|
| 27 |
"username": username,
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
return {"username": username, "error": str(e)}
|
| 34 |
|
| 35 |
+
async def fetch_all_users(usernames):
|
| 36 |
+
tasks = [fetch_user_content(username) for username in usernames]
|
| 37 |
+
return await asyncio.gather(*tasks)
|
| 38 |
+
|
| 39 |
st.title("Hugging Face User Content Display")
|
| 40 |
|
| 41 |
# Convert the default users list to a string
|
|
|
|
| 47 |
if st.button("Show User Content"):
|
| 48 |
if usernames:
|
| 49 |
username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
results = asyncio.run(fetch_all_users(username_list))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
st.markdown("### User Content Overview")
|
| 54 |
for result in results:
|
|
|
|
| 80 |
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames.
|
| 81 |
2. Click 'Show User Content'.
|
| 82 |
3. View the user's models, datasets, and spaces along with a link to their Hugging Face profile.
|
|
|
|
| 83 |
""")
|