Skip to content

Commit 4b148b4

Browse files
committed
Add page
1 parent cfae2fc commit 4b148b4

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

docs/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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>

docs/script.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

docs/words_set.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)