aiqcamp commited on
Commit
5af9b43
Β·
verified Β·
1 Parent(s): fff4f5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +308 -37
app.py CHANGED
@@ -1,49 +1,320 @@
 
 
1
 
2
- import gradio as gr
3
- from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
4
 
5
- # Load Whisper for ASR
6
- asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
 
 
 
 
 
7
 
8
- # Load Grammar Scoring Model (CoLA)
9
- cola_model = AutoModelForSequenceClassification.from_pretrained("textattack/roberta-base-CoLA")
10
- cola_tokenizer = AutoTokenizer.from_pretrained("textattack/roberta-base-CoLA")
11
- grammar_pipeline = pipeline("text-classification", model=cola_model, tokenizer=cola_tokenizer)
 
 
 
 
 
12
 
13
- # Load Grammar Correction Model (T5)
14
- correction_pipeline = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
15
-
16
- def process_audio(audio):
17
- if audio is None:
18
- return "No audio provided.", "", ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- # Step 1: Transcription
21
- transcription = asr_pipeline(audio)["text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- # Step 2: Grammar Scoring
24
- score_output = grammar_pipeline(transcription)[0]
25
- label = score_output["label"]
26
- confidence = score_output["score"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- # Step 3: Grammar Correction
29
- corrected = correction_pipeline(transcription, max_length=128)[0]["generated_text"]
 
 
 
 
 
 
 
30
 
31
- return transcription, f"{label} ({confidence:.2f})", corrected
 
32
 
33
- demo = gr.Interface(
34
- fn=process_audio,
35
- inputs=gr.Audio(sources=["microphone", "upload"], type="filepath", label="🎀 Speak or Upload Audio (.wav)"),
36
- outputs=[
37
- gr.Textbox(label="πŸ“ Transcription"),
38
- gr.Textbox(label="βœ… Grammar Score"),
39
- gr.Textbox(label="✍️ Grammar Correction")
40
- ],
41
- title="πŸŽ™οΈ Voice Grammar Scorer",
42
- description="Record or upload a WAV file. This app transcribes your voice, scores its grammar, and suggests corrections.",
43
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- if __name__ == "__main__":
46
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
-
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import os, re, json
3
 
4
+ app = Flask(__name__)
 
5
 
6
+ # ────────────────────────── 1. CONFIGURATION ──────────────────────────
7
+ # Domains that commonly block iframes
8
+ BLOCKED_DOMAINS = [
9
+ "naver.com", "daum.net", "google.com",
10
+ "facebook.com", "instagram.com", "kakao.com",
11
+ "ycombinator.com"
12
+ ]
13
 
14
+ # ────────────────────────── 2. CURATED CATEGORIES ──────────────────────────
15
+ CATEGORIES = {
16
+ "Popular": [
17
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-REAL",
18
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
19
+ "https://huggingface.co/spaces/Dagfinn1962/Midjourney-Free", ####
20
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
21
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
22
+ "https://huggingface.co/spaces/Heartsync/Novel-NSFW",
23
 
24
+ "https://huggingface.co/spaces/erax/EraX-NSFW-V1.0", ###
25
+ "https://huggingface.co/spaces/yoinked/da_nsfw_checker", #####
26
+ "https://huggingface.co/spaces/LearningnRunning/adult_image_detector", ###
27
+ ],
28
+ "BEST": [
29
+ "https://huggingface.co/spaces/Heartsync/adult",
30
+ "https://huggingface.co/spaces/ginigen/Flux-VIDEO",
31
+ "https://huggingface.co/spaces/openfree/DreamO-video",
32
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
33
+ "https://huggingface.co/spaces/Heartsync/NSFW-novels",
34
+ "https://huggingface.co/spaces/fantaxy/fantasy-novel",
35
+
36
+ ],
37
+
38
+ "TEXT generate": [
39
+ "https://huggingface.co/spaces/Heartsync/Novel-NSFW",
40
+ "https://huggingface.co/spaces/fantaxy/fantasy-novel",
41
+ "https://huggingface.co/spaces/Heartsync/NSFW-novels",
42
+ ],
43
+
44
+ "TEXT TO IMAGE": [
45
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored",
46
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-photo",
47
+ "https://huggingface.co/spaces/Heartsync/adult",
48
+ "https://huggingface.co/spaces/Heartsync/NSFW-novels",
49
+ "https://huggingface.co/spaces/IbarakiDouji/WAI-NSFW-illustrious-SDXL", ###
50
+ "https://huggingface.co/spaces/armen425221356/UnfilteredAI-NSFW-gen-v2_self_parms", ####
51
+
52
+ ],
53
+ "IMAGE TO VIDEO": [
54
+ "https://huggingface.co/spaces/Heartsync/adult",
55
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video",
56
+ "https://huggingface.co/spaces/Heartsync/NSFW-Uncensored-video2",
57
+ "https://huggingface.co/spaces/openfree/DreamO-video",
58
+ "https://huggingface.co/spaces/Heartsync/wan2-1-fast-security",
59
+ "https://huggingface.co/spaces/ginigen/Flux-VIDEO",
60
+ "https://huggingface.co/spaces/Heartsync/WAN-VIDEO-AUDIO",
61
+ ],
62
 
63
+ "IMAGE IN/OUT-PAINTING": [
64
+ "https://huggingface.co/spaces/ginigen/FLUX-Ghibli-LoRA2",
65
+ "https://huggingface.co/spaces/davecarrau/nsfw-face-swap", ###
66
+ "https://huggingface.co/spaces/VIDraft/ReSize-Image-Outpainting",
67
+ "https://huggingface.co/spaces/aiqcamp/REMOVAL-TEXT-IMAGE",
68
+ "https://huggingface.co/spaces/ginigen/MagicFace-V3",
69
+ "https://huggingface.co/spaces/openfree/ColorRevive",
70
+ "https://huggingface.co/spaces/ginigen/VisualCloze",
71
+ "https://huggingface.co/spaces/fantos/textcutobject",
72
+
73
+ ],
74
+
75
+ "Extension": [
76
+ "https://huggingface.co/spaces/erax/EraX-NSFW-V1.0", ###
77
+ "https://huggingface.co/spaces/yoinked/da_nsfw_checker", #####
78
+ "https://huggingface.co/spaces/LearningnRunning/adult_image_detector", ###
79
+
80
+ "https://huggingface.co/spaces/VIDraft/ACE-Singer",
81
+ "https://huggingface.co/spaces/VIDraft/Voice-Clone-Podcast",
82
+ "https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
83
+ "https://huggingface.co/spaces/openfree/Multilingual-TTS",
84
+ "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
85
+ "https://huggingface.co/spaces/ginigen/SFX-Sound-magic",
86
+ "https://huggingface.co/spaces/fantaxy/Remove-Video-Background",
87
+ "https://huggingface.co/spaces/VIDraft/stable-diffusion-3.5-large-turboX",
88
 
89
+ "https://huggingface.co/spaces/aiqtech/imaginpaint",
90
+ "https://huggingface.co/spaces/openfree/ultpixgen",
91
+ # "https://huggingface.co/spaces/ginipick/Change-Hair",
92
+ # "https://huggingface.co/spaces/ginigen/Every-Text",
93
+
94
+ ],
95
+
96
+ "Utility": [
97
+ "https://huggingface.co/spaces/openfree/Chart-GPT",
98
+ "https://huggingface.co/spaces/ginipick/AI-BOOK",
99
+ "https://huggingface.co/spaces/openfree/Live-Podcast",
100
+ "https://huggingface.co/spaces/openfree/AI-Podcast",
101
+ "https://huggingface.co/spaces/ginipick/FLUXllama",
102
+ "https://huggingface.co/spaces/VIDraft/Polaroid-Style",
103
+ "https://huggingface.co/spaces/ginigen/text3d-r1",
104
+ "https://huggingface.co/spaces/openfree/Naming",
105
+ "https://huggingface.co/spaces/ginigen/3D-LLAMA-V1",
106
+ "https://huggingface.co/spaces/fantaxy/flx-pulid",
107
+ ],
108
+ }
109
 
110
+ # ────────────────────────── 3. URL HELPERS ──────────────────────────
111
+ def direct_url(hf_url):
112
+ m = re.match(r"https?://huggingface\.co/spaces/([^/]+)/([^/?#]+)", hf_url)
113
+ if not m:
114
+ return hf_url
115
+ owner, name = m.groups()
116
+ owner = owner.lower()
117
+ name = name.replace('.', '-').replace('_', '-').lower()
118
+ return f"https://{owner}-{name}.hf.space"
119
 
120
+ def screenshot_url(url):
121
+ return f"https://image.thum.io/get/fullpage/{url}"
122
 
123
+ def process_url_for_preview(url):
124
+ """Returns (preview_url, mode)"""
125
+ # Handle blocked domains first
126
+ if any(d for d in BLOCKED_DOMAINS if d in url):
127
+ return screenshot_url(url), "snapshot"
128
+
129
+ # Special case handling for problematic URLs
130
+ if "vibe-coding-tetris" in url or "World-of-Tank-GAME" in url or "Minesweeper-Game" in url:
131
+ return screenshot_url(url), "snapshot"
132
+
133
+ # General HF space handling
134
+ try:
135
+ if "huggingface.co/spaces" in url:
136
+ parts = url.rstrip("/").split("/")
137
+ if len(parts) >= 5:
138
+ owner = parts[-2]
139
+ name = parts[-1]
140
+ embed_url = f"https://huggingface.co/spaces/{owner}/{name}/embed"
141
+ return embed_url, "iframe"
142
+ except Exception:
143
+ return screenshot_url(url), "snapshot"
144
+
145
+ # Default handling
146
+ return url, "iframe"
147
 
148
+ # ────────────────────────── 4. API ROUTES ──────────────────────────
149
+ @app.route('/api/category')
150
+ def api_category():
151
+ cat = request.args.get('name', '')
152
+ urls = CATEGORIES.get(cat, [])
153
+
154
+ # Add pagination for categories
155
+ page = int(request.args.get('page', 1))
156
+ per_page = int(request.args.get('per_page', 4)) # 4 per page for 2x2 grid
157
+
158
+ total_pages = max(1, (len(urls) + per_page - 1) // per_page)
159
+ start = (page - 1) * per_page
160
+ end = min(start + per_page, len(urls))
161
+
162
+ urls_page = urls[start:end]
163
+
164
+ items = [
165
+ {
166
+ "title": url.split('/')[-1],
167
+ "owner": url.split('/')[-2] if '/spaces/' in url else '',
168
+ "iframe": direct_url(url),
169
+ "shot": screenshot_url(url),
170
+ "hf": url
171
+ } for url in urls_page
172
+ ]
173
+
174
+ return jsonify({
175
+ "items": items,
176
+ "page": page,
177
+ "total_pages": total_pages
178
+ })
179
 
180
+ # ────────────────────────── 5. MAIN ROUTES ──────────────────────────
181
+ @app.route('/')
182
+ def home():
183
+ os.makedirs('templates', exist_ok=True)
184
+
185
+ with open('templates/index.html', 'w', encoding='utf-8') as fp:
186
+ fp.write(r'''<!DOCTYPE html>
187
+ <html>
188
+ <head>
189
+ <meta charset="utf-8">
190
+ <meta name="viewport" content="width=device-width, initial-scale=1">
191
+ <title>Free NSFW Hub</title>
192
+ <style>
193
+ @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;600&display=swap');
194
+ body{margin:0;font-family:Nunito,sans-serif;background:#f6f8fb;}
195
+ .tabs{display:flex;flex-wrap:wrap;gap:8px;padding:16px;}
196
+ .tab{padding:6px 14px;border:none;border-radius:18px;background:#e2e8f0;font-weight:600;cursor:pointer;}
197
+ .tab.active{background:#a78bfa;color:#1a202c;}
198
+ /* Updated grid to show 2x2 layout */
199
+ .grid{display:grid;grid-template-columns:repeat(2,1fr);gap:20px;padding:0 16px 60px;max-width:1200px;margin:0 auto;}
200
+ @media(max-width:800px){.grid{grid-template-columns:1fr;}}
201
+ /* Increased card height for larger display */
202
+ .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;}
203
+ .frame{flex:1;position:relative;overflow:hidden;}
204
+ .frame iframe{position:absolute;width:166.667%;height:166.667%;transform:scale(.6);transform-origin:top left;border:0;}
205
+ .frame img{width:100%;height:100%;object-fit:cover;}
206
+ .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);}
207
+ .label-live{background:linear-gradient(135deg, #00c6ff, #0072ff);color:white;}
208
+ .label-static{background:linear-gradient(135deg, #ff9a9e, #fad0c4);color:#333;}
209
+ .foot{height:44px;background:#fafafa;display:flex;align-items:center;justify-content:center;border-top:1px solid #eee;}
210
+ .foot a{font-size:.82rem;font-weight:700;color:#4a6dd8;text-decoration:none;}
211
+ .pagination{display:flex;justify-content:center;margin:20px 0;gap:10px;}
212
+ .pagination button{padding:5px 15px;border:none;border-radius:20px;background:#e2e8f0;cursor:pointer;}
213
+ .pagination button:disabled{opacity:0.5;cursor:not-allowed;}
214
+ </style>
215
+ </head>
216
+ <body>
217
+ <header style="text-align: center; padding: 20px; background: linear-gradient(135deg, #f6f8fb, #e2e8f0); border-bottom: 1px solid #ddd;">
218
+ <h1 style="margin-bottom: 10px;">πŸ”₯Free NSFW Hub</h1>
219
+ <p style="margin-bottom: 15px; color: #666; font-size: 14px;">
220
+ A curated collection of the most popular and polished NSFW Detection projects on Hugging Face Spaces,<br>
221
+ organized for easy visual exploration and discovery.
222
+ </p>
223
+ <p>
224
+ <a href="https://huggingface.co/spaces/Heartsync/FREE-NSFW-HUB" target="_blank"><img src="https://img.shields.io/static/v1?label=huggingface&message=FREE%20NSFW%20HUB&color=%230000ff&labelColor=%23800080&logo=huggingface&logoColor=%23ffa500&style=for-the-badge" alt="badge"></a>
225
+ </p>
226
+
227
+ </header>
228
+ <div class="tabs" id="tabs"></div>
229
+ <div id="content"></div>
230
+ <script>
231
+ // Basic configuration
232
+ const cats = {{cats|tojson}};
233
+ const tabs = document.getElementById('tabs');
234
+ const content = document.getElementById('content');
235
+ let active = "";
236
+ let currentPage = 1;
237
+ // Simple utility functions
238
+ function makeRequest(url, method, data, callback) {
239
+ const xhr = new XMLHttpRequest();
240
+ xhr.open(method, url, true);
241
+ xhr.onreadystatechange = function() {
242
+ if (xhr.readyState === 4 && xhr.status === 200) {
243
+ callback(JSON.parse(xhr.responseText));
244
+ }
245
+ };
246
+ if (method === 'POST') {
247
+ xhr.send(data);
248
+ } else {
249
+ xhr.send();
250
+ }
251
+ }
252
+ function updateTabs() {
253
+ Array.from(tabs.children).forEach(b => {
254
+ b.classList.toggle('active', b.dataset.c === active);
255
+ });
256
+ }
257
+ // Tab handler for categories
258
+ function loadCategory(cat, page) {
259
+ if(cat === active && currentPage === page) return;
260
+ active = cat;
261
+ currentPage = page || 1;
262
+ updateTabs();
263
+
264
+ content.innerHTML = '<p style="text-align:center;padding:40px">Loading…</p>';
265
+
266
+ makeRequest('/api/category?name=' + encodeURIComponent(cat) + '&page=' + currentPage + '&per_page=4', 'GET', null, function(data) {
267
+ let html = '<div class="grid">';
268
+
269
+ if(data.items.length === 0) {
270
+ html += '<p style="grid-column:1/-1;text-align:center;padding:40px">No items in this category.</p>';
271
+ } else {
272
+ data.items.forEach(item => {
273
+ html += `
274
+ <div class="card">
275
+ <div class="card-label label-live">LIVE</div>
276
+ <div class="frame">
277
+ <iframe src="${item.iframe}" loading="lazy" sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads"></iframe>
278
+ </div>
279
+ <div class="foot">
280
+ <a href="${item.hf}" target="_blank">${item.title}</a>
281
+ </div>
282
+ </div>
283
+ `;
284
+ });
285
+ }
286
+
287
+ html += '</div>';
288
+
289
+ // Add pagination
290
+ html += `
291
+ <div class="pagination">
292
+ <button ${currentPage <= 1 ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage-1})">Β« Previous</button>
293
+ <span>Page ${currentPage} of ${data.total_pages}</span>
294
+ <button ${currentPage >= data.total_pages ? 'disabled' : ''} onclick="loadCategory('${cat}', ${currentPage+1})">Next Β»</button>
295
+ </div>
296
+ `;
297
+
298
+ content.innerHTML = html;
299
+ });
300
+ }
301
+ // Create category tabs
302
+ cats.forEach(c => {
303
+ const b = document.createElement('button');
304
+ b.className = 'tab';
305
+ b.textContent = c;
306
+ b.dataset.c = c;
307
+ b.onclick = function() { loadCategory(c, 1); };
308
+ tabs.appendChild(b);
309
+ });
310
+ // Start with the first category (Productivity)
311
+ loadCategory(cats[0], 1);
312
+ </script>
313
+ </body>
314
+ </html>''')
315
+
316
+ # Return the rendered template
317
+ return render_template('index.html', cats=list(CATEGORIES.keys()))
318
 
319
+ if __name__ == '__main__':
320
+ app.run(host='0.0.0.0', port=7860)