awacke1 commited on
Commit
00551a6
·
verified ·
1 Parent(s): 281bb73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -2,12 +2,16 @@ import streamlit as st
2
  from huggingface_hub import HfApi
3
  import pandas as pd
4
  import asyncio
5
- import base64
6
- from io import BytesIO
7
 
8
  # Initialize the Hugging Face API
9
  api = HfApi()
10
 
 
 
 
 
 
11
  # Default list of Hugging Face usernames - where all the magic begins! 🪄
12
  default_users = {
13
  "users": [
@@ -41,7 +45,7 @@ async def fetch_all_users(usernames):
41
  tasks = [fetch_user_content(username) for username in usernames]
42
  return await asyncio.gather(*tasks)
43
 
44
- # Generate HTML content for a user and encode it as Base64 for download - because who doesn't love a good download link? 💾
45
  def generate_html_page(username, models, datasets):
46
  html_content = f"""
47
  <html>
@@ -72,8 +76,18 @@ def generate_html_page(username, models, datasets):
72
  </body>
73
  </html>
74
  """
75
- # Encode the HTML content as Base64 - like wrapping it in a fancy gift box! 🎁
76
- return base64.b64encode(html_content.encode()).decode()
 
 
 
 
 
 
 
 
 
 
77
 
78
  # Streamlit app setup - the nerve center of our operation! 🎛️
79
  st.title("Hugging Face User Content Display - Let's Automate Some Fun! 🎉")
@@ -124,8 +138,8 @@ if st.button("Show User Content"):
124
  st.markdown("No datasets found. Maybe they’re still baking in the oven? 🍪")
125
 
126
  # Generate HTML page and provide download link - because who wouldn't want a custom webpage? 🌐
127
- html_page = generate_html_page(username, result['models'], result['datasets'])
128
- st.markdown(f"[📄 Download {username}'s HTML Page](data:text/html;base64,{html_page})")
129
 
130
  st.markdown("---")
131
  else:
 
2
  from huggingface_hub import HfApi
3
  import pandas as pd
4
  import asyncio
5
+ import os
 
6
 
7
  # Initialize the Hugging Face API
8
  api = HfApi()
9
 
10
+ # Directory to save the generated HTML files
11
+ HTML_DIR = "generated_html_pages"
12
+ if not os.path.exists(HTML_DIR):
13
+ os.makedirs(HTML_DIR)
14
+
15
  # Default list of Hugging Face usernames - where all the magic begins! 🪄
16
  default_users = {
17
  "users": [
 
45
  tasks = [fetch_user_content(username) for username in usernames]
46
  return await asyncio.gather(*tasks)
47
 
48
+ # Generate HTML content for a user and save it to a file - because who doesn't love a good download link? 💾
49
  def generate_html_page(username, models, datasets):
50
  html_content = f"""
51
  <html>
 
76
  </body>
77
  </html>
78
  """
79
+
80
+ # Save the HTML content to a file
81
+ html_file_path = os.path.join(HTML_DIR, f"{username}.html")
82
+ with open(html_file_path, "w") as html_file:
83
+ html_file.write(html_content)
84
+
85
+ return html_file_path
86
+
87
+ # Cache the HTML generation process using Streamlit's caching decorator - because no one likes to repeat themselves! 🔁
88
+ @st.cache_data(show_spinner=False)
89
+ def get_cached_html_page(username, models, datasets):
90
+ return generate_html_page(username, models, datasets)
91
 
92
  # Streamlit app setup - the nerve center of our operation! 🎛️
93
  st.title("Hugging Face User Content Display - Let's Automate Some Fun! 🎉")
 
138
  st.markdown("No datasets found. Maybe they’re still baking in the oven? 🍪")
139
 
140
  # Generate HTML page and provide download link - because who wouldn't want a custom webpage? 🌐
141
+ html_file_path = get_cached_html_page(username, result['models'], result['datasets'])
142
+ st.markdown(f"[📄 Download {username}'s HTML Page]({html_file_path})")
143
 
144
  st.markdown("---")
145
  else: