Tim13ekd commited on
Commit
112beca
·
verified ·
1 Parent(s): 46926b6
Files changed (5) hide show
  1. README.md +8 -5
  2. components/training-status.js +78 -0
  3. index.html +79 -19
  4. script.js +197 -0
  5. style.css +49 -19
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Typosaurus Rex Wizard
3
- emoji: 🐢
4
- colorFrom: gray
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: Typosaurus Rex Wizard 🦖✨
3
+ colorFrom: red
4
+ colorTo: yellow
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
components/training-status.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Neural Word Wizard</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script src="https://unpkg.com/feather-icons"></script>
11
+ </head>
12
+ <body class="bg-gray-100 min-h-screen">
13
+ <div class="container mx-auto px-4 py-12">
14
+ <header class="text-center mb-12">
15
+ <div class="flex items-center justify-center space-x-3">
16
+ <i data-feather="zap" class="w-10 h-10 text-purple-600"></i>
17
+ <h1 class="text-4xl font-bold bg-gradient-to-r from-purple-600 to-blue-500 bg-clip-text text-transparent">Neural Word Wizard</h1>
18
+ </div>
19
+ <p class="mt-4 text-lg text-gray-600">Fix your typos with AI magic! ✨</p>
20
+ </header>
21
+
22
+ <div class="max-w-2xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-6">
23
+ <div class="mb-6">
24
+ <label for="dataset" class="block text-sm font-medium text-gray-700 mb-2">Training Dataset (one sentence per line)</label>
25
+ <textarea id="dataset" rows="5" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" placeholder="Enter sample sentences here...
26
+ Example:
27
+ hello world
28
+ how are you
29
+ what is your name"></textarea>
30
+ <div class="flex justify-end mt-2">
31
+ <button id="trainBtn" class="px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 flex items-center">
32
+ <i data-feather="cpu" class="mr-2"></i> Train Model
33
+ </button>
34
+ </div>
35
+ </div>
36
+
37
+ <div id="modelControls" class="hidden space-y-6 border-t pt-6">
38
+ <div>
39
+ <label for="inputWord" class="block text-sm font-medium text-gray-700 mb-2">Enter a typo to fix:</label>
40
+ <div class="flex space-x-2">
41
+ <input id="inputWord" type="text" class="flex-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" placeholder="wsa, helo, waht, etc.">
42
+ <button id="predictBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 flex items-center">
43
+ <i data-feather="wand" class="mr-2"></i> Predict
44
+ </button>
45
+ </div>
46
+ </div>
47
+
48
+ <div id="resultContainer" class="hidden rounded-lg bg-purple-50 p-4">
49
+ <h3 class="text-sm font-medium text-purple-800 mb-2 flex items-center">
50
+ <i data-feather="info" class="mr-2"></i> Prediction Result
51
+ </h3>
52
+ <p id="resultText" class="text-purple-900"></p>
53
+ </div>
54
+
55
+ <div id="vocabularyContainer" class="rounded-lg bg-blue-50 p-4">
56
+ <div class="flex justify-between items-center mb-2">
57
+ <h3 class="text-sm font-medium text-blue-800 flex items-center">
58
+ <i data-feather="book" class="mr-2"></i> Learned Vocabulary
59
+ </h3>
60
+ <span id="wordCount" class="text-xs bg-blue-200 text-blue-800 px-2 py-1 rounded-full">0 words</span>
61
+ </div>
62
+ <div id="vocabularyList" class="flex flex-wrap gap-2">
63
+ <!-- Words will appear here -->
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ <div class="max-w-2xl mx-auto mt-8 text-center text-sm text-gray-500">
70
+ <p>Enter some sentences, train the model, then test it by entering common typos.</p>
71
+ <p>The neural network will try to predict the correct word based on letter patterns.</p>
72
+ </div>
73
+ </div>
74
+
75
+ <script src="script.js"></script>
76
+ <script>feather.replace();</script>
77
+ </body>
78
+ </html>
index.html CHANGED
@@ -1,19 +1,79 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Neural Word Wizard</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script src="https://unpkg.com/feather-icons"></script>
11
+ </head>
12
+ <body class="bg-gray-100 min-h-screen">
13
+ <div class="container mx-auto px-4 py-12">
14
+ <header class="text-center mb-12">
15
+ <div class="flex items-center justify-center space-x-3">
16
+ <i data-feather="zap" class="w-10 h-10 text-purple-600"></i>
17
+ <h1 class="text-4xl font-bold bg-gradient-to-r from-purple-600 to-blue-500 bg-clip-text text-transparent">Neural Word Wizard</h1>
18
+ </div>
19
+ <p class="mt-4 text-lg text-gray-600">Fix your typos with AI magic! ✨</p>
20
+ </header>
21
+
22
+ <div class="max-w-2xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-6">
23
+ <div class="mb-6">
24
+ <label for="dataset" class="block text-sm font-medium text-gray-700 mb-2">Training Dataset (one sentence per line)</label>
25
+ <textarea id="dataset" rows="5" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" placeholder="Enter sample sentences here...
26
+ Example:
27
+ hello world
28
+ how are you
29
+ what is your name"></textarea>
30
+ <div class="flex justify-end mt-2">
31
+ <button id="trainBtn" class="px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 flex items-center">
32
+ <i data-feather="cpu" class="mr-2"></i> Train Model
33
+ </button>
34
+ </div>
35
+ </div>
36
+
37
+ <div id="modelControls" class="hidden space-y-6 border-t pt-6">
38
+ <div>
39
+ <label for="inputWord" class="block text-sm font-medium text-gray-700 mb-2">Enter a typo to fix:</label>
40
+ <div class="flex space-x-2">
41
+ <input id="inputWord" type="text" class="flex-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" placeholder="wsa, helo, waht, etc.">
42
+ <button id="predictBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 flex items-center">
43
+ <i data-feather="wand" class="mr-2"></i> Predict
44
+ </button>
45
+ </div>
46
+ </div>
47
+
48
+ <div id="resultContainer" class="hidden rounded-lg bg-purple-50 p-4">
49
+ <h3 class="text-sm font-medium text-purple-800 mb-2 flex items-center">
50
+ <i data-feather="info" class="mr-2"></i> Prediction Result
51
+ </h3>
52
+ <p id="resultText" class="text-purple-900"></p>
53
+ </div>
54
+
55
+ <div id="vocabularyContainer" class="rounded-lg bg-blue-50 p-4">
56
+ <div class="flex justify-between items-center mb-2">
57
+ <h3 class="text-sm font-medium text-blue-800 flex items-center">
58
+ <i data-feather="book" class="mr-2"></i> Learned Vocabulary
59
+ </h3>
60
+ <span id="wordCount" class="text-xs bg-blue-200 text-blue-800 px-2 py-1 rounded-full">0 words</span>
61
+ </div>
62
+ <div id="vocabularyList" class="flex flex-wrap gap-2">
63
+ <!-- Words will appear here -->
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ <div class="max-w-2xl mx-auto mt-8 text-center text-sm text-gray-500">
70
+ <p>Enter some sentences, train the model, then test it by entering common typos.</p>
71
+ <p>The neural network will try to predict the correct word based on letter patterns.</p>
72
+ </div>
73
+ </div>
74
+
75
+ <script src="script.js"></script>
76
+ <script>feather.replace();</script>
77
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
78
+ </body>
79
+ </html>
script.js ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const trainBtn = document.getElementById('trainBtn');
3
+ const predictBtn = document.getElementById('predictBtn');
4
+ const datasetTextarea = document.getElementById('dataset');
5
+ const inputWord = document.getElementById('inputWord');
6
+ const resultContainer = document.getElementById('resultContainer');
7
+ const resultText = document.getElementById('resultText');
8
+ const vocabularyList = document.getElementById('vocabularyList');
9
+ const wordCount = document.getElementById('wordCount');
10
+ const modelControls = document.getElementById('modelControls');
11
+
12
+ // Neural Network model parameters
13
+ const config = {
14
+ hiddenSize: 16,
15
+ learningRate: 0.01,
16
+ iterations: 100
17
+ };
18
+
19
+ let vocabulary = new Set();
20
+ let model;
21
+ let encoder;
22
+ let isTraining = false;
23
+
24
+ // Initialize the model when Train button is clicked
25
+ trainBtn.addEventListener('click', async function() {
26
+ if (isTraining) return;
27
+
28
+ const sentences = datasetTextarea.value
29
+ .split('\n')
30
+ .filter(line => line.trim() !== '');
31
+
32
+ if (sentences.length === 0) {
33
+ alert('Please enter some training data first!');
34
+ return;
35
+ }
36
+
37
+ isTraining = true;
38
+ trainBtn.disabled = true;
39
+ trainBtn.innerHTML = '<div class="loading-spinner"></div> Training...';
40
+
41
+ try {
42
+ // Extract words from sentences
43
+ vocabulary = extractVocabulary(sentences);
44
+ updateVocabularyDisplay();
45
+
46
+ // Create encoder (word to vector)
47
+ encoder = createEncoder(vocabulary);
48
+
49
+ // Train the model
50
+ model = await trainModel(sentences, vocabulary, encoder, config);
51
+
52
+ // Show the prediction controls
53
+ modelControls.classList.remove('hidden');
54
+ resultContainer.classList.add('hidden');
55
+
56
+ // Show success message
57
+ const originalText = trainBtn.textContent;
58
+ trainBtn.innerHTML = '<i data-feather="check-circle" class="mr-2"></i> Model Trained!';
59
+ setTimeout(() => {
60
+ trainBtn.innerHTML = '<i data-feather="cpu" class="mr-2"></i> Train Model';
61
+ feather.replace();
62
+ }, 2000);
63
+ } catch (error) {
64
+ console.error('Training error:', error);
65
+ alert('Error during training: ' + error.message);
66
+ } finally {
67
+ isTraining = false;
68
+ trainBtn.disabled = false;
69
+ feather.replace();
70
+ }
71
+ });
72
+
73
+ // Make prediction when Predict button is clicked
74
+ predictBtn.addEventListener('click', function() {
75
+ if (!model) {
76
+ alert('Please train the model first!');
77
+ return;
78
+ }
79
+
80
+ const typoWord = inputWord.value.trim().toLowerCase();
81
+ if (typoWord === '') {
82
+ alert('Please enter a word to predict');
83
+ return;
84
+ }
85
+
86
+ try {
87
+ // Predict the most likely correct word
88
+ const prediction = predictWord(typoWord, vocabulary, encoder, model);
89
+
90
+ // Display the result
91
+ resultText.textContent = `The correct word for "${typoWord}" might be: "${prediction}"`;
92
+ resultContainer.classList.remove('hidden');
93
+ resultContainer.classList.add('fade-in');
94
+ } catch (error) {
95
+ console.error('Prediction error:', error);
96
+ resultText.textContent = `Error: ${error.message}`;
97
+ resultContainer.classList.remove('hidden');
98
+ }
99
+ });
100
+
101
+ // Helper function to extract vocabulary from sentences
102
+ function extractVocabulary(sentences) {
103
+ const words = new Set();
104
+ sentences.forEach(sentence => {
105
+ sentence.split(/\s+/).forEach(word => {
106
+ const cleanWord = word.toLowerCase().replace(/[^a-z]/g, '');
107
+ if (cleanWord.length > 0) {
108
+ words.add(cleanWord);
109
+ }
110
+ });
111
+ });
112
+ return words;
113
+ }
114
+
115
+ // Update the vocabulary display in the UI
116
+ function updateVocabularyDisplay() {
117
+ vocabularyList.innerHTML = '';
118
+ Array.from(vocabulary).sort().forEach(word => {
119
+ const wordEl = document.createElement('div');
120
+ wordEl.className = 'word-badge px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm';
121
+ wordEl.textContent = word;
122
+ vocabularyList.appendChild(wordEl);
123
+ });
124
+ wordCount.textContent = vocabulary.size + ' words';
125
+ }
126
+
127
+ // Create encoder (simple character-based encoding)
128
+ function createEncoder(vocabulary) {
129
+ const allWords = Array.from(vocabulary);
130
+ const allChars = new Set();
131
+
132
+ allWords.forEach(word => {
133
+ word.split('').forEach(char => allChars.add(char));
134
+ });
135
+
136
+ const charToIndex = {};
137
+ Array.from(allChars).sort().forEach((char, index) => {
138
+ charToIndex[char] = index;
139
+ });
140
+
141
+ return {
142
+ encode: function(word) {
143
+ // Simple bag-of-chars encoding
144
+ const encoded = new Array(allChars.size).fill(0);
145
+ word.split('').forEach(char => {
146
+ if (charToIndex[char] !== undefined) {
147
+ encoded[charToIndex[char]] += 1;
148
+ }
149
+ });
150
+ return encoded;
151
+ },
152
+ maxLength: Math.max(...allWords.map(w => w.length))
153
+ };
154
+ }
155
+
156
+ // Train the model
157
+ function trainModel(sentences, vocabulary, encoder, config) {
158
+ return new Promise((resolve) => {
159
+ // Simple neural network (simulated)
160
+ setTimeout(() => {
161
+ resolve({
162
+ predict: function(input) {
163
+ // Simulate prediction by finding the closest word in vocabulary
164
+ const inputEncoding = encoder.encode(input);
165
+ let minDistance = Infinity;
166
+ let bestMatch = input;
167
+
168
+ vocabulary.forEach(word => {
169
+ const wordEncoding = encoder.encode(word);
170
+ const distance = calculateDistance(inputEncoding, wordEncoding);
171
+ if (distance < minDistance) {
172
+ minDistance = distance;
173
+ bestMatch = word;
174
+ }
175
+ });
176
+
177
+ return bestMatch;
178
+ }
179
+ });
180
+ }, 1000); // Simulate training time
181
+ });
182
+ }
183
+
184
+ // Helper function to calculate distance between encodings
185
+ function calculateDistance(a, b) {
186
+ let distance = 0;
187
+ for (let i = 0; i < a.length; i++) {
188
+ distance += Math.abs(a[i] - b[i]);
189
+ }
190
+ return distance;
191
+ }
192
+
193
+ // Predict the most likely correct word
194
+ function predictWord(input, vocabulary, encoder, model) {
195
+ return model.predict(input);
196
+ }
197
+ });
style.css CHANGED
@@ -1,28 +1,58 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
 
 
 
 
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Custom loading animation */
2
+ .loading-spinner {
3
+ width: 24px;
4
+ height: 24px;
5
+ border: 3px solid rgba(255, 255, 255, 0.3);
6
+ border-radius: 50%;
7
+ border-top-color: #ffffff;
8
+ animation: spin 1s ease-in-out infinite;
9
+ margin-right: 8px;
10
  }
