Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -1,79 +1,41 @@
|
|
1 |
-
import { pipeline
|
2 |
|
3 |
-
//
|
4 |
-
env.allowLocalModels = false;
|
5 |
-
|
6 |
-
// Reference the elements that we will need
|
7 |
const status = document.getElementById('status');
|
8 |
-
const
|
9 |
-
const
|
10 |
-
const
|
11 |
-
|
12 |
-
const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
13 |
-
|
14 |
-
// Create a new object detection pipeline
|
15 |
-
status.textContent = 'Loading model...';
|
16 |
-
const detector = await pipeline('object-detection', 'Xenova/detr-resnet-50');
|
17 |
-
status.textContent = 'Ready';
|
18 |
-
|
19 |
-
example.addEventListener('click', (e) => {
|
20 |
-
e.preventDefault();
|
21 |
-
detect(EXAMPLE_URL);
|
22 |
-
});
|
23 |
-
|
24 |
-
fileUpload.addEventListener('change', function (e) {
|
25 |
-
const file = e.target.files[0];
|
26 |
-
if (!file) {
|
27 |
-
return;
|
28 |
-
}
|
29 |
-
|
30 |
-
const reader = new FileReader();
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
});
|
37 |
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
imageContainer.innerHTML = '';
|
42 |
-
imageContainer.style.backgroundImage = `url(${img})`;
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
threshold: 0.5,
|
47 |
-
percentage: true,
|
48 |
-
});
|
49 |
-
status.textContent = '';
|
50 |
-
output.forEach(renderBox);
|
51 |
}
|
52 |
|
53 |
-
//
|
54 |
-
function
|
55 |
-
const
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
// Draw the box
|
61 |
-
const boxElement = document.createElement('div');
|
62 |
-
boxElement.className = 'bounding-box';
|
63 |
-
Object.assign(boxElement.style, {
|
64 |
-
borderColor: color,
|
65 |
-
left: 100 * xmin + '%',
|
66 |
-
top: 100 * ymin + '%',
|
67 |
-
width: 100 * (xmax - xmin) + '%',
|
68 |
-
height: 100 * (ymax - ymin) + '%',
|
69 |
-
})
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
labelElement.textContent = label;
|
74 |
-
labelElement.className = 'bounding-box-label';
|
75 |
-
labelElement.style.backgroundColor = color;
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
1 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
2 |
|
3 |
+
// Status- und Input-Elemente
|
|
|
|
|
|
|
4 |
const status = document.getElementById('status');
|
5 |
+
const userInput = document.getElementById('user-input');
|
6 |
+
const sendButton = document.getElementById('send-button');
|
7 |
+
const chatBox = document.getElementById('chat-box');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
// Chatbot-Pipeline initialisieren
|
10 |
+
status.textContent = 'Lade Modell...';
|
11 |
+
const chatbot = await pipeline('text-generation', 'IhrModellName'); // Ersetzen Sie 'IhrModellName' mit dem Namen des Hugging Face Modells
|
12 |
+
status.textContent = 'Bereit';
|
|
|
13 |
|
14 |
+
// Nachrichtensendefunktion
|
15 |
+
async function sendMessage() {
|
16 |
+
const message = userInput.value;
|
17 |
+
if (!message) return;
|
18 |
|
19 |
+
displayMessage('Du: ' + message);
|
20 |
+
userInput.value = '';
|
|
|
|
|
21 |
|
22 |
+
const response = await chatbot(message);
|
23 |
+
displayMessage('Bot: ' + response[0].generated_text);
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
+
// Nachricht im Chat anzeigen
|
27 |
+
function displayMessage(message) {
|
28 |
+
const messageElement = document.createElement('div');
|
29 |
+
messageElement.textContent = message;
|
30 |
+
chatBox.appendChild(messageElement);
|
31 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
// Event-Listener für den Senden-Button
|
34 |
+
sendButton.addEventListener('click', sendMessage);
|
|
|
|
|
|
|
35 |
|
36 |
+
// Enter-Taste als Alternative zum Senden
|
37 |
+
userInput.addEventListener('keypress', function(e) {
|
38 |
+
if (e.key === 'Enter') {
|
39 |
+
sendMessage();
|
40 |
+
}
|
41 |
+
});
|