Spaces:
Running
Running
mache das dataset ist als datei im workspace
Browse files- components/file-upload.js +98 -0
- index.html +6 -5
- style.css +7 -2
components/file-upload.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class FileUpload extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
.file-upload-container {
|
| 7 |
+
display: flex;
|
| 8 |
+
flex-direction: column;
|
| 9 |
+
gap: 0.5rem;
|
| 10 |
+
margin-bottom: 1rem;
|
| 11 |
+
}
|
| 12 |
+
.drop-area {
|
| 13 |
+
border: 2px dashed #d1d5db;
|
| 14 |
+
border-radius: 0.5rem;
|
| 15 |
+
padding: 1rem;
|
| 16 |
+
text-align: center;
|
| 17 |
+
cursor: pointer;
|
| 18 |
+
transition: all 0.2s;
|
| 19 |
+
}
|
| 20 |
+
.drop-area:hover, .drop-area.highlight {
|
| 21 |
+
border-color: #7c3aed;
|
| 22 |
+
background-color: #f5f3ff;
|
| 23 |
+
}
|
| 24 |
+
.file-input {
|
| 25 |
+
display: none;
|
| 26 |
+
}
|
| 27 |
+
.file-info {
|
| 28 |
+
font-size: 0.875rem;
|
| 29 |
+
color: #6b7280;
|
| 30 |
+
margin-top: 0.5rem;
|
| 31 |
+
}
|
| 32 |
+
</style>
|
| 33 |
+
<div class="file-upload-container">
|
| 34 |
+
<label for="file-upload" class="drop-area" id="drop-area">
|
| 35 |
+
<p>Click to select or drag & drop a text file</p>
|
| 36 |
+
<input type="file" id="file-upload" class="file-input" accept=".txt">
|
| 37 |
+
</label>
|
| 38 |
+
<div class="file-info" id="file-info">No file selected</div>
|
| 39 |
+
</div>
|
| 40 |
+
`;
|
| 41 |
+
|
| 42 |
+
const dropArea = this.shadowRoot.getElementById('drop-area');
|
| 43 |
+
const fileInput = this.shadowRoot.getElementById('file-upload');
|
| 44 |
+
const fileInfo = this.shadowRoot.getElementById('file-info');
|
| 45 |
+
|
| 46 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
| 47 |
+
dropArea.addEventListener(eventName, preventDefaults, false);
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
| 51 |
+
dropArea.addEventListener(eventName, highlight, false);
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
['dragleave', 'drop'].forEach(eventName => {
|
| 55 |
+
dropArea.addEventListener(eventName, unhighlight, false);
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
dropArea.addEventListener('drop', handleDrop, false);
|
| 59 |
+
fileInput.addEventListener('change', handleFiles, false);
|
| 60 |
+
|
| 61 |
+
function preventDefaults(e) {
|
| 62 |
+
e.preventDefault();
|
| 63 |
+
e.stopPropagation();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function highlight() {
|
| 67 |
+
dropArea.classList.add('highlight');
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function unhighlight() {
|
| 71 |
+
dropArea.classList.remove('highlight');
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function handleDrop(e) {
|
| 75 |
+
const dt = e.dataTransfer;
|
| 76 |
+
const files = dt.files;
|
| 77 |
+
fileInput.files = files;
|
| 78 |
+
handleFiles({ target: fileInput });
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function handleFiles(e) {
|
| 82 |
+
const file = e.target.files[0];
|
| 83 |
+
if (file) {
|
| 84 |
+
fileInfo.textContent = `Selected: ${file.name} (${(file.size / 1024).toFixed(1)} KB)`;
|
| 85 |
+
const reader = new FileReader();
|
| 86 |
+
reader.onload = function(e) {
|
| 87 |
+
const textarea = document.getElementById('dataset');
|
| 88 |
+
textarea.value = e.target.result;
|
| 89 |
+
};
|
| 90 |
+
reader.readAsText(file);
|
| 91 |
+
} else {
|
| 92 |
+
fileInfo.textContent = 'No file selected';
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
customElements.define('file-upload', FileUpload);
|
index.html
CHANGED
|
@@ -21,8 +21,9 @@
|
|
| 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 |
-
<
|
| 25 |
-
<
|
|
|
|
| 26 |
Example:
|
| 27 |
hello world
|
| 28 |
how are you
|
|
@@ -71,9 +72,9 @@ what is your name"></textarea>
|
|
| 71 |
<p>The neural network will try to predict the correct word based on letter patterns.</p>
|
| 72 |
</div>
|
| 73 |
</div>
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 78 |
</body>
|
| 79 |
</html>
|
|
|
|
| 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 |
+
<file-upload></file-upload>
|
| 25 |
+
<label for="dataset" class="block text-sm font-medium text-gray-700 mb-2">Or enter manually (one sentence per line):</label>
|
| 26 |
+
<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...
|
| 27 |
Example:
|
| 28 |
hello world
|
| 29 |
how are you
|
|
|
|
| 72 |
<p>The neural network will try to predict the correct word based on letter patterns.</p>
|
| 73 |
</div>
|
| 74 |
</div>
|
| 75 |
+
<script src="components/file-upload.js"></script>
|
| 76 |
+
<script src="script.js"></script>
|
| 77 |
+
<script>feather.replace();</script>
|
| 78 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 79 |
</body>
|
| 80 |
</html>
|
style.css
CHANGED
|
@@ -51,8 +51,13 @@
|
|
| 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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
.word-badge {
|
| 52 |
transition: all 0.2s ease;
|
| 53 |
}
|
|
|
|
| 54 |
.word-badge:hover {
|
| 55 |
transform: translateY(-2px);
|
| 56 |
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* File upload component styles */
|
| 60 |
+
file-upload {
|
| 61 |
+
display: block;
|
| 62 |
+
margin-bottom: 1rem;
|
| 63 |
+
}
|