Spaces:
Runtime error
Runtime error
Download frontend/script.js from Subhakanta156/Odisha-Disaster-Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/Subhakanta156/Odisha-Disaster-Chatbot/resolve/main/frontend/script.js
- Command line
-
hf download hf://spaces/Subhakanta156/Odisha-Disaster-Chatbot/frontend/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Subhakanta156/Odisha-Disaster-Chatbot/resolve/main/frontend/script.js
1.09 kB
| async function askBot() { | |
| let query = document.getElementById("query").value; | |
| if (!query.trim()) return; | |
| // Show user message | |
| addMessage(query, "user"); | |
| // Clear input field | |
| document.getElementById("query").value = ""; | |
| try { | |
| let res = await fetch("http://127.0.0.1:8000/chat", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ query: query }) | |
| }); | |
| let data = await res.json(); | |
| // Show bot response | |
| addMessage(data.answer, "bot"); | |
| } catch (error) { | |
| addMessage("⚠️ Unable to reach server. Please try again later.", "bot"); | |
| } | |
| } | |
| function addMessage(text, sender) { | |
| let chatbox = document.getElementById("chatbox"); | |
| let msg = document.createElement("div"); | |
| msg.classList.add("message", sender); | |
| // msg.textContent = text; | |
| msg.innerHTML = marked.parse(text); | |
| chatbox.appendChild(msg); | |
| // Auto-scroll to the bottom | |
| chatbox.scrollTop = chatbox.scrollHeight; | |
| } | |