File size: 8,043 Bytes
390cffd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agil Support</title>
<style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f5f5f5;
        }
        .chat-container {
            max-width: 400px;
            margin: 20px auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .chat-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            text-align: center;
        }
        .chat-header h3 {
            font-size: 18px;
            margin-bottom: 5px;
        }
        .chat-header p {
            font-size: 12px;
            opacity: 0.9;
        }
        .chat-messages {
            height: 400px;
            overflow-y: auto;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        .message {
            max-width: 80%;
            padding: 12px 16px;
            border-radius: 18px;
            font-size: 14px;
            line-height: 1.4;
        }
        .user-message {
            background: #667eea;
            color: white;
            align-self: flex-end;
            border-bottom-right-radius: 4px;
        }
        .bot-message {
            background: #f0f0f0;
            color: #333;
            align-self: flex-start;
            border-bottom-left-radius: 4px;
        }
        .typing-indicator {
            display: none;
            align-self: flex-start;
            padding: 12px 16px;
            background: #f0f0f0;
            border-radius: 18px;
            border-bottom-left-radius: 4px;
        }
        .typing-dots {
            display: inline-block;
        }
        .typing-dots span {
            display: inline-block;
            width: 4px;
            height: 4px;
            border-radius: 50%;
            background: #999;
            margin: 0 1px;
            animation: typing 1.4s infinite;
        }
        .typing-dots span:nth-child(2) {
            animation-delay: 0.2s;
        }
        .typing-dots span:nth-child(3) {
            animation-delay: 0.4s;
        }
        @keyframes typing {
            0%, 60%, 100% { transform: translateY(0); }
            30% { transform: translateY(-10px); }
        }
        .chat-input {
            display: flex;
            padding: 20px;
            border-top: 1px solid #eee;
            gap: 10px;
        }
        .chat-input input {
            flex: 1;
            padding: 12px 16px;
            border: 1px solid #ddd;
            border-radius: 24px;
            outline: none;
            font-size: 14px;
        }
        .chat-input input:focus {
            border-color: #667eea;
        }
        .send-btn {
            padding: 12px 20px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 24px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.3s;
        }
        .send-btn:hover {
            background: #5a6fd8;
        }
        .send-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
        }
        .quick-questions {
            padding: 20px;
            border-top: 1px solid #eee;
        }
        .quick-questions h4 {
            font-size: 14px;
            margin-bottom: 10px;
            color: #666;
        }
        .question-btn {
            display: block;
            width: 100%;
            padding: 8px 12px;
            margin-bottom: 6px;
            background: #f8f9ff;
            border: 1px solid #e0e5ff;
            border-radius: 8px;
            color: #667eea;
            font-size: 12px;
            cursor: pointer;
            text-align: left;
            transition: all 0.3s;
        }
        .question-btn:hover {
            background: #667eea;
            color: white;
        }
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h3>Agil Support</h3>
<p>Ask me anything about the platform</p>
</div>
<div class="chat-messages" id="messages">
<div class="message bot-message">
                Hi! I'm here to help with OncoConnect questions. Ask me about accounts, image uploads, trials, or challenges!
</div>
</div>
<div class="typing-indicator" id="typing">
<div class="typing-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="chat-input">
<input type="text" id="messageInput" placeholder="Type your question..." maxlength="200">
<button id="sendBtn" class="send-btn">Send</button>
</div>
<div class="quick-questions">
<h4>Quick Questions:</h4>
<button class="question-btn" onclick="askQuestion('How do I create an account?')">How do I create an account?</button>
<button class="question-btn" onclick="askQuestion('What file types can I upload?')">What file types can I upload?</button>
<button class="question-btn" onclick="askQuestion('How do I join a challenge?')">How do I join a challenge?</button>
<button class="question-btn" onclick="askQuestion('Is this tool FDA cleared?')">Is this tool FDA cleared?</button>
</div>
</div>
 
    <script>
        const messagesContainer = document.getElementById('messages');
        const messageInput = document.getElementById('messageInput');
        const sendBtn = document.getElementById('sendBtn');
        const typing = document.getElementById('typing');
 
        async function sendMessage(message) {
            if (!message.trim()) return;
 
            // Add user message
            addMessage(message, 'user');
            messageInput.value = '';
            sendBtn.disabled = true;
            // Show typing indicator
            typing.style.display = 'block';
            messagesContainer.scrollTop = messagesContainer.scrollHeight;
 
            try {
                const response = await fetch('http://localhost:5000/chat', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ message: message })
                });
 
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
 
                const data = await response.json();
                // Hide typing indicator
                typing.style.display = 'none';
                // Add bot response
                addMessage(data.response, 'bot');
            } catch (error) {
                typing.style.display = 'none';
                addMessage('Sorry, I encountered an error. Please try again.', 'bot');
                console.error('Error:', error);
            }
 
            sendBtn.disabled = false;
        }
 
        function addMessage(text, sender) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message ${sender}-message`;
            messageDiv.textContent = text;
            messagesContainer.appendChild(messageDiv);
            messagesContainer.scrollTop = messagesContainer.scrollHeight;
        }
 
        function askQuestion(question) {
            messageInput.value = question;
            sendMessage(question);
        }
 
        sendBtn.addEventListener('click', () => {
            sendMessage(messageInput.value);
        });
 
        messageInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                sendMessage(messageInput.value);
            }
        });
 
        messageInput.addEventListener('input', () => {
            sendBtn.disabled = !messageInput.value.trim();
        });
</script>
</body>
</html>