from flask import Flask, render_template, request, jsonify import os, re, json app = Flask(__name__) # ───────────────────────── 1. CURATED CATEGORIES ───────────────────────── CATEGORIES = { "Productivity": [ "https://huggingface.co/spaces/ginigen/perflexity-clone", "https://huggingface.co/spaces/ginipick/IDEA-DESIGN", "https://huggingface.co/spaces/VIDraft/mouse-webgen", "https://huggingface.co/spaces/openfree/Vibe-Game", "https://huggingface.co/spaces/openfree/Game-Gallery", "https://huggingface.co/spaces/aiqtech/Contributors-Leaderboard", "https://huggingface.co/spaces/fantaxy/Model-Leaderboard", "https://huggingface.co/spaces/fantaxy/Space-Leaderboard", "https://huggingface.co/spaces/openfree/Korean-Leaderboard", ], "Multimodal": [ "https://huggingface.co/spaces/openfree/DreamO-video", "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo", "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored", "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX", "https://huggingface.co/spaces/ginigen/SFX-Sound-magic", "https://huggingface.co/spaces/ginigen/VoiceClone-TTS", "https://huggingface.co/spaces/aiqcamp/MCP-kokoro", "https://huggingface.co/spaces/aiqcamp/ENGLISH-Speaking-Scoring", ], "Professional": [ "https://huggingface.co/spaces/ginigen/blogger", "https://huggingface.co/spaces/VIDraft/money-radar", "https://huggingface.co/spaces/immunobiotech/drug-discovery", "https://huggingface.co/spaces/immunobiotech/Gemini-MICHELIN", "https://huggingface.co/spaces/Heartsync/Papers-Leaderboard", "https://huggingface.co/spaces/VIDraft/PapersImpact", "https://huggingface.co/spaces/ginipick/AgentX-Papers", "https://huggingface.co/spaces/openfree/Cycle-Navigator", ], "Image": [ "https://huggingface.co/spaces/ginigen/interior-design", "https://huggingface.co/spaces/ginigen/Workflow-Canvas", "https://huggingface.co/spaces/ginigen/Multi-LoRAgen", "https://huggingface.co/spaces/ginigen/Every-Text", "https://huggingface.co/spaces/ginigen/text3d-r1", "https://huggingface.co/spaces/ginipick/FLUXllama", "https://huggingface.co/spaces/Heartsync/FLUX-Vision", "https://huggingface.co/spaces/ginigen/VisualCloze", "https://huggingface.co/spaces/seawolf2357/Ghibli-Multilingual-Text-rendering", "https://huggingface.co/spaces/ginigen/Ghibli-Meme-Studio", "https://huggingface.co/spaces/VIDraft/Open-Meme-Studio", "https://huggingface.co/spaces/ginigen/3D-LLAMA", ], "LLM / VLM": [ "https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-4B", "https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-12B", "https://huggingface.co/spaces/ginigen/Mistral-Perflexity", "https://huggingface.co/spaces/aiqcamp/gemini-2.5-flash-preview", "https://huggingface.co/spaces/openfree/qwen3-30b-a3b-research", "https://huggingface.co/spaces/openfree/qwen3-235b-a22b-research", "https://huggingface.co/spaces/openfree/Llama-4-Maverick-17B-Research", ], } # ─────────── 2. HELPERS: build embed & direct URLs from HF link ─────────── def space_embed_url(hf_url: str) -> str: m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url) if not m: return hf_url owner, name = m.groups() return f"https://huggingface.co/spaces/{owner}/{name}/embed" def space_direct_url(hf_url: str) -> str: m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url) if not m: return hf_url owner, name = m.groups() # dots/underscores → dashes, lowercase owner = owner.lower() name = name.replace('.', '-').replace('_', '-').lower() return f"https://{owner}-{name}.hf.space" # ───────────── 3. API: return spaces for a given category ────────────── @app.route('/api/category') def api_category(): cat = request.args.get('name', '') urls = CATEGORIES.get(cat, []) spaces = [{ "title": url.split('/')[-1], "embedUrl": space_embed_url(url), "directUrl": space_direct_url(url) } for url in urls] return jsonify({"spaces": spaces}) # ───────────────────────────── 4. ROUTES ──────────────────────────────── @app.route('/') def home(): return render_template('index.html', categories=list(CATEGORIES.keys())) # ───────────── 5. CREATE index.html with tabbed UI (once) ─────────────── if not os.path.exists('templates'): os.makedirs('templates') with open('templates/index.html', 'w', encoding='utf-8') as f: f.write(r'''