Add 4 files
Browse files- app.js +33 -0
- index.html +1 -19
- main.js +17 -0
- safeteans-llm.js +27 -0
app.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import SafeteansLLM from './safeteans-llm';
|
| 2 |
+
|
| 3 |
+
class App {
|
| 4 |
+
constructor({ el, data, methods, created }) {
|
| 5 |
+
// Create the LLM instance
|
| 6 |
+
this.llm = new SafeteansLLM();
|
| 7 |
+
|
| 8 |
+
// Mount the root component
|
| 9 |
+
this.render([{
|
| 10 |
+
el: el,
|
| 11 |
+
data: data,
|
| 12 |
+
methods: methods,
|
| 13 |
+
created: created,
|
| 14 |
+
}]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
render({ el, data, methods, created }) {
|
| 18 |
+
// Create the element
|
| 19 |
+
const element = createElement(el);
|
| 20 |
+
|
| 21 |
+
// Set the data and methods
|
| 22 |
+
Object.keys(data).forEach(key => element.dataset[key] = data[key]);
|
| 23 |
+
Object.keys(methods).forEach(key => element[key] = methods[key]);
|
| 24 |
+
|
| 25 |
+
// Set the created callback
|
| 26 |
+
if (created) created(element);
|
| 27 |
+
|
| 28 |
+
// Append the element to the body
|
| 29 |
+
document.body.appendChild(element);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export default App;
|
index.html
CHANGED
|
@@ -1,19 +1 @@
|
|
| 1 |
-
<
|
| 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 |
+
<html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Safeteans Chat Interface</title></head><body style="height: 100vh; display: flex; flex-direction: column;"><div style="flex: 1; display: flex; flex-direction: column; align-items: center;"><h1 style="margin-top: -40em; margin-bottom: 0em; color: yellow;">Safeteans Chat Interface</h1><div style="margin-top: 2em; overflow: auto; height: 100%;"><div id="app" class="p-8"><div class="max-w-lg mx-auto prose"><h3 class="text-xl">Please enter your message:</h3><textarea class="w-full" rows="4" cols="50" id="message" placeholder="Type your message here..."></textarea></div></div></div></div></body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import 'https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js';
|
| 2 |
+
import * as from './app.js';
|
| 3 |
+
|
| 4 |
+
const app = new App({
|
| 5 |
+
el: '#app',
|
| 6 |
+
data: {
|
| 7 |
+
message: '',
|
| 8 |
+
},
|
| 9 |
+
methods: {
|
| 10 |
+
handleInput: function(event) {
|
| 11 |
+
this.message = event.target.value;
|
| 12 |
+
},
|
| 13 |
+
},
|
| 14 |
+
created: function() {
|
| 15 |
+
this.message = 'Initialize your message...';
|
| 16 |
+
},
|
| 17 |
+
});
|
safeteans-llm.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class SafeteansLLM {
|
| 2 |
+
constructor() {
|
| 3 |
+
// Create the WebSocket connection
|
| 4 |
+
this.socket = new WebSocket('wss://<server-url>');
|
| 5 |
+
|
| 6 |
+
// Listen for incoming messages
|
| 7 |
+
this.socket.onmessage = this.handleMessage;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
handleMessage(event) {
|
| 11 |
+
// Parse the incoming message
|
| 12 |
+
const message = JSON.parse(event.data);
|
| 13 |
+
|
| 14 |
+
// Print the message to the console
|
| 15 |
+
console.log(message);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
sendMessage(message) {
|
| 19 |
+
// Stringify the message
|
| 20 |
+
const data = JSON.stringify(message);
|
| 21 |
+
|
| 22 |
+
// Send the message over the WebSocket
|
| 23 |
+
this.socket.send(data);
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export default SafeteansLLM;
|