-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
439 lines (380 loc) · 15.3 KB
/
index.html
File metadata and controls
439 lines (380 loc) · 15.3 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StreamKar Support Bot</title>
<link rel="icon" href="https://raw.githubusercontent.com/superuser303/streamkar-bot/refs/heads/main/images.jpeg" type="image/png">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.chat-container {
width: 100%;
max-width: 900px;
height: 90vh;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 25px;
text-align: center;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.chat-header h1 { font-size: 24px; margin-bottom: 5px; }
.chat-header p { font-size: 14px; opacity: 0.9; }
.chat-messages {
flex: 1;
padding: 20px;
overflow-y: auto;
background: #f8f9fa;
}
.message {
margin-bottom: 20px;
display: flex;
align-items: flex-start;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message.user { flex-direction: row-reverse; }
.message-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: white;
flex-shrink: 0;
font-size: 14px;
object-fit: cover;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.user-avatar-style {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.message-content { max-width: 70%; margin: 0 15px; }
.message-bubble {
padding: 15px 20px;
border-radius: 18px;
line-height: 1.5;
font-size: 15px;
}
.message.bot .message-bubble {
background: white;
border: 1px solid #e0e0e0;
border-top-left-radius: 4px;
color: #333;
}
.message.user .message-bubble {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-top-right-radius: 4px;
}
.message-bubble strong { font-weight: 700; color: #764ba2; }
.message-bubble ul { margin-left: 20px; margin-top: 5px; margin-bottom: 5px; }
.message-bubble li { margin-bottom: 4px; }
/* Loading Dots */
.typing-indicator {
display: none;
padding: 15px 20px;
background: white;
border-radius: 18px;
border-top-left-radius: 4px;
width: fit-content;
border: 1px solid #e0e0e0;
margin-left: 55px;
margin-bottom: 20px;
}
.typing-indicator span {
height: 8px;
width: 8px;
background: #667eea;
border-radius: 50%;
display: inline-block;
margin: 0 2px;
animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
0%, 60%, 100% { transform: translateY(0); }
30% { transform: translateY(-8px); }
}
/* Input Area Styles */
.chat-input-container {
padding: 20px;
background: white;
border-top: 1px solid #e0e0e0;
}
.quick-questions {
display: flex;
gap: 10px;
margin-bottom: 15px;
overflow-x: auto;
padding-bottom: 5px;
}
.quick-question-btn {
padding: 8px 16px;
background: #f0f0f0;
border: 1px solid #ddd;
border-radius: 20px;
cursor: pointer;
font-size: 13px;
white-space: nowrap;
transition: all 0.2s;
color: #555;
}
.quick-question-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.input-wrapper { display: flex; gap: 10px; align-items: center; }
.chat-input {
flex: 1;
padding: 15px 20px;
border: 2px solid #e0e0e0;
border-radius: 25px;
font-size: 15px;
outline: none;
transition: border-color 0.3s;
}
.chat-input:focus { border-color: #667eea; }
.send-button {
padding: 15px 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 25px;
cursor: pointer;
font-weight: bold;
transition: transform 0.2s;
}
.send-button:hover { transform: scale(1.05); }
/* Upload Button Style */
.upload-btn {
background: #f0f0f0;
border: none;
padding: 10px 15px;
border-radius: 50%;
font-size: 20px;
cursor: pointer;
transition: background 0.2s;
}
.upload-btn:hover { background: #e0e0e0; }
/* Download Button for Generated Image */
.download-btn {
display: inline-block;
margin-top: 10px;
padding: 8px 15px;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 15px;
font-size: 12px;
font-weight: bold;
}
.download-btn:hover {
background: #5a6fd1;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h1>
<img src="https://raw.githubusercontent.com/superuser303/streamkar-bot/refs/heads/main/logo2.png"
alt="Logo"
style="vertical-align: middle; width: 35px; height: 35px; border-radius: 50%; margin-right: 10px; border: 2px solid rgba(255,255,255,0.3);">
StreamKar Support Bot
</h1>
<p>Expert Help • 24/7 AI Support</p>
</div>
<div class="chat-messages" id="chat-box">
<div class="message bot">
<img src="https://raw.githubusercontent.com/superuser303/streamkar-bot/refs/heads/main/images.jpeg" class="message-avatar" alt="SK">
<div class="message-content">
<div class="message-bubble">
👋 <strong>Hello! I'm StreamKar Bot.</strong><br><br>
I can help you with:<br>
• Creating Accounts & Salary<br>
• <strong>Creating Avatar</strong> (Click the button below!)<br>
• <strong>Analyzing Screenshots</strong> (Click the 📎 icon!)<br>
</div>
</div>
</div>
</div>
<div class="typing-indicator" id="loading">
<span></span><span></span><span></span>
</div>
<div class="chat-input-container">
<div class="quick-questions">
<button class="quick-question-btn" onclick="sendQuickQuestion('How to create an account?')">Create Account</button>
<button class="quick-question-btn" onclick="sendQuickQuestion('What is VIP status?')">VIP Status</button>
<button class="quick-question-btn" onclick="sendQuickQuestion('How to withdraw salary?')">Withdraw Money</button>
<button class="quick-question-btn" onclick="sendQuickQuestion('What is a PK Battle?')">PK Battle</button>
<button class="quick-question-btn" onclick="generateLogo()" style="background: #E91E63; color: white; border: none;">🎨 Create Avatar</button>
</div>
<div id="image-preview-container" style="display: none; padding: 10px; background: #f0f0f0; border-radius: 10px; margin-bottom: 10px; position: relative; width: fit-content;">
<img id="image-preview" src="" style="max-height: 80px; border-radius: 5px;">
<button onclick="clearImage()" style="position: absolute; top: -5px; right: -5px; background: red; color: white; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer;">×</button>
</div>
<div class="input-wrapper">
<input type="file" id="image-upload" accept="image/*" style="display: none;" onchange="handleImageUpload()">
<button class="upload-btn" onclick="document.getElementById('image-upload').click()" title="Upload Screenshot">📎</button>
<input type="text" class="chat-input" id="user-input" placeholder="Type a message..." onkeypress="handleEnter(event)">
<button class="send-button" onclick="sendMessage()">Send</button>
</div>
</div>
</div>
<script>
// ⚠️ UPDATE THIS: If running locally, use http://localhost:8000/chat
const BACKEND_URL = "https://streamkar-bot.onrender.com/chat";
let currentImageBase64 = null;
// --- 1. HANDLE IMAGE UPLOAD (VISION) ---
function handleImageUpload() {
const fileInput = document.getElementById('image-upload');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
currentImageBase64 = e.target.result;
document.getElementById('image-preview').src = currentImageBase64;
document.getElementById('image-preview-container').style.display = 'block';
};
reader.readAsDataURL(file);
}
}
function clearImage() {
currentImageBase64 = null;
document.getElementById('image-upload').value = "";
document.getElementById('image-preview-container').style.display = 'none';
}
// --- 2. SEND MESSAGE (TEXT + OPTIONAL IMAGE) ---
async function sendMessage() {
const input = document.getElementById("user-input");
const msg = input.value.trim();
const loading = document.getElementById("loading");
if (!msg && !currentImageBase64) return;
// Display User Message
let userHTML = msg;
if (currentImageBase64) {
userHTML = `<img src="${currentImageBase64}" style="max-width: 200px; border-radius: 10px; margin-bottom:5px;"><br>${msg}`;
}
addMessage(userHTML, 'user');
const payload = {
message: msg || "Analyze this image",
image: currentImageBase64
};
// Reset Input
input.value = "";
clearImage();
loading.style.display = "flex";
try {
const response = await fetch(BACKEND_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
loading.style.display = "none";
if (data.reply) {
let formattedReply = data.reply.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>").replace(/\n/g, "<br>");
addMessage(formattedReply, 'bot');
} else {
addMessage("⚠️ Error: " + (data.detail || "Unknown"), 'bot');
}
} catch (error) {
loading.style.display = "none";
console.error(error);
addMessage("❌ Connection Error: Is the backend running?", 'bot');
}
}
// --- 3. GENERATE LOGO (UPDATED FOR SECURE PROXY) ---
async function generateLogo() {
const loading = document.getElementById("loading");
addMessage("🎨 Generate a StreamKar Avatar for me!", 'user');
loading.style.display = "flex";
try {
// Replace /chat with /generate-logo
const logoUrl = BACKEND_URL.replace("/chat", "/generate-logo");
const response = await fetch(logoUrl, {
method: "POST",
headers: { "Content-Type": "application/json" }
});
loading.style.display = "none";
// Check if successful (Status 200)
if (response.ok) {
// 1. Convert response to Blob (Image File)
const imageBlob = await response.blob();
// 2. Create a local URL for the Blob
const imageObjectURL = URL.createObjectURL(imageBlob);
// 3. Create display HTML with Download Button
const imgHTML = `
<div>Here is your custom avatar:</div>
<img src="${imageObjectURL}" style="width: 100%; max-width: 300px; border-radius: 15px; margin-top: 10px; border: 2px solid #E91E63;">
<br>
<a href="${imageObjectURL}" download="streamkar-avatar.jpg" class="download-btn">⬇️ Download Image</a>
`;
addMessage(imgHTML, 'bot');
} else {
// Try to read JSON error message if possible
try {
const errorData = await response.json();
addMessage("⚠️ " + (errorData.error || "Generation failed."), 'bot');
} catch (e) {
addMessage("⚠️ Generation failed (Server Error).", 'bot');
}
}
} catch (error) {
loading.style.display = "none";
console.error(error);
addMessage("❌ Generation Error: Check backend console.", 'bot');
}
}
// --- HELPER FUNCTIONS ---
function addMessage(htmlContent, sender) {
const chatBox = document.getElementById("chat-box");
const div = document.createElement("div");
div.className = `message ${sender}`;
const avatarHTML = sender === 'bot'
? '<img src="https://raw.githubusercontent.com/superuser303/streamkar-bot/refs/heads/main/images.jpeg" class="message-avatar" alt="SK">'
: '<div class="message-avatar user-avatar-style">U</div>';
div.innerHTML = `
${sender === 'bot' ? avatarHTML : ''}
<div class="message-content">
<div class="message-bubble">${htmlContent}</div>
</div>
${sender === 'user' ? avatarHTML : ''}
`;
chatBox.appendChild(div);
chatBox.scrollTop = chatBox.scrollHeight;
}
function sendQuickQuestion(question) {
document.getElementById("user-input").value = question;
sendMessage();
}
function handleEnter(e) {
if (e.key === "Enter") sendMessage();
}
</script>
</body>
</html>