Spaces:
Running
Running
Utkarsh Verma
commited on
Commit
·
732ddfe
1
Parent(s):
ad15d33
Changes in UI
Browse files- templates/index.html +120 -2
templates/index.html
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
@@ -29,4 +29,122 @@
|
|
29 |
<input type="text" id="user-input" placeholder="Type a message...">
|
30 |
<button onclick="sendMessage()">Send</button>
|
31 |
</body>
|
32 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- <!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
|
|
29 |
<input type="text" id="user-input" placeholder="Type a message...">
|
30 |
<button onclick="sendMessage()">Send</button>
|
31 |
</body>
|
32 |
+
</html> -->
|
33 |
+
|
34 |
+
<!DOCTYPE html>
|
35 |
+
<html lang="en">
|
36 |
+
<head>
|
37 |
+
<meta charset="UTF-8" />
|
38 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
39 |
+
<title>AI Chatbot</title>
|
40 |
+
<style>
|
41 |
+
body {
|
42 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
43 |
+
background: #f4f7f9;
|
44 |
+
display: flex;
|
45 |
+
flex-direction: column;
|
46 |
+
align-items: center;
|
47 |
+
justify-content: start;
|
48 |
+
padding: 30px;
|
49 |
+
min-height: 100vh;
|
50 |
+
}
|
51 |
+
|
52 |
+
h1 {
|
53 |
+
color: #333;
|
54 |
+
margin-bottom: 20px;
|
55 |
+
}
|
56 |
+
|
57 |
+
#chat-box {
|
58 |
+
width: 90%;
|
59 |
+
max-width: 600px;
|
60 |
+
height: 400px;
|
61 |
+
border: 1px solid #ddd;
|
62 |
+
background: #fff;
|
63 |
+
border-radius: 10px;
|
64 |
+
padding: 15px;
|
65 |
+
overflow-y: auto;
|
66 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
67 |
+
margin-bottom: 20px;
|
68 |
+
}
|
69 |
+
|
70 |
+
#chat-box p {
|
71 |
+
margin: 10px 0;
|
72 |
+
line-height: 1.4;
|
73 |
+
}
|
74 |
+
|
75 |
+
#chat-box b {
|
76 |
+
color: #0057b7;
|
77 |
+
}
|
78 |
+
|
79 |
+
.chat-input {
|
80 |
+
display: flex;
|
81 |
+
width: 90%;
|
82 |
+
max-width: 600px;
|
83 |
+
}
|
84 |
+
|
85 |
+
#user-input {
|
86 |
+
flex: 1;
|
87 |
+
padding: 12px;
|
88 |
+
border: 1px solid #ccc;
|
89 |
+
border-radius: 10px 0 0 10px;
|
90 |
+
font-size: 16px;
|
91 |
+
}
|
92 |
+
|
93 |
+
button {
|
94 |
+
padding: 12px 20px;
|
95 |
+
background: #0057b7;
|
96 |
+
color: #fff;
|
97 |
+
border: none;
|
98 |
+
border-radius: 0 10px 10px 0;
|
99 |
+
cursor: pointer;
|
100 |
+
font-size: 16px;
|
101 |
+
transition: background 0.3s ease;
|
102 |
+
}
|
103 |
+
|
104 |
+
button:hover {
|
105 |
+
background: #003f91;
|
106 |
+
}
|
107 |
+
</style>
|
108 |
+
<script>
|
109 |
+
async function sendMessage() {
|
110 |
+
let userInput = document.getElementById("user-input").value;
|
111 |
+
let chatBox = document.getElementById("chat-box");
|
112 |
+
|
113 |
+
if (!userInput.trim()) return;
|
114 |
+
|
115 |
+
chatBox.innerHTML += `<p><b>You:</b> ${userInput}</p>`;
|
116 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
117 |
+
|
118 |
+
let response = await fetch("/chat", {
|
119 |
+
method: "POST",
|
120 |
+
headers: { "Content-Type": "application/json" },
|
121 |
+
body: JSON.stringify({ message: userInput }),
|
122 |
+
});
|
123 |
+
|
124 |
+
let data = await response.json();
|
125 |
+
chatBox.innerHTML += `<p><b>Bot:</b> ${data.reply || "Error in response"}</p>`;
|
126 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
127 |
+
|
128 |
+
document.getElementById("user-input").value = "";
|
129 |
+
}
|
130 |
+
|
131 |
+
// Allow pressing Enter to send message
|
132 |
+
document.addEventListener("DOMContentLoaded", () => {
|
133 |
+
document.getElementById("user-input").addEventListener("keydown", (e) => {
|
134 |
+
if (e.key === "Enter") {
|
135 |
+
e.preventDefault();
|
136 |
+
sendMessage();
|
137 |
+
}
|
138 |
+
});
|
139 |
+
});
|
140 |
+
</script>
|
141 |
+
</head>
|
142 |
+
<body>
|
143 |
+
<h1>AI Chatbot</h1>
|
144 |
+
<div id="chat-box"></div>
|
145 |
+
<div class="chat-input">
|
146 |
+
<input type="text" id="user-input" placeholder="Type a message..." />
|
147 |
+
<button onclick="sendMessage()">Send</button>
|
148 |
+
</div>
|
149 |
+
</body>
|
150 |
+
</html>
|