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 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Readability Analyzer</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
        
        body { font-family: 'Inter', sans-serif; }
        
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .glass-effect {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .hover-scale {
            transition: transform 0.3s ease;
        }
        
        .hover-scale:hover {
            transform: translateY(-2px);
        }
        
        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .pulse-animation {
            animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.7; }
        }
        
        .score-ring {
            transform: rotate(-90deg);
        }
        
        .score-ring circle {
            transition: stroke-dashoffset 0.5s ease;
        }
        
        .char-count {
            transition: all 0.3s ease;
        }
        
        .reading-level {
            transition: all 0.3s ease;
        }
        
        .tooltip {
            position: relative;
            cursor: help;
        }
        
        .tooltip:hover .tooltip-text {
            visibility: visible;
            opacity: 1;
        }
        
        .tooltip-text {
            visibility: hidden;
            opacity: 0;
            position: absolute;
            bottom: 125%;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 8px 12px;
            border-radius: 6px;
            font-size: 12px;
            white-space: nowrap;
            z-index: 10;
            transition: opacity 0.3s;
        }
        
        .tooltip-text::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            border: 5px solid transparent;
            border-top-color: rgba(0, 0, 0, 0.8);
        }
    </style>
</head>
<body class="min-h-screen gradient-bg">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <header class="text-center mb-8">
            <h1 class="text-4xl md:text-6xl font-bold text-white mb-4">
                <i class="fas fa-brain mr-3"></i>
                Readability Analyzer
            </h1>
            <p class="text-white/80 text-lg md:text-xl max-w-2xl mx-auto">
                Analyze your text's readability with advanced metrics and get actionable insights
            </p>
        </header>

        <!-- Main Content -->
        <div class="max-w-6xl mx-auto">
            <!-- Input Section -->
            <div class="bg-white/10 backdrop-blur-lg rounded-2xl p-6 mb-8 border border-white/20">
                <div class="flex items-center justify-between mb-4">
                    <h2 class="text-2xl font-semibold text-white">
                        <i class="fas fa-edit mr-2"></i>
                        Input Text
                    </h2>
                    <div class="flex items-center space-x-4">
                        <span class="text-white/70 text-sm">
                            <span id="wordCount" class="font-bold text-white">0</span> words
                        </span>
                        <span class="text-white/70 text-sm">
                            <span id="charCount" class="font-bold text-white">0</span> chars
                        </span>
                    </div>
                </div>
                
                <textarea 
                    id="textInput" 
                    class="w-full h-64 p-4 bg-white/10 border border-white/20 rounded-lg text-white placeholder-white/60 focus:outline-none focus:ring-2 focus:ring-white/50 resize-none"
                    placeholder="Paste or type your text here to analyze its readability..."
                ></textarea>
                
                <div class="flex flex-wrap gap-4 mt-4">
                    <button id="analyzeBtn" class="px-6 py-3 bg-white/20 hover:bg-white/30 text-white rounded-lg font-medium transition-all hover:scale-105">
                        <i class="fas fa-chart-line mr-2"></i>
                        Analyze Text
                    </button>
                    <button id="clearBtn" class="px-6 py-3 bg-red-500/20 hover:bg-red-500/30 text-white rounded-lg font-medium transition-all hover:scale-105">
                        <i class="fas fa-trash mr-2"></i>
                        Clear
                    </button>
                    <button id="sampleBtn" class="px-6 py-3 bg-green-500/20 hover:bg-green-500/30 text-white rounded-lg font-medium transition-all hover:scale-105">
                        <i class="fas fa-file-alt mr-2"></i>
                        Load Sample
                    </button>
                </div>
            </div>

            <!-- Results Section -->
            <div id="resultsSection" class="hidden">
                <!-- Overall Score -->
                <div class="grid md:grid-cols-2 gap-8 mb-8">
                    <div class="bg-white/10 backdrop-blur-lg rounded-2xl p-6 border border-white/20">
                        <h3 class="text-xl font-semibold text-white mb-4">
                            <i class="fas fa-star mr-2"></i>
                            Overall Readability Score
                        </h3>
                        <div class="relative w-32 h-32 mx-auto">
                            <svg class="w-32 h-32 score-ring">
                                <circle
                                    cx="64"
                                    cy="64"
                                    r="56"
                                    stroke="rgba(255,255,255,0.2)"
                                    stroke-width="8"
                                    fill="none"
                                />
                                <circle
                                    id="scoreCircle"
                                    cx="64"
                                    cy="64"
                                    r="56"
                                    stroke="#10b981"
                                    stroke-width="8"
                                    fill="none"
                                    stroke-dasharray="351.86"
                                    stroke-dashoffset="351.86"
                                />
                            </svg>
                            <div class="absolute inset-0 flex items-center justify-center">
                                <span id="overallScore" class="text-3xl font-bold text-white">0</span>
                                <span class="text-white/70 text-sm ml-1">/100</span>
                            </div>
                        </div>
                        <p id="scoreText" class="text-center text-white/80 mt-4">Analyzing...</p>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-2xl p-6 border border-white/20">
                        <h3 class="text-xl font-semibold text-white mb-4">
                            <i class="fas fa-graduation-cap mr-2"></i>
                            Reading Level
                        </h3>
                        <div class="text-center">
                            <div id="readingLevel" class="text-4xl font-bold text-white mb-2">--</div>
                            <div id="gradeLevel" class="text-white/80 mb-4">--</div>
                            <div id="readingTime" class="text-white/70">
                                <i class="fas fa-clock mr-2"></i>
                                ~-- min read
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Detailed Metrics -->
                <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">Flesch Score</h4>
                                <p class="text-white/60 text-sm">Higher is easier</p>
                            </div>
                            <div id="fleschScore" class="text-2xl font-bold text-green-400">--</div>
                        </div>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">Gunning Fog</h4>
                                <p class="text-white/60 text-sm">Years of education</p>
                            </div>
                            <div id="gunningFog" class="text-2xl font-bold text-blue-400">--</div>
                        </div>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">SMOG Index</h4>
                                <p class="text-white/60 text-sm">Simple Measure</p>
                            </div>
                            <div id="smogIndex" class="text-2xl font-bold text-purple-400">--</div>
                        </div>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">Sentences</h4>
                                <p class="text-white/60 text-sm">Total count</p>
                            </div>
                            <div id="sentenceCount" class="text-2xl font-bold text-yellow-400">--</div>
                        </div>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">Avg Words/Sentence</h4>
                                <p class="text-white/60 text-sm">Optimal: 15-20</p>
                            </div>
                            <div id="avgWordsPerSentence" class="text-2xl font-bold text-orange-400">--</div>
                        </div>
                    </div>

                    <div class="bg-white/10 backdrop-blur-lg rounded-xl p-4 border border-white/20 hover-scale">
                        <div class="flex items-center justify-between">
                            <div>
                                <h4 class="text-white font-medium">Complex Words</h4>
                                <p class="text-white/60 text-sm">3+ syllables</p>
                            </div>
                            <div id="complexWords" class="text-2xl font-bold text-red-400">--</div>
                        </div>
                    </div>
                </div>

                <!-- Recommendations -->
                <div class="bg-white/10 backdrop-blur-lg rounded-2xl p-6 border border-white/20">
                    <h3 class="text-xl font-semibold text-white mb-4">
                        <i class="fas fa-lightbulb mr-2"></i>
                        AI Recommendations
                    </h3>
                    <ul id="recommendations" class="space-y-3">
                        <li class="text-white/80 italic">Analyzing your text for personalized recommendations...</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <script>
        class ReadabilityAnalyzer {
            constructor() {
                this.initializeElements();
                this.bindEvents();
            }

            initializeElements() {
                this.textInput = document.getElementById('textInput');
                this.wordCount = document.getElementById('wordCount');
                this.charCount = document.getElementById('charCount');
                this.analyzeBtn = document.getElementById('analyzeBtn');
                this.clearBtn = document.getElementById('clearBtn');
                this.sampleBtn = document.getElementById('sampleBtn');
                this.resultsSection = document.getElementById('resultsSection');
            }

            bindEvents() {
                this.textInput.addEventListener('input', () => this.updateCounts());
                this.analyzeBtn.addEventListener('click', () => this.analyze());
                this.clearBtn.addEventListener('click', () => this.clear());
                this.sampleBtn.addEventListener('click', () => this.loadSample());
            }

            updateCounts() {
                const text = this.textInput.value;
                const words = text.trim() ? text.trim().split(/\s+/).length : 0;
                const chars = text.length;
                
                this.wordCount.textContent = words;
                this.charCount.textContent = chars;
            }

            clear() {
                this.textInput.value = '';
                this.wordCount.textContent = '0';
                this.charCount.textContent = '0';
                this.resultsSection.classList.add('hidden');
            }

            loadSample() {
                const sampleText = `Artificial intelligence is transforming how we live and work. From personalized recommendations on streaming platforms to autonomous vehicles navigating city streets, AI applications are becoming increasingly sophisticated. Machine learning algorithms analyze vast amounts of data to identify patterns and make predictions, while natural language processing enables computers to understand and respond to human language. As these technologies continue to advance, they promise to revolutionize industries ranging from healthcare to finance, creating new opportunities and challenges for society. The integration of AI into daily life raises important questions about privacy, ethics, and the future of human-machine collaboration.`;
                
                this.textInput.value = sampleText;
                this.updateCounts();
                this.analyze();
            }

            analyze() {
                const text = this.textInput.value.trim();
                if (!text) {
                    alert('Please enter some text to analyze.');
                    return;
                }

                this.resultsSection.classList.remove('hidden');
                this.resultsSection.classList.add('fade-in');

                const analysis = this.performAnalysis(text);
                this.displayResults(analysis);
            }

            performAnalysis(text) {
                const sentences = this.getSentences(text);
                const words = this.getWords(text);
                const syllables = words.reduce((sum, word) => sum + this.countSyllables(word), 0);
                const complexWords = words.filter(word => this.countSyllables(word) >= 3).length;

                const sentenceCount = sentences.length;
                const wordCount = words.length;
                const avgWordsPerSentence = wordCount / sentenceCount;

                // Flesch Reading Ease
                const fleschScore = Math.max(0, Math.min(100, 
                    206.835 - 1.015 * avgWordsPerSentence - 84.6 * (syllables / wordCount)
                ));

                // Flesch-Kincaid Grade Level
                const fkGrade = Math.max(0, 
                    0.39 * avgWordsPerSentence + 11.8 * (syllables / wordCount) - 15.59
                );

                // Gunning Fog Index
                const fogIndex = 0.4 * (avgWordsPerSentence + 100 * (complexWords / wordCount));

                // SMOG Index
                const smogIndex = 1.043 * Math.sqrt(complexWords * (30 / sentenceCount)) + 3.1291;

                // Reading time (assuming 200 WPM)
                const readingTime = Math.ceil(wordCount / 200);

                // Overall score (normalized to 0-100)
                const overallScore = Math.round((fleschScore + (100 - fkGrade * 10) + (100 - fogIndex * 10) + (100 - smogIndex * 10)) / 4);

                return {
                    fleschScore: Math.round(fleschScore),
                    fkGrade: Math.round(fkGrade * 10) / 10,
                    fogIndex: Math.round(fogIndex * 10) / 10,
                    smogIndex: Math.round(smogIndex * 10) / 10,
                    overallScore,
                    sentenceCount,
                    wordCount,
                    avgWordsPerSentence: Math.round(avgWordsPerSentence * 10) / 10,
                    complexWords,
                    readingTime
                };
            }

            getSentences(text) {
                return text.split(/[.!?]+/).filter(s => s.trim().length > 0);
            }

            getWords(text) {
                return text.toLowerCase().match(/\b\w+\b/g) || [];
            }

            countSyllables(word) {
                word = word.toLowerCase();
                if (word.length <= 3) return 1;
                
                const vowels = /[aeiouy]/g;
                const matches = word.match(vowels);
                if (!matches) return 1;
                
                let syllableCount = matches.length;
                
                // Handle special cases
                if (word.endsWith('e')) syllableCount--;
                if (word.endsWith('le') && word.length > 2 && word[word.length - 3] !== 'e') syllableCount++;
                
                return Math.max(1, syllableCount);
            }

            displayResults(analysis) {
                // Animate score circle
                const scoreCircle = document.getElementById('scoreCircle');
                const scorePercentage = analysis.overallScore / 100;
                const offset = 351.86 - (351.86 * scorePercentage);
                scoreCircle.style.strokeDashoffset = offset;
                scoreCircle.style.stroke = analysis.overallScore >= 70 ? '#10b981' : 
                                          analysis.overallScore >= 50 ? '#f59e0b' : '#ef4444';

                // Update display
                document.getElementById('overallScore').textContent = analysis.overallScore;
                document.getElementById('scoreText').textContent = this.getScoreText(analysis.overallScore);
                document.getElementById('readingLevel').textContent = this.getReadingLevel(analysis.fkGrade);
                document.getElementById('gradeLevel').textContent = `Grade ${analysis.fkGrade}`;
                document.getElementById('readingTime').innerHTML = `<i class="fas fa-clock mr-2"></i>~${analysis.readingTime} min read`;

                // Update metrics
                document.getElementById('fleschScore').textContent = analysis.fleschScore;
                document.getElementById('gunningFog').textContent = analysis.fogIndex;
                document.getElementById('smogIndex').textContent = analysis.smogIndex;
                document.getElementById('sentenceCount').textContent = analysis.sentenceCount;
                document.getElementById('avgWordsPerSentence').textContent = analysis.avgWordsPerSentence;
                document.getElementById('complexWords').textContent = analysis.complexWords;

                // Generate recommendations
                this.generateRecommendations(analysis);
            }

            getScoreText(score) {
                if (score >= 90) return 'Very Easy to Read';
                if (score >= 80) return 'Easy to Read';
                if (score >= 70) return 'Fairly Easy to Read';
                if (score >= 60) return 'Standard';
                if (score >= 50) return 'Fairly Difficult';
                if (score >= 30) return 'Difficult';
                return 'Very Difficult';
            }

            getReadingLevel(grade) {
                if (grade <= 5) return 'Elementary';
                if (grade <= 8) return 'Middle School';
                if (grade <= 12) return 'High School';
                if (grade <= 16) return 'College';
                return 'Graduate';
            }

            generateRecommendations(analysis) {
                const recommendations = [];
                
                if (analysis.avgWordsPerSentence > 20) {
                    recommendations.push('Consider breaking long sentences into shorter ones for better readability.');
                }
                
                if (analysis.complexWords > analysis.wordCount * 0.15) {
                    recommendations.push('Try replacing some complex words (3+ syllables) with simpler alternatives.');
                }
                
                if (analysis.fleschScore < 50) {
                    recommendations.push('Use shorter words and sentences to improve readability.');
                }
                
                if (analysis.fogIndex > 12) {
                    recommendations.push('Your text may be too complex for general audiences. Simplify where possible.');
                }
                
                if (analysis.sentenceCount < 5) {
                    recommendations.push('Consider adding more sentences to provide better context.');
                }
                
                if (recommendations.length === 0) {
                    recommendations.push('Great job! Your text has excellent readability.');
                }

                const recommendationsList = document.getElementById('recommendations');
                recommendationsList.innerHTML = recommendations.map(rec => 
                    `<li class="text-white/80 flex items-start">
                        <i class="fas fa-check-circle text-green-400 mr-3 mt-1 flex-shrink-0"></i>
                        ${rec}
                    </li>`
                ).join('');
            }
        }

        // Initialize the analyzer
        const analyzer = new ReadabilityAnalyzer();
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=dominiklukes/readability-analyzer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>