awacke1 commited on
Commit
74df5c0
·
verified ·
1 Parent(s): e855afd

Update app-backup.py

Browse files
Files changed (1) hide show
  1. 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
- st.error(f"Error fetching content for {username}: {str(e)}")
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
- progress_bar = st.progress(0)
49
- for i, username in enumerate(username_list):
 
 
 
50
  content = get_user_content(username)
51
- if content:
52
- profile_link = f"https://huggingface.co/{username}"
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
- results.append({
60
- "Hugging Face": username,
61
- "Profile Link": f"[{profile_emoji} Profile]({profile_link})",
62
- "Models": models,
63
- "Datasets": datasets,
64
- "Spaces": spaces
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
- if "Error" not in result:
73
- st.markdown(f"**{result['Hugging Face']}** {result['Profile Link']}")
 
 
 
 
 
 
 
 
74
  st.markdown("**Models:**")
75
- st.markdown("\n".join(result["Models"]) if result["Models"] else "No models found")
76
  st.markdown("**Datasets:**")
77
- st.markdown("\n".join(result["Datasets"]) if result["Datasets"] else "No datasets found")
78
  st.markdown("**Spaces:**")
79
- st.markdown("\n".join(result["Spaces"]) if result["Spaces"] else "No spaces found")
80
  st.markdown("---")
81
  else:
82
- st.warning(f"{result['Hugging Face']}: {result['Error']}")
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 bar shows the status of content retrieval.
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
  """)