File size: 28,272 Bytes
fb1f165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2eb0e4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd7ad6c
2eb0e4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb1f165
 
483d945
3cd9aad
 
 
 
fb1f165
3cd9aad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb1f165
3cd9aad
 
 
 
 
 
fb1f165
 
1b40f3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb1f165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c1a185
fb1f165
e2c1bdc
fb1f165
a475042
8522c92
fb1f165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
from flask import Flask, render_template, request, jsonify
import os, re, json

app = Flask(__name__)

# ────────────────────────── 1. CONFIGURATION ──────────────────────────

# Domains that commonly block iframes
BLOCKED_DOMAINS = [
    "naver.com", "daum.net", "google.com",
    "facebook.com", "instagram.com", "kakao.com",
    "ycombinator.com"
]

# ────────────────────────── 2. CURATED CATEGORIES ──────────────────────────
CATEGORIES = {
    "Popular": [

        "https://huggingface.co/spaces/fantaxy/ofai-flx-logo",
        "https://huggingface.co/spaces/aiqtech/FLUX-Ghibli-Studio-LoRA",
        "https://huggingface.co/spaces/seawolf2357/REALVISXL-V5",
        "https://huggingface.co/spaces/fantos/flx8lora",
        "https://huggingface.co/spaces/ginipick/Realtime-FLUX",
        "https://huggingface.co/spaces/fantaxy/flx-pulid",
        "https://huggingface.co/spaces/ginipick/FLUX-Prompt-Generator",
        "https://huggingface.co/spaces/aiqtech/kofaceid",
        "https://huggingface.co/spaces/aiqtech/flxgif",
        "https://huggingface.co/spaces/fantos/flxfashmodel",
        "https://huggingface.co/spaces/fantos/flxcontrol",
        "https://huggingface.co/spaces/fantos/textcutobject",
        "https://huggingface.co/spaces/seawolf2357/flxloraexp",
        "https://huggingface.co/spaces/fantaxy/flxloraexp",
        "https://huggingface.co/spaces/aiqtech/imaginpaint",
        "https://huggingface.co/spaces/ginipick/FLUXllama",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
        "https://huggingface.co/spaces/fantaxy/flx-upscale",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
        "https://huggingface.co/spaces/fantos/VoiceClone",
        "https://huggingface.co/spaces/fantaxy/Rolls-Royce",
        "https://huggingface.co/spaces/aiqtech/FLUX-military",
        "https://huggingface.co/spaces/fantaxy/FLUX-Animations",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
        "https://huggingface.co/spaces/ginipick/Time-Stream",
        "https://huggingface.co/spaces/seawolf2357/sd-prompt-gen",
        "https://huggingface.co/spaces/openfree/MagicFace-V3",
        "https://huggingface.co/spaces/Heartsync/adult",
        "https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL",
        "https://huggingface.co/spaces/seawolf2357/img2vid",
        "https://huggingface.co/spaces/openfree/image-to-vector",
        "https://huggingface.co/spaces/openfree/DreamO-video",
        "https://huggingface.co/spaces/VIDraft/FramePack_rotate_landscape",
        "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
        "https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
        "https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB",
        "https://huggingface.co/spaces/Heartsync/NSFW-image",
        "https://huggingface.co/spaces/Heartsync/NSFW-detection",
        "https://huggingface.co/spaces/Heartsync/VEO3-RealTime",
        "https://huggingface.co/spaces/ginigen/VEO3-Free",
        "https://huggingface.co/spaces/ginigen/FLUX-Text-Tree-Image",
        "https://huggingface.co/spaces/ginigen/text3d-r1",
        "https://huggingface.co/spaces/VIDraft/stable-diffusion-3.5-large-turboX",
        
    ],
    "BEST": [

        "https://huggingface.co/spaces/openfree/Cycle-Navigator",
        "https://huggingface.co/spaces/ginigen/Flux-Kontext-FaceLORA",
        "https://huggingface.co/spaces/ginigen/Seedance-Free",
        "https://huggingface.co/spaces/VIDraft/SOMA-AGI",
        "https://huggingface.co/spaces/aiqtech/Heatmap-Leaderboard",
        "https://huggingface.co/spaces/VIDraft/DNA-CASINO",
        "https://huggingface.co/spaces/aiqtech/SOMA-Oriental",
        "https://huggingface.co/spaces/fantaxy/YTB-TEST",
        "https://huggingface.co/spaces/aiqtech/Contributors-Leaderboard",
        "https://huggingface.co/spaces/ginigen/text3d-r1",
        "https://huggingface.co/spaces/VIDraft/stable-diffusion-3.5-large-turboX",
        "https://huggingface.co/spaces/openfree/Korean-Leaderboard",
        "https://huggingface.co/spaces/fantos/flxcontrol",
        "https://huggingface.co/spaces/aiqtech/FLUX-Ghibli-Studio-LoRA",
        "https://huggingface.co/spaces/openfree/AI-Podcast",
        "https://huggingface.co/spaces/ginigen/Workflow-Canvas",
        "https://huggingface.co/spaces/ginigen/3D-LLAMA",
        "https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
        "https://huggingface.co/spaces/VIDraft/ACE-Singer",
        "https://huggingface.co/spaces/ginipick/AI-BOOK",
        "https://huggingface.co/spaces/immunobiotech/drug-discovery",
        "https://huggingface.co/spaces/VIDraft/Robo-Beam",
        "https://huggingface.co/spaces/fantaxy/fantasy-novel",
        "https://huggingface.co/spaces/immunobiotech/Gemini-MICHELIN",
        "https://huggingface.co/spaces/openfree/Chart-GPT",
        "https://huggingface.co/spaces/ginipick/NH-Korea",
        "https://huggingface.co/spaces/VIDraft/Voice-Clone-Podcast",
        "https://huggingface.co/spaces/ginipick/Private-AI",
        "https://huggingface.co/spaces/ginigen/Flux-VIDEO",
        "https://huggingface.co/spaces/openfree/open-GAMMA",
        "https://huggingface.co/spaces/ginipick/PharmAI-Korea",
        "https://huggingface.co/spaces/ginipick/Pharmacy",
        "https://huggingface.co/spaces/ginipick/PDF-EXAM",
        "https://huggingface.co/spaces/ginipick/IDEA-DESIGN",
        "https://huggingface.co/spaces/openfree/DreamO-video",
        "https://huggingface.co/spaces/ginipick/10m-marketing",
        "https://huggingface.co/spaces/VIDraft/voice-trans",
        "https://huggingface.co/spaces/VIDraft/NH-Prediction",
        "https://huggingface.co/spaces/fantos/flx8lora",
        "https://huggingface.co/spaces/ginigen/MagicFace-V3",
        "https://huggingface.co/spaces/openfree/Live-Podcast",
        "https://huggingface.co/spaces/seawolf2357/ocrlatex",
        "https://huggingface.co/spaces/Heartsync/VEO3-RealTime",
        "https://huggingface.co/spaces/ginigen/VEO3-Free",
        "https://huggingface.co/spaces/openfree/MagicFace-V3",
        "https://huggingface.co/spaces/aiqtech/FLUX-military",
        "https://huggingface.co/spaces/fantaxy/flxloraexp",
        "https://huggingface.co/spaces/Heartsync/WAN2-1-fast-T2V-FusioniX",
        "https://huggingface.co/spaces/ginigen/FLUXllama-Multilingual",
        "https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",
        "https://huggingface.co/spaces/fantaxy/Rolls-Royce",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL",
        "https://huggingface.co/spaces/ginipick/Realtime-FLUX",
        "https://huggingface.co/spaces/aiqtech/imaginpaint",
        "https://huggingface.co/spaces/aiqtech/flxgif",
        "https://huggingface.co/spaces/fantos/flxfashmodel",
        "https://huggingface.co/spaces/aiqtech/kofaceid",
        "https://huggingface.co/spaces/ginipick/FLUX-Prompt-Generator",
        "https://huggingface.co/spaces/seawolf2357/REALVISXL-V5",
        "https://huggingface.co/spaces/fantaxy/FLUX-Animations",
        "https://huggingface.co/spaces/fantaxy/flx-pulid",
        "https://huggingface.co/spaces/fantaxy/ofai-flx-logo",
        "https://huggingface.co/spaces/openfree/image-to-vector",
        "https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB",
        "https://huggingface.co/spaces/seawolf2357/sd-prompt-gen",
        "https://huggingface.co/spaces/VIDraft/FramePack_rotate_landscape",
        "https://huggingface.co/spaces/ginipick/FLUXllama",
        "https://huggingface.co/spaces/Heartsync/NSFW-image",
        "https://huggingface.co/spaces/seawolf2357/img2vid",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
        "https://huggingface.co/spaces/Heartsync/NSFW-detection",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
        "https://huggingface.co/spaces/Heartsync/adult",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
        "https://huggingface.co/spaces/fantos/VoiceClone",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
        "https://huggingface.co/spaces/fantaxy/flx-upscale",
        "https://huggingface.co/spaces/seawolf2357/flxloraexp",
        "https://huggingface.co/spaces/ginipick/Time-Stream",
        "https://huggingface.co/spaces/fantos/textcutobject",
    
        
    ],
    "NEW": [
        "https://huggingface.co/spaces/VIDraft/ACE-Singer",        
        "https://huggingface.co/spaces/ginipick/AI-BOOK",
        "https://huggingface.co/spaces/openfree/Best-AI", 
        "https://huggingface.co/spaces/aiqtech/Heatmap-Leaderboard", 
        "https://huggingface.co/spaces/VIDraft/DNA-CASINO", 
        "https://huggingface.co/spaces/ginigen/Seedance-Free", 
        "https://huggingface.co/spaces/aiqtech/SOMA-Oriental", 
        "https://huggingface.co/spaces/ginigen/Flux-Kontext-FaceLORA", 
        "https://huggingface.co/spaces/VIDraft/SOMA-AGI", 
        "https://huggingface.co/spaces/Heartsync/VEO3-RealTime", 
        "https://huggingface.co/spaces/openfree/Open-GAMMA", 
        "https://huggingface.co/spaces/ginigen/VEO3-Free", 
        "https://huggingface.co/spaces/Heartsync/WAN2-1-fast-T2V-FusioniX", 
        "https://huggingface.co/spaces/VIDraft/voice-trans", 
        "https://huggingface.co/spaces/VIDraft/Robo-Beam", 
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL", 
        "https://huggingface.co/spaces/fantaxy/fantasy-novel", 
        "https://huggingface.co/spaces/openfree/Chart-GPT", 
        "https://huggingface.co/spaces/Heartsync/Novel-NSFW",   
        "https://huggingface.co/spaces/ginigen/FLUX-Ghibli-LoRA2",     
        "https://huggingface.co/spaces/Heartsync/WAN-VIDEO-AUDIO",       
        "https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",       
        "https://huggingface.co/spaces/ginigen/Flux-VIDEO",    
        "https://huggingface.co/spaces/aiqcamp/REMOVAL-TEXT-IMAGE",   
        "https://huggingface.co/spaces/VIDraft/Mistral-RAG-BitSix",    
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
        "https://huggingface.co/spaces/fantaxy/YTB-TEST", 
        "https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB", 
        "https://huggingface.co/spaces/Heartsync/adult",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",  
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",          
        "https://huggingface.co/spaces/openfree/Live-Podcast",
        "https://huggingface.co/spaces/openfree/AI-Podcast",
        "https://huggingface.co/spaces/ginipick/NH-Korea",
        "https://huggingface.co/spaces/VIDraft/NH-Prediction",
        "https://huggingface.co/spaces/VIDraft/Voice-Clone-Podcast",
        "https://huggingface.co/spaces/ginipick/PDF-EXAM",        
        "https://huggingface.co/spaces/openfree/Game-Gallery",
        "https://huggingface.co/spaces/openfree/Vibe-Game",
        "https://huggingface.co/spaces/ginipick/IDEA-DESIGN",
        "https://huggingface.co/spaces/openfree/Cycle-Navigator",
        "https://huggingface.co/spaces/openfree/DreamO-video",
        "https://huggingface.co/spaces/Heartsync/NSFW-detection",      


    ],
    "Productivity": [
        "https://huggingface.co/spaces/aiqtech/Heatmap-Leaderboard", 
        "https://huggingface.co/spaces/VIDraft/DNA-CASINO", 
        "https://huggingface.co/spaces/openfree/Open-GAMMA", 
        "https://huggingface.co/spaces/VIDraft/Robo-Beam",         
        "https://huggingface.co/spaces/VIDraft/voice-trans", 
        "https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB", 
        "https://huggingface.co/spaces/openfree/Chart-GPT",
        "https://huggingface.co/spaces/ginipick/AI-BOOK",       
        "https://huggingface.co/spaces/VIDraft/Voice-Clone-Podcast",
        "https://huggingface.co/spaces/ginipick/PDF-EXAM",
        "https://huggingface.co/spaces/ginigen/perflexity-clone",  
        "https://huggingface.co/spaces/ginipick/IDEA-DESIGN",    
        "https://huggingface.co/spaces/ginipick/10m-marketing",
        "https://huggingface.co/spaces/openfree/Live-Podcast",
        "https://huggingface.co/spaces/openfree/AI-Podcast",
        "https://huggingface.co/spaces/ginipick/QR-Canvas-plus",
        "https://huggingface.co/spaces/openfree/Badge",
        "https://huggingface.co/spaces/VIDraft/mouse-webgen",
        "https://huggingface.co/spaces/openfree/Vibe-Game",      
        "https://huggingface.co/spaces/VIDraft/NH-Prediction",
        "https://huggingface.co/spaces/ginipick/NH-Korea",     
        "https://huggingface.co/spaces/openfree/Naming",
        "https://huggingface.co/spaces/ginipick/Change-Hair",         
    ],
    "Multimodal": [
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
        "https://huggingface.co/spaces/fantaxy/YTB-TEST", 
        "https://huggingface.co/spaces/ginigen/Seedance-Free", 
        "https://huggingface.co/spaces/Heartsync/VEO3-RealTime",
        "https://huggingface.co/spaces/ginigen/VEO3-Free", 
        "https://huggingface.co/spaces/ginigen/VEO3-Directors", 
        "https://huggingface.co/spaces/Heartsync/WAN2-1-fast-T2V-FusioniX",        
        "https://huggingface.co/spaces/Heartsync/adult",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored", 
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",  
        "https://huggingface.co/spaces/Heartsync/WAN-VIDEO-AUDIO",   
        "https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",       
        "https://huggingface.co/spaces/ginigen/Flux-VIDEO",            
        "https://huggingface.co/spaces/ginigen/3D-LLAMA-V1",
        "https://huggingface.co/spaces/ginigen/Flux-VIDEO",            
        "https://huggingface.co/spaces/openfree/Multilingual-TTS",
        "https://huggingface.co/spaces/VIDraft/ACE-Singer",
        "https://huggingface.co/spaces/openfree/DreamO-video",
        "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/ENGLISH-Speaking-Scoring",
        "https://huggingface.co/spaces/fantaxy/Remove-Video-Background",
    ],
    "Professional": [
        "https://huggingface.co/spaces/Heartsync/NSFW-novels",
        "https://huggingface.co/spaces/aiqtech/SOMA-Oriental", 
        "https://huggingface.co/spaces/VIDraft/SOMA-AGI",         
        "https://huggingface.co/spaces/Heartsync/Novel-NSFW", 
        "https://huggingface.co/spaces/fantaxy/fantasy-novel",
        "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/openfree/Cycle-Navigator",
        "https://huggingface.co/spaces/VIDraft/Fashion-Fit",
        "https://huggingface.co/spaces/openfree/Stock-Trading-Analysis",   
        "https://huggingface.co/spaces/ginipick/AgentX-Papers",        
        "https://huggingface.co/spaces/Heartsync/Papers-Leaderboard",
        "https://huggingface.co/spaces/VIDraft/PapersImpact",
        "https://huggingface.co/spaces/ginigen/multimodal-chat-mbti-korea",
    ],
    "Image": [
        "https://huggingface.co/spaces/ginigen/Flux-Kontext-FaceLORA",            
        "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL",         
        "https://huggingface.co/spaces/ginigen/FLUX-Ghibli-LoRA2",
        "https://huggingface.co/spaces/aiqcamp/REMOVAL-TEXT-IMAGE",  
        "https://huggingface.co/spaces/VIDraft/BAGEL-Websearch",   
        "https://huggingface.co/spaces/ginigen/Every-Text",
        "https://huggingface.co/spaces/ginigen/text3d-r1",
        "https://huggingface.co/spaces/ginipick/FLUXllama",
        "https://huggingface.co/spaces/ginigen/Workflow-Canvas", 
        "https://huggingface.co/spaces/ginigen/canvas-studio",
        "https://huggingface.co/spaces/VIDraft/ReSize-Image-Outpainting",
        "https://huggingface.co/spaces/Heartsync/FLUX-Vision",
        "https://huggingface.co/spaces/fantos/textcutobject",
        "https://huggingface.co/spaces/aiqtech/imaginpaint",
        "https://huggingface.co/spaces/openfree/ColorRevive",
        "https://huggingface.co/spaces/openfree/ultpixgen",
        "https://huggingface.co/spaces/VIDraft/Polaroid-Style",
        "https://huggingface.co/spaces/ginigen/VisualCloze",
        "https://huggingface.co/spaces/fantaxy/ofai-flx-logo",
        "https://huggingface.co/spaces/ginigen/interior-design",
        "https://huggingface.co/spaces/ginigen/MagicFace-V3",  
        "https://huggingface.co/spaces/fantaxy/flx-pulid",
        "https://huggingface.co/spaces/seawolf2357/Ghibli-Multilingual-Text-rendering",
        "https://huggingface.co/spaces/VIDraft/Open-Meme-Studio",
        "https://huggingface.co/spaces/VIDraft/stable-diffusion-3.5-large-turboX",
        "https://huggingface.co/spaces/aiqtech/flxgif",
        "https://huggingface.co/spaces/openfree/VectorFlow",
        "https://huggingface.co/spaces/ginigen/3D-LLAMA",        
        "https://huggingface.co/spaces/ginigen/Multi-LoRAgen",
    ],
    "LLM / VLM": [
        "https://huggingface.co/spaces/fantaxy/fantasy-novel",         
        "https://huggingface.co/spaces/ginigen/deepseek-r1-0528-API",   
        "https://huggingface.co/spaces/aiqcamp/Mistral-Devstral-API",
        "https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528",
        "https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528-qwen3-8b",   
        "https://huggingface.co/spaces/aiqcamp/deepseek-r1-0528", 
        "https://huggingface.co/spaces/aiqcamp/Mistral-Devstral-API",
        "https://huggingface.co/spaces/VIDraft/Mistral-RAG-BitSix",    
        "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",
    ],
}

