Spaces:
Runtime error
Runtime error
Download static/app.js from Daniel1812/Asistente-3D: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/Daniel1812/Asistente-3D/resolve/main/static/app.js
- Command line
-
hf download hf://spaces/Daniel1812/Asistente-3D/static/app.js
-
curl -L -o app.js https://huggingface.co/spaces/Daniel1812/Asistente-3D/resolve/main/static/app.js
1.3 kB
| // ====== UI helpers ====== | |
| const chatEl = document.getElementById("chat"); | |
| const form = document.getElementById("chatForm"); | |
| const input = document.getElementById("msgInput"); | |
| function addMsg(text, who = "bot") { | |
| const div = document.createElement("div"); | |
| div.className = `msg ${who}`; | |
| div.textContent = text; | |
| chatEl.appendChild(div); | |
| chatEl.scrollTop = chatEl.scrollHeight; | |
| } | |
| // ====== Llamada al backend ====== | |
| async function askBackend(message) { | |
| const resp = await fetch("/api/chat", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ message }) | |
| }); | |
| if (!resp.ok) throw new Error("Error en el servidor"); | |
| const data = await resp.json(); | |
| return data.reply || "No tengo respuesta ahora."; | |
| } | |
| // ====== Manejo del formulario ====== | |
| form.addEventListener("submit", async (e) => { | |
| e.preventDefault(); | |
| const text = input.value.trim(); | |
| if (!text) return; | |
| addMsg(text, "user"); | |
| input.value = ""; | |
| addMsg("Pensando..."); | |
| try { | |
| const reply = await askBackend(text); | |
| // quita "Pensando..." | |
| chatEl.lastElementChild.remove(); | |
| addMsg(reply, "bot"); | |
| } catch (err) { | |
| chatEl.lastElementChild.remove(); | |
| addMsg("Hubo un problema al responder. Intenta de nuevo.", "bot"); | |
| console.error(err); | |
| } | |
| }); | |