awacke1 commited on
Commit
00ca949
ยท
verified ยท
1 Parent(s): bbd8a08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -4
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  from huggingface_hub import HfApi
3
  import asyncio
4
  import os
 
5
 
6
  # Initialize the Hugging Face API
7
  api = HfApi()
@@ -89,7 +90,7 @@ def get_cached_html_page(username):
89
  user_data = asyncio.run(fetch_user_content(username))
90
  if "error" in user_data:
91
  return None, user_data["error"]
92
- return generate_html_page(username, user_data["models"], user_data["datasets"]), None
93
 
94
  # Streamlit app setup - the nerve center of our operation! ๐ŸŽ›๏ธ
95
  st.title("Hugging Face User Content Display - Let's Automate Some Fun! ๐ŸŽ‰")
@@ -105,6 +106,9 @@ if st.button("Show User Content"):
105
  if usernames:
106
  username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
107
 
 
 
 
108
  st.markdown("### User Content Overview")
109
  for username in username_list:
110
  with st.container():
@@ -112,15 +116,50 @@ if st.button("Show User Content"):
112
  st.markdown(f"**{username}** [๐Ÿ”— Profile](https://huggingface.co/{username})")
113
 
114
  # Generate HTML page and provide download link - because who wouldn't want a custom webpage? ๐ŸŒ
115
- html_file_path, error = get_cached_html_page(username)
116
 
117
- if error:
118
- st.warning(f"{username}: {error} - Looks like the AI needs a coffee break โ˜•")
119
  else:
120
  st.markdown(f"[๐Ÿ“„ Download {username}'s HTML Page]({html_file_path})")
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  st.markdown("---")
123
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  else:
125
  st.warning("Please enter at least one username. Don't be shy! ๐Ÿ˜…")
126
 
@@ -131,4 +170,5 @@ st.sidebar.markdown("""
131
  2. Click 'Show User Content'.
132
  3. View the user's models and datasets along with a link to their Hugging Face profile.
133
  4. Download an HTML page for each user to use the absolute links offline!
 
134
  """)
 
2
  from huggingface_hub import HfApi
3
  import asyncio
4
  import os
5
+ import plotly.express as px
6
 
7
  # Initialize the Hugging Face API
8
  api = HfApi()
 
90
  user_data = asyncio.run(fetch_user_content(username))
91
  if "error" in user_data:
92
  return None, user_data["error"]
93
+ return generate_html_page(username, user_data["models"], user_data["datasets"]), user_data
94
 
95
  # Streamlit app setup - the nerve center of our operation! ๐ŸŽ›๏ธ
96
  st.title("Hugging Face User Content Display - Let's Automate Some Fun! ๐ŸŽ‰")
 
106
  if usernames:
107
  username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
108
 
109
+ # Collect statistics for Plotly graphs
110
+ stats = {"username": [], "models_count": [], "datasets_count": []}
111
+
112
  st.markdown("### User Content Overview")
113
  for username in username_list:
114
  with st.container():
 
116
  st.markdown(f"**{username}** [๐Ÿ”— Profile](https://huggingface.co/{username})")
117
 
118
  # Generate HTML page and provide download link - because who wouldn't want a custom webpage? ๐ŸŒ
119
+ html_file_path, user_data = get_cached_html_page(username)
120
 
121
+ if not html_file_path:
122
+ st.warning(f"{username}: {user_data} - Looks like the AI needs a coffee break โ˜•")
123
  else:
124
  st.markdown(f"[๐Ÿ“„ Download {username}'s HTML Page]({html_file_path})")
125
 
126
+ # Add to statistics for Plotly graphs
127
+ stats["username"].append(username)
128
+ stats["models_count"].append(len(user_data["models"]))
129
+ stats["datasets_count"].append(len(user_data["datasets"]))
130
+
131
+ # Models section with expander - ๐Ÿง  because AI models are brainy! ๐Ÿง 
132
+ with st.expander(f"๐Ÿง  Models ({len(user_data['models'])})", expanded=False):
133
+ if user_data['models']:
134
+ for model in user_data['models']:
135
+ model_name = model.modelId.split("/")[-1]
136
+ st.markdown(f"- [{model_name}](https://huggingface.co/{model.modelId})")
137
+ else:
138
+ st.markdown("No models found. Did you check under the rug? ๐Ÿ•ต๏ธโ€โ™‚๏ธ")
139
+
140
+ # Datasets section with expander - ๐Ÿ“š because data is the foundation of AI! ๐Ÿ“š
141
+ with st.expander(f"๐Ÿ“š Datasets ({len(user_data['datasets'])})", expanded=False):
142
+ if user_data['datasets']:
143
+ for dataset in user_data['datasets']:
144
+ dataset_name = dataset.id.split("/")[-1]
145
+ st.markdown(f"- [{dataset_name}](https://huggingface.co/datasets/{dataset.id})")
146
+ else:
147
+ st.markdown("No datasets found. Maybe theyโ€™re still baking in the oven? ๐Ÿช")
148
+
149
  st.markdown("---")
150
 
151
+ # Plotly graphs to visualize the number of models and datasets each user has
152
+ if stats["username"]:
153
+ st.markdown("### User Content Statistics")
154
+
155
+ # Plotting the number of models per user
156
+ fig_models = px.bar(x=stats["username"], y=stats["models_count"], labels={'x':'Username', 'y':'Number of Models'}, title="Number of Models per User")
157
+ st.plotly_chart(fig_models)
158
+
159
+ # Plotting the number of datasets per user
160
+ fig_datasets = px.bar(x=stats["username"], y=stats["datasets_count"], labels={'x':'Username', 'y':'Number of Datasets'}, title="Number of Datasets per User")
161
+ st.plotly_chart(fig_datasets)
162
+
163
  else:
164
  st.warning("Please enter at least one username. Don't be shy! ๐Ÿ˜…")
165
 
 
170
  2. Click 'Show User Content'.
171
  3. View the user's models and datasets along with a link to their Hugging Face profile.
172
  4. Download an HTML page for each user to use the absolute links offline!
173
+ 5. Check out the statistics visualizations at the end!
174
  """)