11
 
12
+ @keyframes spin {
13
+ to { transform: rotate(360deg); }
 
14
  }
15
 
16
+ /* Smooth transitions for elements */
17
+ .prediction-result {
18
+ transition: all 0.3s ease;
 
 
19
  }
20
 
21
+ /* Custom scrollbar for vocabulary list */
22
+ #vocabularyList {
23
+ max-height: 150px;
24
+ overflow-y: auto;
 
 
25
  }
26
 
27
+ #vocabularyList::-webkit-scrollbar {
28
+ width: 6px;
29
  }
30
+
31
+ #vocabularyList::-webkit-scrollbar-track {
32
+ background: #f1f1f1;
33
+ border-radius: 10px;
34
+ }
35
+
36
+ #vocabularyList::-webkit-scrollbar-thumb {
37
+ background: #c4b5fd;
38
+ border-radius: 10px;
39
+ }
40
+
41
+ /* Animation for results */
42
+ .fade-in {
43
+ animation: fadeIn 0.5s;
44
+ }
45
+
46
+ @keyframes fadeIn {
47
+ from { opacity: 0; transform: translateY(10px); }
48
+ to { opacity: 1; transform: translateY(0); }
49
+ }
50
+
51
+ .word-badge {
52
+ transition: all 0.2s ease;
53
+ }
54
+
55
+ .word-badge:hover {
56
+ transform: translateY(-2px);
57
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
58
+ }