Spaces:
Running
Running
File size: 988 Bytes
a102191 8bdccc6 a102191 8bdccc6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import { Client } from "@gradio/client";
document.addEventListener("DOMContentLoaded", async () => {
const messagesDiv = document.getElementById("messages");
const chatForm = document.getElementById("chat-form");
const userInput = document.getElementById("user-input");
const client = await Client.connect("nroggendorff/not-my-emma");
chatForm.addEventListener("submit", async (e) => {
e.preventDefault();
const userMessage = userInput.value;
if (!userMessage) return;
addMessage(userMessage, "user");
const result = await client.predict("/chat", {
message: userMessage
});
addMessage(result.data, "ai");
userInput.value = "";
});
function addMessage(message, sender) {
const messageElement = document.createElement("div");
messageElement.classList.add("message", sender);
messageElement.textContent = message;
messagesDiv.appendChild(messageElement);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
}); |