# ────────────────────────── 3. URL HELPERS ──────────────────────────
def direct_url(hf_url):
    m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url)
    if not m:
        return hf_url
    owner, name = m.groups()
    owner = owner.lower()
    name = name.replace('.', '-').replace('_', '-').lower()
    return f"https://{owner}-{name}.hf.space"

def screenshot_url(url):
    return f"https://image.thum.io/get/fullpage/{url}"

def process_url_for_preview(url):
    """Returns (preview_url, mode)"""
    # Handle blocked domains first
    if any(d for d in BLOCKED_DOMAINS if d in url):
        return screenshot_url(url), "snapshot"
    
    # Special case handling for problematic URLs
    if "vibe-coding-tetris" in url or "World-of-Tank-GAME" in url or "Minesweeper-Game" in url:
        return screenshot_url(url), "snapshot"
    
    # General HF space handling
    try:
        if "huggingface.co/spaces" in url:
            parts = url.rstrip("/").split("/")
            if len(parts) >= 5:
                owner = parts[-2]
                name = parts[-1]
                embed_url = f"https://huggingface.co/spaces/{owner}/{name}/embed"
                return embed_url, "iframe"
    except Exception:
        return screenshot_url(url), "snapshot"
    
    # Default handling
    return url, "iframe"

# ────────────────────────── 4. API ROUTES ──────────────────────────
@app.route('/api/category')
def api_category():
    cat = request.args.get('name', '')
    urls = CATEGORIES.get(cat, [])
    
    # Add pagination for categories
    page = int(request.args.get('page', 1))
    per_page = int(request.args.get('per_page', 4))
    
    total_pages = max(1, (len(urls) + per_page - 1) // per_page)
    start = (page - 1) * per_page
    end = min(start + per_page, len(urls))
    
    urls_page = urls[start:end]
    
    items = [
        {
            "title": url.split('/')[-1],
            "owner": url.split('/')[-2] if '/spaces/' in url else '',
            "iframe": direct_url(url),
            "shot": screenshot_url(url),
            "hf": url
        } for url in urls_page
    ]
    
    return jsonify({
        "items": items,
        "page": page,
        "total_pages": total_pages
    })

# ────────────────────────── 5. MAIN ROUTES ──────────────────────────
@app.route('/')
def home():
    os.makedirs('templates', exist_ok=True)
    
    with open('templates/index.html', 'w', encoding='utf-8') as fp:
        fp.write(r'''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web Gallery</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;600&display=swap');
body{margin:0;font-family:Nunito,sans-serif;background:#f6f8fb;}
.tabs{display:flex;flex-wrap:wrap;gap:8px;padding:16px;}
.tab{padding:6px 14px;border:none;border-radius:18px;background:#e2e8f0;font-weight:600;cursor:pointer;}
.tab.active{background:#a78bfa;color:#1a202c;}
.tab.popular{background:#ff6b6b;color:white;}
.tab.popular.active{background:#fa5252;color:white;}
.tab.best{background:#4ecdc4;color:white;}
.tab.best.active{background:#38d9a9;color:white;}
.tab.new{background:#ffe066;color:#1a202c;}
.tab.new.active{background:#ffd43b;color:#1a202c;}
/* Updated grid to show 2x2 layout */
.grid{display:grid;grid-template-columns:repeat(2,1fr);gap:20px;padding:0 16px 60px;max-width:1200px;margin:0 auto;}
@media(max-width:800px){.grid{grid-template-columns:1fr;}}
/* Increased card height for larger display */
.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;}
.frame{flex:1;position:relative;overflow:hidden;}
.frame iframe{position:absolute;width:166.667%;height:166.667%;transform:scale(.6);transform-origin:top left;border:0;}
.frame img{width:100%;height:100%;object-fit:cover;}
.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);}
.label-live{background:linear-gradient(135deg, #00c6ff, #0072ff);color:white;}
.label-static{background:linear-gradient(135deg, #ff9a9e, #fad0c4);color:#333;}
.foot{height:44px;background:#fafafa;display:flex;align-items:center;justify-content:center;border-top:1px solid #eee;}
.foot a{font-size:.82rem;font-weight:700;color:#4a6dd8;text-decoration:none;}
.pagination{display:flex;justify-content:center;margin:20px 0;gap:10px;}
.pagination button{padding:5px 15px;border:none;border-radius:20px;background:#e2e8f0;cursor:pointer;}
.pagination button:disabled{opacity:0.5;cursor:not-allowed;}
</style>
</head>
<body>
<header style="text-align: center; padding: 20px; background: linear-gradient(135deg, #f6f8fb, #e2e8f0); border-bottom: 1px solid #ddd;">
  <h1 style="margin-bottom: 10px;">🌟OPEN & Free: BEST AI Playground</h1>
  <p>
    <a href="https://huggingface.co/OpenFreeAI" target="_blank"><img src="https://img.shields.io/static/v1?label=Community&message=OpenFree_AI&color=%23800080&labelColor=%23000080&logo=HUGGINGFACE&logoColor=%23ffa500&style=for-the-badge" alt="badge"></a>
    <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>
    <a href="https://huggingface.co/spaces/openfree/Best-AI" target="_blank"><img src="https://img.shields.io/static/v1?label=OpenFree&message=BEST%20AI%20Services&color=%230000ff&labelColor=%23000080&logo=huggingface&logoColor=%23ffa500&style=for-the-badge" alt="badge"></a>
  </p>    
</header>
<div class="tabs" id="tabs"></div>
<div id="content"></div>

<script>
// Basic configuration
const cats = {{cats|tojson}};
const tabs = document.getElementById('tabs');
const content = document.getElementById('content');
let active = "";
let currentPage = 1;

// Simple utility functions
function makeRequest(url, method, data, callback) {
  const xhr = new XMLHttpRequest();
  xhr.open(method, url, true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
      callback(JSON.parse(xhr.responseText));
    }
  };
  if (method === 'POST') {
    xhr.send(data);
  } else {
    xhr.send();
  }
}

function updateTabs() {
  Array.from(tabs.children).forEach(b => {
    b.classList.toggle('active', b.dataset.c === active);
  });
}

// Tab handlers
function loadCategory(cat, page) {
  if(cat === active && currentPage === page) return;
  active = cat;
  currentPage = page || 1;
  updateTabs();
  
  content.innerHTML = '<p style="text-align:center;padding:40px">Loading…</p>';
  
  makeRequest('/api/category?name=' + encodeURIComponent(cat) + '&page=' + currentPage + '&per_page=4', 'GET', null, function(data) {
    let html = '<div class="grid">';
    
    if(data.items.length === 0) {
      html += '<p style="grid-column:1/-1;text-align:center;padding:40px">No items in this category.</p>';
    } else {
      data.items.forEach(item => {
        html += `
          <div class="card">
            <div class="card-label label-live">LIVE</div>
            <div class="frame">
              <iframe src="${item.iframe}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
            </div>
            <div class="foot">
              <a href="${item.hf}" target="_blank">${item.title}</a>
            </div>
          </div>
        `;
      });
    }
    
    html += '</div>';
    
    // Add pagination
    html += `
      <div class="pagination">
        <button ${currentPage <= 1 ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage-1})">Β« Previous</button>
        <span>Page ${currentPage} of ${data.total_pages}</span>
        <button ${currentPage >= data.total_pages ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage+1})">Next Β»</button>
      </div>
    `;
    
    content.innerHTML = html;
  });
}

// Create tabs
// Special tabs first (Popular, BEST, NEW)
['Popular', 'BEST', 'NEW'].forEach(specialCat => {
  const b = document.createElement('button');
  b.className = 'tab ' + specialCat.toLowerCase();
  b.textContent = specialCat;
  b.dataset.c = specialCat;
  b.onclick = function() { loadCategory(specialCat, 1); };
  tabs.appendChild(b);
});

// Regular category tabs
cats.forEach(c => {
  if (!['Popular', 'BEST', 'NEW'].includes(c)) {
    const b = document.createElement('button');
    b.className = 'tab';
    b.textContent = c;
    b.dataset.c = c;
    b.onclick = function() { loadCategory(c, 1); };
    tabs.appendChild(b);
  }
});

// Start with Popular tab
loadCategory('Popular', 1);
</script>
</body>
</html>''')
    
    # Return the rendered template
    return render_template('index.html', cats=list(CATEGORIES.keys()))

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)