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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify
|
| 2 |
+
import os, re, json
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# ────────────────────────── 1. CONFIGURATION ──────────────────────────
|
| 7 |
+
|
| 8 |
+
# Domains that commonly block iframes
|
| 9 |
+
BLOCKED_DOMAINS = [
|
| 10 |
+
"naver.com", "daum.net", "google.com",
|
| 11 |
+
"facebook.com", "instagram.com", "kakao.com",
|
| 12 |
+
"ycombinator.com"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
# ────────────────────────── 2. CURATED CATEGORIES ──────────────────────────
|
| 16 |
+
CATEGORIES = {
|
| 17 |
+
"Popular": [
|
| 18 |
+
"https://huggingface.co/spaces/ginigen/Flux-VIDEO",
|
| 19 |
+
"https://huggingface.co/spaces/openfree/Open-GAMMA",
|
| 20 |
+
"https://huggingface.co/spaces/VIDraft/DNA-CASINO",
|
| 21 |
+
],
|
| 22 |
+
"BEST": [
|
| 23 |
+
"https://huggingface.co/spaces/aiqtech/Heatmap-Leaderboard",
|
| 24 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
|
| 25 |
+
"https://huggingface.co/spaces/ginigen/deepseek-r1-0528-API",
|
| 26 |
+
],
|
| 27 |
+
"NEW": [
|
| 28 |
+
"https://huggingface.co/spaces/fantaxy/YTB-TEST",
|
| 29 |
+
"https://huggingface.co/spaces/ginigen/VEO3-Free",
|
| 30 |
+
"https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528",
|
| 31 |
+
],
|
| 32 |
+
"Productivity": [
|
| 33 |
+
"https://huggingface.co/spaces/aiqtech/Heatmap-Leaderboard",
|
| 34 |
+
"https://huggingface.co/spaces/VIDraft/DNA-CASINO",
|
| 35 |
+
"https://huggingface.co/spaces/openfree/Open-GAMMA",
|
| 36 |
+
"https://huggingface.co/spaces/VIDraft/Robo-Beam",
|
| 37 |
+
"https://huggingface.co/spaces/VIDraft/voice-trans",
|
| 38 |
+
"https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB",
|
| 39 |
+
"https://huggingface.co/spaces/openfree/Chart-GPT",
|
| 40 |
+
"https://huggingface.co/spaces/ginipick/AI-BOOK",
|
| 41 |
+
"https://huggingface.co/spaces/VIDraft/Voice-Clone-Podcast",
|
| 42 |
+
"https://huggingface.co/spaces/ginipick/PDF-EXAM",
|
| 43 |
+
"https://huggingface.co/spaces/ginigen/perflexity-clone",
|
| 44 |
+
"https://huggingface.co/spaces/ginipick/IDEA-DESIGN",
|
| 45 |
+
"https://huggingface.co/spaces/ginipick/10m-marketing",
|
| 46 |
+
"https://huggingface.co/spaces/openfree/Live-Podcast",
|
| 47 |
+
"https://huggingface.co/spaces/openfree/AI-Podcast",
|
| 48 |
+
"https://huggingface.co/spaces/ginipick/QR-Canvas-plus",
|
| 49 |
+
"https://huggingface.co/spaces/openfree/Badge",
|
| 50 |
+
"https://huggingface.co/spaces/VIDraft/mouse-webgen",
|
| 51 |
+
"https://huggingface.co/spaces/openfree/Vibe-Game",
|
| 52 |
+
"https://huggingface.co/spaces/VIDraft/NH-Prediction",
|
| 53 |
+
"https://huggingface.co/spaces/ginipick/NH-Korea",
|
| 54 |
+
"https://huggingface.co/spaces/openfree/Naming",
|
| 55 |
+
"https://huggingface.co/spaces/ginipick/Change-Hair",
|
| 56 |
+
],
|
| 57 |
+
"Multimodal": [
|
| 58 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
|
| 59 |
+
"https://huggingface.co/spaces/fantaxy/YTB-TEST",
|
| 60 |
+
"https://huggingface.co/spaces/ginigen/Seedance-Free",
|
| 61 |
+
"https://huggingface.co/spaces/Heartsync/VEO3-RealTime",
|
| 62 |
+
"https://huggingface.co/spaces/ginigen/VEO3-Free",
|
| 63 |
+
"https://huggingface.co/spaces/ginigen/VEO3-Directors",
|
| 64 |
+
"https://huggingface.co/spaces/Heartsync/WAN2-1-fast-T2V-FusioniX",
|
| 65 |
+
"https://huggingface.co/spaces/Heartsync/adult",
|
| 66 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
|
| 67 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
|
| 68 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
|
| 69 |
+
"https://huggingface.co/spaces/Heartsync/WAN-VIDEO-AUDIO",
|
| 70 |
+
"https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",
|
| 71 |
+
"https://huggingface.co/spaces/ginigen/Flux-VIDEO",
|
| 72 |
+
"https://huggingface.co/spaces/ginigen/3D-LLAMA-V1",
|
| 73 |
+
"https://huggingface.co/spaces/ginigen/Flux-VIDEO",
|
| 74 |
+
"https://huggingface.co/spaces/openfree/Multilingual-TTS",
|
| 75 |
+
"https://huggingface.co/spaces/VIDraft/ACE-Singer",
|
| 76 |
+
"https://huggingface.co/spaces/openfree/DreamO-video",
|
| 77 |
+
"https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
|
| 78 |
+
"https://huggingface.co/spaces/ginigen/SFX-Sound-magic",
|
| 79 |
+
"https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
|
| 80 |
+
"https://huggingface.co/spaces/aiqcamp/ENGLISH-Speaking-Scoring",
|
| 81 |
+
"https://huggingface.co/spaces/fantaxy/Remove-Video-Background",
|
| 82 |
+
],
|
| 83 |
+
"Professional": [
|
| 84 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-novels",
|
| 85 |
+
"https://huggingface.co/spaces/aiqtech/SOMA-Oriental",
|
| 86 |
+
"https://huggingface.co/spaces/VIDraft/SOMA-AGI",
|
| 87 |
+
"https://huggingface.co/spaces/Heartsync/Novel-NSFW",
|
| 88 |
+
"https://huggingface.co/spaces/fantaxy/fantasy-novel",
|
| 89 |
+
"https://huggingface.co/spaces/VIDraft/money-radar",
|
| 90 |
+
"https://huggingface.co/spaces/immunobiotech/drug-discovery",
|
| 91 |
+
"https://huggingface.co/spaces/immunobiotech/Gemini-MICHELIN",
|
| 92 |
+
"https://huggingface.co/spaces/openfree/Cycle-Navigator",
|
| 93 |
+
"https://huggingface.co/spaces/VIDraft/Fashion-Fit",
|
| 94 |
+
"https://huggingface.co/spaces/openfree/Stock-Trading-Analysis",
|
| 95 |
+
"https://huggingface.co/spaces/ginipick/AgentX-Papers",
|
| 96 |
+
"https://huggingface.co/spaces/Heartsync/Papers-Leaderboard",
|
| 97 |
+
"https://huggingface.co/spaces/VIDraft/PapersImpact",
|
| 98 |
+
"https://huggingface.co/spaces/ginigen/multimodal-chat-mbti-korea",
|
| 99 |
+
],
|
| 100 |
+
"Image": [
|
| 101 |
+
"https://huggingface.co/spaces/ginigen/Flux-Kontext-FaceLORA",
|
| 102 |
+
"https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL",
|
| 103 |
+
"https://huggingface.co/spaces/ginigen/FLUX-Ghibli-LoRA2",
|
| 104 |
+
"https://huggingface.co/spaces/aiqcamp/REMOVAL-TEXT-IMAGE",
|
| 105 |
+
"https://huggingface.co/spaces/VIDraft/BAGEL-Websearch",
|
| 106 |
+
"https://huggingface.co/spaces/ginigen/Every-Text",
|
| 107 |
+
"https://huggingface.co/spaces/ginigen/text3d-r1",
|
| 108 |
+
"https://huggingface.co/spaces/ginipick/FLUXllama",
|
| 109 |
+
"https://huggingface.co/spaces/ginigen/Workflow-Canvas",
|
| 110 |
+
"https://huggingface.co/spaces/ginigen/canvas-studio",
|
| 111 |
+
"https://huggingface.co/spaces/VIDraft/ReSize-Image-Outpainting",
|
| 112 |
+
"https://huggingface.co/spaces/Heartsync/FLUX-Vision",
|
| 113 |
+
"https://huggingface.co/spaces/fantos/textcutobject",
|
| 114 |
+
"https://huggingface.co/spaces/aiqtech/imaginpaint",
|
| 115 |
+
"https://huggingface.co/spaces/openfree/ColorRevive",
|
| 116 |
+
"https://huggingface.co/spaces/openfree/ultpixgen",
|
| 117 |
+
"https://huggingface.co/spaces/VIDraft/Polaroid-Style",
|
| 118 |
+
"https://huggingface.co/spaces/ginigen/VisualCloze",
|
| 119 |
+
"https://huggingface.co/spaces/fantaxy/ofai-flx-logo",
|
| 120 |
+
"https://huggingface.co/spaces/ginigen/interior-design",
|
| 121 |
+
"https://huggingface.co/spaces/ginigen/MagicFace-V3",
|
| 122 |
+
"https://huggingface.co/spaces/fantaxy/flx-pulid",
|
| 123 |
+
"https://huggingface.co/spaces/seawolf2357/Ghibli-Multilingual-Text-rendering",
|
| 124 |
+
"https://huggingface.co/spaces/VIDraft/Open-Meme-Studio",
|
| 125 |
+
"https://huggingface.co/spaces/VIDraft/stable-diffusion-3.5-large-turboX",
|
| 126 |
+
"https://huggingface.co/spaces/aiqtech/flxgif",
|
| 127 |
+
"https://huggingface.co/spaces/openfree/VectorFlow",
|
| 128 |
+
"https://huggingface.co/spaces/ginigen/3D-LLAMA",
|
| 129 |
+
"https://huggingface.co/spaces/ginigen/Multi-LoRAgen",
|
| 130 |
+
],
|
| 131 |
+
"LLM / VLM": [
|
| 132 |
+
"https://huggingface.co/spaces/fantaxy/fantasy-novel",
|
| 133 |
+
"https://huggingface.co/spaces/ginigen/deepseek-r1-0528-API",
|
| 134 |
+
"https://huggingface.co/spaces/aiqcamp/Mistral-Devstral-API",
|
| 135 |
+
"https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528",
|
| 136 |
+
"https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528-qwen3-8b",
|
| 137 |
+
"https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528",
|
| 138 |
+
"https://huggingface.co/spaces/aiqcamp/Mistral-Devstral-API",
|
| 139 |
+
"https://huggingface.co/spaces/VIDraft/Mistral-RAG-BitSix",
|
| 140 |
+
"https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-4B",
|
| 141 |
+
"https://huggingface.co/spaces/VIDraft/Gemma-3-R1984-12B",
|
| 142 |
+
"https://huggingface.co/spaces/ginigen/Mistral-Perflexity",
|
| 143 |
+
"https://huggingface.co/spaces/aiqcamp/gemini-2.5-flash-preview",
|
| 144 |
+
"https://huggingface.co/spaces/openfree/qwen3-30b-a3b-research",
|
| 145 |
+
"https://huggingface.co/spaces/openfree/qwen3-235b-a22b-research",
|
| 146 |
+
"https://huggingface.co/spaces/openfree/Llama-4-Maverick-17B-Research",
|
| 147 |
+
],
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
# ────────────────────────── 3. URL HELPERS ──────────────────────────
|
| 151 |
+
def direct_url(hf_url):
|
| 152 |
+
m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url)
|
| 153 |
+
if not m:
|
| 154 |
+
return hf_url
|
| 155 |
+
owner, name = m.groups()
|
| 156 |
+
owner = owner.lower()
|
| 157 |
+
name = name.replace('.', '-').replace('_', '-').lower()
|
| 158 |
+
return f"https://{owner}-{name}.hf.space"
|
| 159 |
+
|
| 160 |
+
def screenshot_url(url):
|
| 161 |
+
return f"https://image.thum.io/get/fullpage/{url}"
|
| 162 |
+
|
| 163 |
+
def process_url_for_preview(url):
|
| 164 |
+
"""Returns (preview_url, mode)"""
|
| 165 |
+
# Handle blocked domains first
|
| 166 |
+
if any(d for d in BLOCKED_DOMAINS if d in url):
|
| 167 |
+
return screenshot_url(url), "snapshot"
|
| 168 |
+
|
| 169 |
+
# Special case handling for problematic URLs
|
| 170 |
+
if "vibe-coding-tetris" in url or "World-of-Tank-GAME" in url or "Minesweeper-Game" in url:
|
| 171 |
+
return screenshot_url(url), "snapshot"
|
| 172 |
+
|
| 173 |
+
# General HF space handling
|
| 174 |
+
try:
|
| 175 |
+
if "huggingface.co/spaces" in url:
|
| 176 |
+
parts = url.rstrip("/").split("/")
|
| 177 |
+
if len(parts) >= 5:
|
| 178 |
+
owner = parts[-2]
|
| 179 |
+
name = parts[-1]
|
| 180 |
+
embed_url = f"https://huggingface.co/spaces/{owner}/{name}/embed"
|
| 181 |
+
return embed_url, "iframe"
|
| 182 |
+
except Exception:
|
| 183 |
+
return screenshot_url(url), "snapshot"
|
| 184 |
+
|
| 185 |
+
# Default handling
|
| 186 |
+
return url, "iframe"
|
| 187 |
+
|
| 188 |
+
# ───────────────────────���── 4. API ROUTES ──────────────────────────
|
| 189 |
+
@app.route('/api/category')
|
| 190 |
+
def api_category():
|
| 191 |
+
cat = request.args.get('name', '')
|
| 192 |
+
urls = CATEGORIES.get(cat, [])
|
| 193 |
+
|
| 194 |
+
# Add pagination for categories
|
| 195 |
+
page = int(request.args.get('page', 1))
|
| 196 |
+
per_page = int(request.args.get('per_page', 4))
|
| 197 |
+
|
| 198 |
+
total_pages = max(1, (len(urls) + per_page - 1) // per_page)
|
| 199 |
+
start = (page - 1) * per_page
|
| 200 |
+
end = min(start + per_page, len(urls))
|
| 201 |
+
|
| 202 |
+
urls_page = urls[start:end]
|
| 203 |
+
|
| 204 |
+
items = [
|
| 205 |
+
{
|
| 206 |
+
"title": url.split('/')[-1],
|
| 207 |
+
"owner": url.split('/')[-2] if '/spaces/' in url else '',
|
| 208 |
+
"iframe": direct_url(url),
|
| 209 |
+
"shot": screenshot_url(url),
|
| 210 |
+
"hf": url
|
| 211 |
+
} for url in urls_page
|
| 212 |
+
]
|
| 213 |
+
|
| 214 |
+
return jsonify({
|
| 215 |
+
"items": items,
|
| 216 |
+
"page": page,
|
| 217 |
+
"total_pages": total_pages
|
| 218 |
+
})
|
| 219 |
+
|
| 220 |
+
# ────────────────────────── 5. MAIN ROUTES ──────────────────────────
|
| 221 |
+
@app.route('/')
|
| 222 |
+
def home():
|
| 223 |
+
os.makedirs('templates', exist_ok=True)
|
| 224 |
+
|
| 225 |
+
with open('templates/index.html', 'w', encoding='utf-8') as fp:
|
| 226 |
+
fp.write(r'''<!DOCTYPE html>
|
| 227 |
+
<html>
|
| 228 |
+
<head>
|
| 229 |
+
<meta charset="utf-8">
|
| 230 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 231 |
+
<title>Web Gallery</title>
|
| 232 |
+
<style>
|
| 233 |
+
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;600&display=swap');
|
| 234 |
+
body{margin:0;font-family:Nunito,sans-serif;background:#f6f8fb;}
|
| 235 |
+
.tabs{display:flex;flex-wrap:wrap;gap:8px;padding:16px;}
|
| 236 |
+
.tab{padding:6px 14px;border:none;border-radius:18px;background:#e2e8f0;font-weight:600;cursor:pointer;}
|
| 237 |
+
.tab.active{background:#a78bfa;color:#1a202c;}
|
| 238 |
+
.tab.popular{background:#ff6b6b;color:white;}
|
| 239 |
+
.tab.popular.active{background:#fa5252;color:white;}
|
| 240 |
+
.tab.best{background:#4ecdc4;color:white;}
|
| 241 |
+
.tab.best.active{background:#38d9a9;color:white;}
|
| 242 |
+
.tab.new{background:#ffe066;color:#1a202c;}
|
| 243 |
+
.tab.new.active{background:#ffd43b;color:#1a202c;}
|
| 244 |
+
/* Updated grid to show 2x2 layout */
|
| 245 |
+
.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:20px;padding:0 16px 60px;max-width:1200px;margin:0 auto;}
|
| 246 |
+
@media(max-width:800px){.grid{grid-template-columns:1fr;}}
|
| 247 |
+
/* Increased card height for larger display */
|
| 248 |
+
.card{background:#fff;border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,.08);overflow:hidden;height:540px;display:flex;flex-direction:column;position:relative;}
|
| 249 |
+
.frame{flex:1;position:relative;overflow:hidden;}
|
| 250 |
+
.frame iframe{position:absolute;width:166.667%;height:166.667%;transform:scale(.6);transform-origin:top left;border:0;}
|
| 251 |
+
.frame img{width:100%;height:100%;object-fit:cover;}
|
| 252 |
+
.card-label{position:absolute;top:10px;left:10px;padding:4px 8px;border-radius:4px;font-size:11px;font-weight:bold;z-index:100;text-transform:uppercase;letter-spacing:0.5px;box-shadow:0 2px 4px rgba(0,0,0,0.2);}
|
| 253 |
+
.label-live{background:linear-gradient(135deg, #00c6ff, #0072ff);color:white;}
|
| 254 |
+
.label-static{background:linear-gradient(135deg, #ff9a9e, #fad0c4);color:#333;}
|
| 255 |
+
.foot{height:44px;background:#fafafa;display:flex;align-items:center;justify-content:center;border-top:1px solid #eee;}
|
| 256 |
+
.foot a{font-size:.82rem;font-weight:700;color:#4a6dd8;text-decoration:none;}
|
| 257 |
+
.pagination{display:flex;justify-content:center;margin:20px 0;gap:10px;}
|
| 258 |
+
.pagination button{padding:5px 15px;border:none;border-radius:20px;background:#e2e8f0;cursor:pointer;}
|
| 259 |
+
.pagination button:disabled{opacity:0.5;cursor:not-allowed;}
|
| 260 |
+
</style>
|
| 261 |
+
</head>
|
| 262 |
+
<body>
|
| 263 |
+
<header style="text-align: center; padding: 20px; background: linear-gradient(135deg, #f6f8fb, #e2e8f0); border-bottom: 1px solid #ddd;">
|
| 264 |
+
<h1 style="margin-bottom: 10px;">🌟AI Playground</h1>
|
| 265 |
+
<p>
|
| 266 |
+
<a href="https://discord.gg/openfreeai" target="_blank"><img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="badge"></a>
|
| 267 |
+
</p>
|
| 268 |
+
</header>
|
| 269 |
+
<div class="tabs" id="tabs"></div>
|
| 270 |
+
<div id="content"></div>
|
| 271 |
+
|
| 272 |
+
<script>
|
| 273 |
+
// Basic configuration
|
| 274 |
+
const cats = {{cats|tojson}};
|
| 275 |
+
const tabs = document.getElementById('tabs');
|
| 276 |
+
const content = document.getElementById('content');
|
| 277 |
+
let active = "";
|
| 278 |
+
let currentPage = 1;
|
| 279 |
+
|
| 280 |
+
// Simple utility functions
|
| 281 |
+
function makeRequest(url, method, data, callback) {
|
| 282 |
+
const xhr = new XMLHttpRequest();
|
| 283 |
+
xhr.open(method, url, true);
|
| 284 |
+
xhr.onreadystatechange = function() {
|
| 285 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 286 |
+
callback(JSON.parse(xhr.responseText));
|
| 287 |
+
}
|
| 288 |
+
};
|
| 289 |
+
if (method === 'POST') {
|
| 290 |
+
xhr.send(data);
|
| 291 |
+
} else {
|
| 292 |
+
xhr.send();
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
function updateTabs() {
|
| 297 |
+
Array.from(tabs.children).forEach(b => {
|
| 298 |
+
b.classList.toggle('active', b.dataset.c === active);
|
| 299 |
+
});
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
// Tab handlers
|
| 303 |
+
function loadCategory(cat, page) {
|
| 304 |
+
if(cat === active && currentPage === page) return;
|
| 305 |
+
active = cat;
|
| 306 |
+
currentPage = page || 1;
|
| 307 |
+
updateTabs();
|
| 308 |
+
|
| 309 |
+
content.innerHTML = '<p style="text-align:center;padding:40px">Loading…</p>';
|
| 310 |
+
|
| 311 |
+
makeRequest('/api/category?name=' + encodeURIComponent(cat) + '&page=' + currentPage + '&per_page=4', 'GET', null, function(data) {
|
| 312 |
+
let html = '<div class="grid">';
|
| 313 |
+
|
| 314 |
+
if(data.items.length === 0) {
|
| 315 |
+
html += '<p style="grid-column:1/-1;text-align:center;padding:40px">No items in this category.</p>';
|
| 316 |
+
} else {
|
| 317 |
+
data.items.forEach(item => {
|
| 318 |
+
html += `
|
| 319 |
+
<div class="card">
|
| 320 |
+
<div class="card-label label-live">LIVE</div>
|
| 321 |
+
<div class="frame">
|
| 322 |
+
<iframe src="${item.iframe}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
|
| 323 |
+
</div>
|
| 324 |
+
<div class="foot">
|
| 325 |
+
<a href="${item.hf}" target="_blank">${item.title}</a>
|
| 326 |
+
</div>
|
| 327 |
+
</div>
|
| 328 |
+
`;
|
| 329 |
+
});
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
html += '</div>';
|
| 333 |
+
|
| 334 |
+
// Add pagination
|
| 335 |
+
html += `
|
| 336 |
+
<div class="pagination">
|
| 337 |
+
<button ${currentPage <= 1 ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage-1})">« Previous</button>
|
| 338 |
+
<span>Page ${currentPage} of ${data.total_pages}</span>
|
| 339 |
+
<button ${currentPage >= data.total_pages ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage+1})">Next »</button>
|
| 340 |
+
</div>
|
| 341 |
+
`;
|
| 342 |
+
|
| 343 |
+
content.innerHTML = html;
|
| 344 |
+
});
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// Create tabs
|
| 348 |
+
// Special tabs first (Popular, BEST, NEW)
|
| 349 |
+
['Popular', 'BEST', 'NEW'].forEach(specialCat => {
|
| 350 |
+
const b = document.createElement('button');
|
| 351 |
+
b.className = 'tab ' + specialCat.toLowerCase();
|
| 352 |
+
b.textContent = specialCat;
|
| 353 |
+
b.dataset.c = specialCat;
|
| 354 |
+
b.onclick = function() { loadCategory(specialCat, 1); };
|
| 355 |
+
tabs.appendChild(b);
|
| 356 |
+
});
|
| 357 |
+
|
| 358 |
+
// Regular category tabs
|
| 359 |
+
cats.forEach(c => {
|
| 360 |
+
if (!['Popular', 'BEST', 'NEW'].includes(c)) {
|
| 361 |
+
const b = document.createElement('button');
|
| 362 |
+
b.className = 'tab';
|
| 363 |
+
b.textContent = c;
|
| 364 |
+
b.dataset.c = c;
|
| 365 |
+
b.onclick = function() { loadCategory(c, 1); };
|
| 366 |
+
tabs.appendChild(b);
|
| 367 |
+
}
|
| 368 |
+
});
|
| 369 |
+
|
| 370 |
+
// Start with Popular tab
|
| 371 |
+
loadCategory('Popular', 1);
|
| 372 |
+
</script>
|
| 373 |
+
</body>
|
| 374 |
+
</html>''')
|
| 375 |
+
|
| 376 |
+
# Return the rendered template
|
| 377 |
+
return render_template('index.html', cats=list(CATEGORIES.keys()))
|
| 378 |
+
|
| 379 |
+
if __name__ == '__main__':
|
| 380 |
+
app.run(host='0.0.0.0', port=7860)
|