""" 现象人工智能 (phenom-ai) — 内部模型与数据资产管理门户 Space: https://huggingface.co/spaces/phenom-ai/assets """ import gradio as gr from huggingface_hub import HfApi, list_models, list_datasets ORG = "phenom-ai" api = HfApi() # ── Colors ────────────────────────────────────────────────────────────── CSS = """ .main-title { text-align: center; font-size: 2em; margin-bottom: 0.5em; color: #1f2937; } .subtitle { text-align: center; color: #6b7280; margin-bottom: 2em; } .card { border-radius: 12px; padding: 20px; background: #f9fafb; border: 1px solid #e5e7eb; } .section-header { font-size: 1.3em; font-weight: 600; color: #374151; margin-bottom: 1em; } .tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.85em; margin: 2px; } .tag-model { background: #dbeafe; color: #1e40af; } .tag-dataset { background: #dcfce7; color: #166534; } .stat-card { text-align: center; padding: 16px; border-radius: 10px; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.08); } .stat-number { font-size: 2em; font-weight: 700; color: #111827; } .stat-label { font-size: 0.85em; color: #6b7280; margin-top: 4px; } """ def fetch_models(): """获取组织下所有模型""" try: models = list_models(author=ORG, token=None) items = [] for m in models: tags = m.tags or [] pipeline = next((t for t in tags if t in [ "text-generation", "text-classification", "image-to-text", "image-classification", "zero-shot-image-classification", "object-detection", "translation", "summarization", "automatic-speech-recognition", "text-to-image", "image-to-image", "feature-extraction", ]), "Other") items.append({ "名称": f"[{m.id}]({m.url})", "类型": pipeline, "下载": f"{m.downloads or 0:,}", "点赞": f"{m.likes or 0}", "更新": str(m.lastModified)[:10] if m.lastModified else "-", "私有": "是" if m.private else "否", }) return items if else [["暂无模型,等待上传..."]] except Exception as e: return [[f"加载失败: {e}"]] def fetch_datasets(): """获取组织下所有数据集""" try: datasets = list_datasets(author=ORG, token=None) items = [] for d in datasets: items.append({ "名称": f"[{d.id}]({d.url})", "下载": f"{d.downloads or 0:,}", "点赞": f"{d.likes or 0}", "更新": str(d.lastModified)[:10] if d.lastModified else "-", "私有": "是" if d.private else "否", }) return items if else [["暂无数据集,等待上传..."]] except Exception as e: return [[f"加载失败: {e}"]] def get_stats(): """统计概览""" try: models = list_models(author=ORG, token=None) datasets = list_datasets(author=ORG, token=None) model_count = sum(1 for _ in models) dataset_count = sum(1 for _ in datasets) total_downloads = sum(m.downloads or 0 for m in models) + sum(d.downloads or 0 for d in datasets) total_likes = sum(m.likes or 0 for m in models) + sum(d.likes or 0 for d in datasets) return model_count, dataset_count, total_downloads, total_likes except Exception as e: return 0, 0, 0, 0 with gr.Blocks(title="现象人工智能 — 资产中心", css=CSS, theme=gr.themes.Soft()) as demo: # ── Header ─────────────────────────────────────────────────────── gr.HTML("""