Jasleen05 commited on
Commit
c48360b
·
verified ·
1 Parent(s): 662f50d

Add static folder

Browse files
Files changed (2) hide show
  1. static/script.js +51 -0
  2. static/styles.css +173 -0
static/script.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ window.addEventListener("DOMContentLoaded", () => {
2
+ const form = document.getElementById("chat-form");
3
+ const input = document.getElementById("user-input");
4
+ const chatBox = document.getElementById("chat-box");
5
+
6
+ // ✅ Load chat history from backend
7
+ async function loadHistory() {
8
+ try {
9
+ const res = await fetch("/history");
10
+ const data = await res.json();
11
+
12
+ data.forEach(entry => {
13
+ chatBox.innerHTML += `
14
+ <div class="msg user-msg"><strong>You:</strong> ${entry.user}</div>
15
+ <div class="msg bot-msg"><strong>Bot:</strong> ${entry.bot}</div>
16
+ `;
17
+ });
18
+
19
+ chatBox.scrollTop = chatBox.scrollHeight;
20
+ } catch (err) {
21
+ chatBox.innerHTML += `<div class="msg bot-msg">⚠️ Failed to load history.</div>`;
22
+ }
23
+ }
24
+
25
+ // ✅ Handle new chat message submit
26
+ form.addEventListener("submit", async (e) => {
27
+ e.preventDefault();
28
+ const message = input.value.trim();
29
+ if (!message) return;
30
+
31
+ chatBox.innerHTML += `<div class="msg user-msg">You: ${message}</div>`;
32
+ input.value = "";
33
+
34
+ try {
35
+ const response = await fetch("/chat", {
36
+ method: "POST",
37
+ headers: { "Content-Type": "application/json" },
38
+ body: JSON.stringify({ message }),
39
+ });
40
+
41
+ const data = await response.json();
42
+ chatBox.innerHTML += `<div class="msg bot-msg">Bot: ${data.response}</div>`;
43
+ chatBox.scrollTop = chatBox.scrollHeight;
44
+ } catch (error) {
45
+ chatBox.innerHTML += `<div class="msg bot-msg">⚠️ Error: Could not get a response.</div>`;
46
+ }
47
+ });
48
+
49
+ // 🔄 Load history on page load
50
+ loadHistory();
51
+ });
static/styles.css ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* 📄 File: static/styles.css */
2
+ body {
3
+ margin: 0;
4
+ font-family: 'Segoe UI', sans-serif;
5
+ background: linear-gradient(-45deg, #0f0f0f, #1a1a1a, #2c2c2c, #000000);
6
+ background-size: 400% 400%;
7
+ animation: gradientBG 18s ease infinite;
8
+ display: flex;
9
+ justify-content: center;
10
+ align-items: center;
11
+ height: 100vh;
12
+ overflow: hidden;
13
+ }
14
+
15
+ @keyframes gradientBG {
16
+ 0% { background-position: 0% 50%; }
17
+ 50% { background-position: 100% 50%; }
18
+ 100% { background-position: 0% 50%; }
19
+ }
20
+
21
+ .chat-container {
22
+ width: 90%;
23
+ max-width: 600px;
24
+ background: rgba(0, 0, 0, 0.3);
25
+ padding: 1.5rem;
26
+ border-radius: 20px;
27
+ backdrop-filter: blur(15px);
28
+ -webkit-backdrop-filter: blur(15px);
29
+ border: 2px solid rgba(255, 255, 255, 0.1);
30
+ box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
31
+ position: relative;
32
+ overflow: hidden;
33
+ }
34
+
35
+ .chat-container::before {
36
+ content: "";
37
+ position: absolute;
38
+ top: -50%;
39
+ left: -50%;
40
+ width: 200%;
41
+ height: 200%;
42
+ background: linear-gradient(45deg, #ff00cc, #3333ff, #00ffcc, #ffcc00);
43
+ background-size: 400% 400%;
44
+ animation: glowingBorder 12s linear infinite;
45
+ z-index: -1;
46
+ filter: blur(50px);
47
+ opacity: 0.15;
48
+ }
49
+
50
+ @keyframes glowingBorder {
51
+ 0% { transform: rotate(0deg); }
52
+ 100% { transform: rotate(360deg); }
53
+ }
54
+
55
+ h1 {
56
+ text-align: center;
57
+ color: #ffffff;
58
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
59
+ margin-bottom: 1rem;
60
+ font-size: 2rem;
61
+ }
62
+
63
+ .chat-box {
64
+ height: 400px;
65
+ overflow-y: auto;
66
+ border: 1px solid rgba(255, 255, 255, 0.1);
67
+ padding: 1rem;
68
+ margin-bottom: 1rem;
69
+ background-color: rgba(255, 255, 255, 0.05);
70
+ border-radius: 12px;
71
+ box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.2);
72
+ color: white;
73
+ display: flex;
74
+ flex-direction: column;
75
+ scroll-behavior: smooth; /* 💡 Smooth scroll on new messages */
76
+ word-wrap: break-word;
77
+ }
78
+
79
+ .msg {
80
+ margin-bottom: 1rem;
81
+ padding: 0.6rem 1rem;
82
+ border-radius: 10px;
83
+ max-width: 90%;
84
+ line-height: 1.4;
85
+ word-break: break-word;
86
+ background: rgba(255, 255, 255, 0.08);
87
+ backdrop-filter: blur(4px);
88
+ animation: fadeIn 0.4s ease;
89
+ }
90
+
91
+ /* 👤 User messages aligned right */
92
+ .user-msg {
93
+ align-self: flex-end;
94
+ background: rgba(0, 162, 255, 0.2);
95
+ color: #80d8ff;
96
+ text-align: right;
97
+ }
98
+
99
+ /* 🤖 Bot messages aligned left */
100
+ .bot-msg {
101
+ align-self: flex-start;
102
+ background: rgba(0, 255, 170, 0.15);
103
+ color: #a7ffeb;
104
+ text-align: left;
105
+ }
106
+
107
+ @keyframes fadeIn {
108
+ from { opacity: 0; transform: translateY(10px); }
109
+ to { opacity: 1; transform: translateY(0); }
110
+ }
111
+
112
+ form {
113
+ display: flex;
114
+ gap: 0.5rem;
115
+ }
116
+
117
+ input[type="text"] {
118
+ flex: 1;
119
+ padding: 0.75rem;
120
+ border: 1px solid rgba(255, 255, 255, 0.15);
121
+ border-radius: 12px;
122
+ font-size: 1rem;
123
+ background: rgba(255, 255, 255, 0.05);
124
+ color: white;
125
+ outline: none;
126
+ transition: box-shadow 0.3s ease;
127
+ }
128
+
129
+ input[type="text"]::placeholder {
130
+ color: rgba(255, 255, 255, 0.5);
131
+ }
132
+
133
+ input[type="text"]:focus {
134
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
135
+ }
136
+
137
+ button {
138
+ background: linear-gradient(135deg, #00c6ff, #0072ff);
139
+ color: white;
140
+ border: none;
141
+ padding: 0.8rem 1.4rem;
142
+ border-radius: 12px;
143
+ font-size: 1rem;
144
+ font-weight: bold;
145
+ cursor: pointer;
146
+ box-shadow: 0 0 15px rgba(0, 198, 255, 0.5);
147
+ transition: all 0.3s ease-in-out;
148
+ position: relative;
149
+ overflow: hidden;
150
+ }
151
+
152
+ button::before {
153
+ content: "";
154
+ position: absolute;
155
+ top: 50%;
156
+ left: 50%;
157
+ width: 0%;
158
+ height: 0%;
159
+ background: rgba(255, 255, 255, 0.15);
160
+ border-radius: 50%;
161
+ transform: translate(-50%, -50%);
162
+ transition: width 0.5s ease, height 0.5s ease;
163
+ }
164
+
165
+ button:hover::before {
166
+ width: 300%;
167
+ height: 300%;
168
+ }
169
+
170
+ button:hover {
171
+ box-shadow: 0 0 18px rgba(0, 210, 255, 0.8), 0 0 28px rgba(58, 71, 213, 0.6);
172
+ transform: scale(1.05);
173
+ }