Update app.py
Browse files
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
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 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 |
-
|
| 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! π
")
|