qdqd commited on
Commit
2e4802f
·
verified ·
1 Parent(s): 371e000

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +261 -0
templates/index.html ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html><head><base href="https://aidemo.org/justiceforkdr/">
2
+ <meta charset="UTF-8">
3
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
4
+ <title>Sonia Bot - Justice AI Chatbot</title>
5
+ <style>
6
+ @import url('https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap');
7
+
8
+ body, html {
9
+ margin: 0;
10
+ padding: 0;
11
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
12
+ background-color: #121212;
13
+ color: #ffffff;
14
+ height: 100%;
15
+ overflow: hidden;
16
+ }
17
+ .chat-container {
18
+ display: flex;
19
+ flex-direction: column;
20
+ height: 100vh;
21
+ background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
22
+ }
23
+ .chat-header {
24
+ background-color: #1e1e1e;
25
+ padding: 15px 20px;
26
+ display: flex;
27
+ justify-content: space-between;
28
+ align-items: center;
29
+ box-shadow: 0 2px 10px rgba(0,0,0,0.2);
30
+ }
31
+ .chat-header h1 {
32
+ margin: 0;
33
+ font-size: 32px;
34
+ font-weight: bold;
35
+ font-family: 'Dancing Script', cursive;
36
+ color: #b30000;
37
+ text-align: center;
38
+ flex-grow: 1;
39
+ }
40
+ .chat-header button {
41
+ background-color: transparent;
42
+ border: 2px solid #b30000;
43
+ color: #b30000;
44
+ padding: 8px 15px;
45
+ border-radius: 20px;
46
+ cursor: pointer;
47
+ transition: all 0.3s ease;
48
+ }
49
+ .chat-header button:hover {
50
+ background-color: #b30000;
51
+ color: #fff;
52
+ }
53
+ .chat-messages {
54
+ flex-grow: 1;
55
+ overflow-y: auto;
56
+ padding: 20px;
57
+ display: flex;
58
+ flex-direction: column;
59
+ }
60
+ .message {
61
+ margin-bottom: 15px;
62
+ padding: 12px 18px;
63
+ border-radius: 18px;
64
+ max-width: 80%;
65
+ animation: fadeIn 0.3s ease-out;
66
+ }
67
+ @keyframes fadeIn {
68
+ from { opacity: 0; transform: translateY(10px); }
69
+ to { opacity: 1; transform: translateY(0); }
70
+ }
71
+ .user-message {
72
+ background-color: #2a2a2a;
73
+ margin-left: auto;
74
+ border-bottom-right-radius: 4px;
75
+ }
76
+ .ai-message {
77
+ background-color: #b30000;
78
+ margin-right: auto;
79
+ border-bottom-left-radius: 4px;
80
+ }
81
+ .input-area {
82
+ display: flex;
83
+ padding: 20px;
84
+ background-color: #1e1e1e;
85
+ box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
86
+ }
87
+ #user-input {
88
+ flex-grow: 1;
89
+ padding: 15px;
90
+ border: none;
91
+ border-radius: 25px;
92
+ background-color: #2a2a2a;
93
+ color: #fff;
94
+ font-size: 16px;
95
+ transition: all 0.3s ease;
96
+ }
97
+ #user-input:focus {
98
+ outline: none;
99
+ box-shadow: 0 0 0 2px #b30000;
100
+ }
101
+ #send-button {
102
+ padding: 15px 25px;
103
+ margin-left: 10px;
104
+ border: none;
105
+ background-color: #b30000;
106
+ color: white;
107
+ cursor: pointer;
108
+ border-radius: 25px;
109
+ font-size: 16px;
110
+ transition: background-color 0.3s ease;
111
+ }
112
+ #send-button:hover {
113
+ background-color: #8b0000;
114
+ }
115
+ .typing-indicator {
116
+ display: flex;
117
+ padding: 12px 18px;
118
+ background-color: #b30000;
119
+ border-radius: 18px;
120
+ margin-right: auto;
121
+ margin-bottom: 15px;
122
+ align-items: center;
123
+ }
124
+ .typing-indicator span {
125
+ height: 8px;
126
+ width: 8px;
127
+ background-color: #fff;
128
+ border-radius: 50%;
129
+ display: inline-block;
130
+ margin-right: 5px;
131
+ animation: typing 1s infinite ease-in-out;
132
+ }
133
+ .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
134
+ .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
135
+ @keyframes typing {
136
+ 0% { transform: translateY(0); }
137
+ 50% { transform: translateY(-5px); }
138
+ 100% { transform: translateY(0); }
139
+ }
140
+ </style>
141
+ </head>
142
+ <body>
143
+ <div class="chat-container">
144
+ <div class="chat-header">
145
+ <button id="clear-chat">Clear Chat</button>
146
+ <h1>Sonia Bot</h1>
147
+ <div style="width: 95px;"></div> <!-- Placeholder for balance -->
148
+ </div>
149
+ <div class="chat-messages" id="chat-messages"></div>
150
+ <div class="input-area">
151
+ <input type="text" id="user-input" placeholder="Type your message here...">
152
+ <button id="send-button">Send</button>
153
+ </div>
154
+ </div>
155
+
156
+ <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
157
+ <script>
158
+ const chatMessages = document.getElementById('chat-messages');
159
+ const userInput = document.getElementById('user-input');
160
+ const sendButton = document.getElementById('send-button');
161
+ const clearChatButton = document.getElementById('clear-chat');
162
+
163
+ const OPENAI_API_KEY = 'sk-OsMMq65tXdfOIlTUYtocSL7NCsmA7CerN77OkEv29dODg1EA'; // Replace with your actual API key
164
+ const SYSTEM_PROMPT = `You are Sonia Bot, an AI assistant dedicated to providing information and support regarding the case of Kolkata's fallen doctor. Your role is to offer factual information, empathetic responses, and guidance on how people can support the cause for justice. Always maintain a respectful and compassionate tone while discussing this sensitive topic.
165
+
166
+ Key points to remember:
167
+ 1. Provide accurate information about the case timeline and current status.
168
+ 2. Offer ways for users to support the cause, such as signing petitions or joining awareness campaigns.
169
+ 3. Emphasize the importance of improved safety measures for healthcare workers.
170
+ 4. Direct users to reliable sources for more information.
171
+ 5. Be sensitive and supportive when discussing the impact on the victim's family and the medical community.
172
+
173
+ Remember, your primary goal is to inform and guide users while promoting a respectful and just approach to addressing this tragic incident.`;
174
+
175
+ let conversationHistory = [
176
+ { role: "system", content: SYSTEM_PROMPT },
177
+ { role: "assistant", content: "Hello! I'm Sonia Bot, here to provide information and support regarding the case of Kolkata's fallen doctor. How can I assist you today?" }
178
+ ];
179
+
180
+ function addMessage(message, isUser) {
181
+ const messageElement = document.createElement('div');
182
+ messageElement.classList.add('message');
183
+ messageElement.classList.add(isUser ? 'user-message' : 'ai-message');
184
+ messageElement.textContent = message;
185
+ chatMessages.appendChild(messageElement);
186
+ chatMessages.scrollTop = chatMessages.scrollHeight;
187
+ }
188
+
189
+ function showTypingIndicator() {
190
+ const indicator = document.createElement('div');
191
+ indicator.classList.add('typing-indicator');
192
+ indicator.innerHTML = '<span></span><span></span><span></span>';
193
+ chatMessages.appendChild(indicator);
194
+ chatMessages.scrollTop = chatMessages.scrollHeight;
195
+ return indicator;
196
+ }
197
+
198
+ async function getAIResponse(userMessage) {
199
+ try {
200
+ conversationHistory.push({ role: "user", content: userMessage });
201
+
202
+ const response = await axios.post('http://localhost:1337/v1', {
203
+ model: "gpt-4o",
204
+ messages: conversationHistory,
205
+ max_tokens: 150,
206
+ temperature: 0.7,
207
+ top_p: 1,
208
+ frequency_penalty: 0,
209
+ presence_penalty: 0,
210
+ }, {
211
+ headers: {
212
+ 'Authorization': `Bearer ${OPENAI_API_KEY}`,
213
+ 'Content-Type': 'application/json'
214
+ }
215
+ });
216
+
217
+ const aiResponse = response.data.choices[0].message.content.trim();
218
+ conversationHistory.push({ role: "assistant", content: aiResponse });
219
+ return aiResponse;
220
+ } catch (error) {
221
+ console.error('Error:', error);
222
+ return "I'm sorry, I couldn't process your request at the moment. Please try again later.";
223
+ }
224
+ }
225
+
226
+ async function handleUserInput() {
227
+ const userMessage = userInput.value.trim();
228
+ if (userMessage) {
229
+ addMessage(userMessage, true);
230
+ userInput.value = '';
231
+
232
+ const typingIndicator = showTypingIndicator();
233
+
234
+ const aiResponse = await getAIResponse(userMessage);
235
+ chatMessages.removeChild(typingIndicator);
236
+ addMessage(aiResponse, false);
237
+ }
238
+ }
239
+
240
+ function clearChat() {
241
+ chatMessages.innerHTML = '';
242
+ conversationHistory = [
243
+ { role: "system", content: SYSTEM_PROMPT },
244
+ { role: "assistant", content: "Hello! I'm Sonia Bot, here to provide information and support regarding the case of Kolkata's fallen doctor. How can I assist you today?" }
245
+ ];
246
+ addMessage(conversationHistory[1].content, false);
247
+ }
248
+
249
+ sendButton.addEventListener('click', handleUserInput);
250
+ userInput.addEventListener('keypress', (e) => {
251
+ if (e.key === 'Enter') {
252
+ handleUserInput();
253
+ }
254
+ });
255
+ clearChatButton.addEventListener('click', clearChat);
256
+
257
+ // Initial message
258
+ addMessage(conversationHistory[1].content, false);
259
+ </script>
260
+ </body>
261
+ </html>