import streamlit as st import datetime def model_list(models, on_select_callback): """Render a list of model cards with enhanced UI and metadata badges""" if not models: st.info("No models found. Create your first repository to get started!") return # Display the models in a grid cols = st.columns(2) for i, model in enumerate(models): with cols[i % 2]: with st.container(): st.markdown( f"""
{model.modelId}
HF HF ℹ️ Last updated: {datetime.datetime.now().strftime("%Y-%m-%d")}
{getattr(model, 'description', 'No description available.') or 'No description available.'}
""", unsafe_allow_html=True, ) # Button to select model below the card if st.button( f"View Details", key=f"view_{model.modelId}", use_container_width=True, ): on_select_callback(model.modelId) def generate_tags(model): """Generate HTML for model tags""" tags = getattr(model, "tags", []) or [] if not tags: tags = ["untagged"] tags_html = "" for tag in tags[:3]: # Limit to 3 tags to avoid clutter tags_html += f'{tag}' if len(tags) > 3: tags_html += f'+{len(tags) - 3} more' return tags_html def model_detail_card(model): """Render a detailed model card with badges, stats, and actions""" st.markdown( f"""

{model.modelId}

HF View on Hugging Face GitHub View on GitHub
📥 {getattr(model, 'downloads', 0)} Total downloads ❤️ {getattr(model, 'likes', 0)} Total likes

Description

{getattr(model, 'description', 'No description available.') or 'No description available.'}

Tags

{generate_detailed_tags(model)}

Last Updated

{datetime.datetime.now().strftime("%B %d, %Y")}

Model Size

{getattr(model, 'size', 'Unknown')} MB

""", unsafe_allow_html=True, ) def generate_detailed_tags(model): """Generate HTML for detailed model tags view""" tags = getattr(model, "tags", []) or [] if not tags: return 'untagged' tags_html = "" for tag in tags: tags_html += f'{tag}' return tags_html