Upload 5 files
Browse files
app.py
CHANGED
|
@@ -79,5 +79,5 @@ def chatbot():
|
|
| 79 |
except Exception as e:
|
| 80 |
return jsonify({"error": str(e)}), 500
|
| 81 |
|
| 82 |
-
if
|
| 83 |
app.run(host='0.0.0.0', port=8000)
|
|
|
|
| 79 |
except Exception as e:
|
| 80 |
return jsonify({"error": str(e)}), 500
|
| 81 |
|
| 82 |
+
if __name__ == '__main__':
|
| 83 |
app.run(host='0.0.0.0', port=8000)
|
script.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
| 1 |
-
document.addEventListener(
|
| 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 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
}
|
| 43 |
}
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
});
|
|
|
|
| 1 |
+
document.addEventListener("DOMContentLoaded", (event) => {
|
| 2 |
+
const chatMessages = document.getElementById("chat-messages");
|
| 3 |
+
const userInput = document.getElementById("user-input");
|
| 4 |
+
const sendButton = document.getElementById("send-button");
|
| 5 |
|
| 6 |
+
function addMessage(message, isUser = false) {
|
| 7 |
+
const messageElement = document.createElement("p");
|
| 8 |
+
messageElement.textContent = message;
|
| 9 |
+
messageElement.style.backgroundColor = isUser ? "#e6f2ff" : "#f0f0f0";
|
| 10 |
+
messageElement.style.padding = "10px";
|
| 11 |
+
messageElement.style.borderRadius = "5px";
|
| 12 |
+
messageElement.style.marginBottom = "10px";
|
| 13 |
+
chatMessages.appendChild(messageElement);
|
| 14 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 15 |
+
}
|
| 16 |
|
| 17 |
+
function sendMessage() {
|
| 18 |
+
const message = userInput.value.trim();
|
| 19 |
+
if (message) {
|
| 20 |
+
addMessage(`You: ${message}`, true);
|
| 21 |
+
userInput.value = "";
|
| 22 |
|
| 23 |
+
fetch("/chatbot", {
|
| 24 |
+
method: "POST",
|
| 25 |
+
headers: {
|
| 26 |
+
"Content-Type": "application/json",
|
| 27 |
+
},
|
| 28 |
+
body: JSON.stringify({ text: message }),
|
| 29 |
+
})
|
| 30 |
+
.then((response) => response.json())
|
| 31 |
+
.then((data) => {
|
| 32 |
+
if (data.error) {
|
| 33 |
+
addMessage(`Error: ${data.error}`);
|
| 34 |
+
} else {
|
| 35 |
+
addMessage(`Chatbot: ${data.response}`);
|
| 36 |
+
}
|
| 37 |
+
})
|
| 38 |
+
.catch((error) => {
|
| 39 |
+
console.error("Error:", error);
|
| 40 |
+
addMessage("Error: Unable to get response from the server.");
|
| 41 |
+
});
|
|
|
|
| 42 |
}
|
| 43 |
+
}
|
| 44 |
|
| 45 |
+
sendButton.addEventListener("click", sendMessage);
|
| 46 |
+
userInput.addEventListener("keypress", function (e) {
|
| 47 |
+
if (e.key === "Enter") {
|
| 48 |
+
sendMessage();
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
+
});
|