import gradio as gr import json import os from pathlib import Path def load_config(): """Load configuration from config.json""" config_path = Path(__file__).parent / "config.json" with open(config_path, 'r', encoding='utf-8') as f: return json.load(f) def get_custom_css(): """Load custom CSS if available""" css_path = Path(__file__).parent / "static" / "style.css" if css_path.exists(): with open(css_path, 'r', encoding='utf-8') as f: return f.read() return "" def create_category_card(category): """Create HTML for a category card""" return f"""
{category['icon']}

{category['name']}

{category['description']}

""" def create_model_card(item, item_type="model"): """Create HTML for a model or dataset card""" tags_html = " ".join([f'{tag}' for tag in item.get('tags', [])]) links = [] if item.get('repo'): links.append(f'๐Ÿค— View on HF') if item.get('demo_url'): links.append(f'๐Ÿš€ Demo') if item.get('paper_url'): links.append(f'๐Ÿ“„ Paper') links_html = " ".join(links) size_info = f'
{item["size"]}
' if item.get('size') else '' return f"""

{item['name']}

{item.get('description', '')}

{size_info}
{tags_html}
""" def create_header(config): """Create site header""" site = config['site'] social_links = [] if site['social_links'].get('github'): social_links.append(f'GitHub') if site['social_links'].get('twitter'): social_links.append(f'Twitter') if site['social_links'].get('linkedin'): social_links.append(f'LinkedIn') social_html = " ยท ".join(social_links) if social_links else "" return f""" """ def create_category_section(config, category_id): """Create a section showing items from a specific category""" models = [m for m in config.get('models', []) if m.get('category') == category_id] datasets = [d for d in config.get('datasets', []) if d.get('category') == category_id] html = "
" for model in models: html += create_model_card(model, "model") for dataset in datasets: html += create_model_card(dataset, "dataset") html += "
" if not models and not datasets: html = "

No items in this category yet.

" return html def build_interface(): """Build the Gradio interface""" config = load_config() custom_css = get_custom_css() with gr.Blocks( title=config['site']['title'], css=custom_css, theme=gr.themes.Soft(primary_hue="indigo") ) as demo: # Header gr.HTML(create_header(config)) # Categories Overview gr.Markdown("## ๐Ÿ“‚ Categories", elem_classes="section-title") categories_html = "
" for category in config['categories']: categories_html += create_category_card(category) categories_html += "
" gr.HTML(categories_html) # Create tabs for each category with gr.Tabs(): for category in config['categories']: with gr.Tab(f"{category['icon']} {category['name']}"): gr.Markdown(f"### {category['description']}") category_html = create_category_section(config, category['id']) gr.HTML(category_html) # All items tab with gr.Tab("๐ŸŒ All Items"): gr.Markdown("### All Models and Datasets") all_html = "
" for model in config.get('models', []): all_html += create_model_card(model, "model") for dataset in config.get('datasets', []): all_html += create_model_card(dataset, "dataset") all_html += "
" gr.HTML(all_html) # Footer gr.Markdown(""" ---
Built with HF Site Builder | Powered by Gradio & Hugging Face Spaces
""") return demo if __name__ == "__main__": demo = build_interface() demo.launch()