awacke1 commited on
Commit
bbd8a08
Β·
verified Β·
1 Parent(s): 9656945

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -44
app.py CHANGED
@@ -44,11 +44,6 @@ async def fetch_all_users(usernames):
44
  tasks = [fetch_user_content(username) for username in usernames]
45
  return await asyncio.gather(*tasks)
46
 
47
- # Cache the HTML generation process using Streamlit's caching decorator
48
- @st.cache_data(show_spinner=False)
49
- def get_cached_html_page(_username, _models, _datasets):
50
- return generate_html_page(_username, _models, _datasets)
51
-
52
  # Generate HTML content for a user and save it to a file - because who doesn't love a good download link? πŸ’Ύ
53
  def generate_html_page(username, models, datasets):
54
  html_content = f"""
@@ -88,6 +83,14 @@ def generate_html_page(username, models, datasets):
88
 
89
  return html_file_path
90
 
 
 
 
 
 
 
 
 
91
  # Streamlit app setup - the nerve center of our operation! πŸŽ›οΈ
92
  st.title("Hugging Face User Content Display - Let's Automate Some Fun! πŸŽ‰")
93
 
@@ -102,47 +105,21 @@ if st.button("Show User Content"):
102
  if usernames:
103
  username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
104
 
105
- # Run the asyncio loop to fetch all users - time to unleash the hounds! πŸ•
106
- results = asyncio.run(fetch_all_users(username_list))
107
-
108
  st.markdown("### User Content Overview")
109
- for result in results:
110
- username = result["username"]
111
- if "error" not in result:
112
- with st.container():
113
- # Profile link - because everyone deserves their 15 seconds of fame! 🎀
114
- st.markdown(f"**{username}** [πŸ”— Profile](https://huggingface.co/{username})")
115
-
116
- # Create columns for models and datasets - divide and conquer! πŸ›οΈ
117
- col1, col2 = st.columns(2)
118
-
119
- # Models section with emoji - 🧠 because AI models are brainy! 🧠
120
- with col1:
121
- st.markdown("**Models:** 🧠")
122
- if result['models']:
123
- for model in result['models']:
124
- model_name = model.modelId.split("/")[-1]
125
- st.markdown(f"- [{model_name}](https://huggingface.co/{model.modelId})")
126
- else:
127
- st.markdown("No models found. Did you check under the rug? πŸ•΅οΈβ€β™‚οΈ")
128
-
129
- # Datasets section with emoji - πŸ“š because data is the foundation of AI! πŸ“š
130
- with col2:
131
- st.markdown("**Datasets:** πŸ“š")
132
- if result['datasets']:
133
- for dataset in result['datasets']:
134
- dataset_name = dataset.id.split("/")[-1]
135
- st.markdown(f"- [{dataset_name}](https://huggingface.co/datasets/{dataset.id})")
136
- else:
137
- st.markdown("No datasets found. Maybe they’re still baking in the oven? πŸͺ")
138
-
139
- # Generate HTML page and provide download link - because who wouldn't want a custom webpage? 🌐
140
- html_file_path = get_cached_html_page(username, result['models'], result['datasets'])
141
  st.markdown(f"[πŸ“„ Download {username}'s HTML Page]({html_file_path})")
142
-
143
- st.markdown("---")
144
- else:
145
- st.warning(f"{username}: {result['error']} - Looks like the AI needs a coffee break β˜•")
146
 
147
  else:
148
  st.warning("Please enter at least one username. Don't be shy! πŸ˜…")
 
44
  tasks = [fetch_user_content(username) for username in usernames]
45
  return await asyncio.gather(*tasks)
46
 
 
 
 
 
 
47
  # Generate HTML content for a user and save it to a file - because who doesn't love a good download link? πŸ’Ύ
48
  def generate_html_page(username, models, datasets):
49
  html_content = f"""
 
83
 
84
  return html_file_path
85
 
86
+ # Cache the HTML generation process using Streamlit's caching decorator
87
+ @st.cache_data(show_spinner=False)
88
+ 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! πŸŽ‰")
96
 
 
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():
111
+ # Profile link - because everyone deserves their 15 seconds of fame! 🎀
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! πŸ˜…")