File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Gibberish Detector</ title >
7+ < script src ="https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js "> </ script >
8+ </ head >
9+ < body >
10+ < h1 > Gibberish Detector</ h1 >
11+ < label for ="userInput "> </ label > < textarea id ="userInput " rows ="4 " cols ="50 " placeholder ="Enter text... "> </ textarea >
12+ < button onclick ="runPython() "> Check</ button >
13+ < p > Score: < span id ="result "> -</ span > </ p >
14+ < script src ="script.js "> </ script >
15+ </ body >
16+ </ html >
Original file line number Diff line number Diff line change 1+ async function runPython ( ) {
2+ let pyodide = await loadPyodide ( ) ;
3+ await pyodide . loadPackage ( [ "micropip" ] ) ;
4+
5+ let response = await fetch ( "words_set.json" ) ;
6+ let wordsSet = new Set ( await response . json ( ) ) ;
7+
8+ let text = document . getElementById ( "userInput" ) . value ;
9+
10+ let pythonScript = `
11+ import re
12+
13+ def words_check(text, words_set):
14+ text = text.lower()
15+ split_text = [re.sub(r"[^\\w'-]", "", word) for word in text.split()]
16+ split_text = [word for word in split_text if word]
17+ if not split_text:
18+ return 0.0
19+ existing_words = sum(1 for word in split_text if word in words_set)
20+ return existing_words / len(split_text)
21+
22+ words_set = ${ JSON . stringify ( [ ...wordsSet ] ) }
23+ result = words_check('${ text } ', words_set)
24+ result
25+ ` ;
26+
27+ let result = await pyodide . runPythonAsync ( pythonScript ) ;
28+ document . getElementById ( "result" ) . innerText = result . toFixed ( 2 ) ;
29+ }
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments