Update app-backup.py
Browse files- app-backup.py +32 -28
app-backup.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import HfApi
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
# Default list of Hugging Face usernames
|
6 |
default_users = {
|
@@ -24,13 +25,13 @@ def get_user_content(username):
|
|
24 |
spaces = api.list_spaces(author=username)
|
25 |
|
26 |
return {
|
|
|
27 |
"models": models,
|
28 |
"datasets": datasets,
|
29 |
"spaces": spaces
|
30 |
}
|
31 |
except Exception as e:
|
32 |
-
|
33 |
-
return None
|
34 |
|
35 |
st.title("Hugging Face User Content Display")
|
36 |
|
@@ -44,42 +45,45 @@ if st.button("Show User Content"):
|
|
44 |
if usernames:
|
45 |
username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
|
46 |
results = []
|
|
|
47 |
|
48 |
-
|
49 |
-
for
|
|
|
|
|
|
|
50 |
content = get_user_content(username)
|
51 |
-
|
52 |
-
|
53 |
-
profile_emoji = "🔗"
|
54 |
-
|
55 |
-
models = [f"[{model.modelId}](https://huggingface.co/{model.modelId})" for model in content['models']]
|
56 |
-
datasets = [f"[{dataset.id}](https://huggingface.co/datasets/{dataset.id})" for dataset in content['datasets']]
|
57 |
-
spaces = [f"[{space.id}](https://huggingface.co/spaces/{space.id})" for space in content['spaces']]
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
})
|
66 |
-
else:
|
67 |
-
results.append({"Hugging Face": username, "Error": "User content not found"})
|
68 |
-
progress_bar.progress((i + 1) / len(username_list))
|
69 |
|
70 |
st.markdown("### User Content Overview")
|
71 |
for result in results:
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.markdown("**Models:**")
|
75 |
-
st.markdown("\n".join(
|
76 |
st.markdown("**Datasets:**")
|
77 |
-
st.markdown("\n".join(
|
78 |
st.markdown("**Spaces:**")
|
79 |
-
st.markdown("\n".join(
|
80 |
st.markdown("---")
|
81 |
else:
|
82 |
-
st.warning(f"{
|
83 |
|
84 |
else:
|
85 |
st.warning("Please enter at least one username.")
|
@@ -89,5 +93,5 @@ st.sidebar.markdown("""
|
|
89 |
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames.
|
90 |
2. Click 'Show User Content'.
|
91 |
3. View the user's models, datasets, and spaces along with a link to their Hugging Face profile.
|
92 |
-
4. The progress
|
93 |
""")
|
|
|
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 = {
|
|
|
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 |
|
|
|
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.")
|
|
|
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 |
""")
|