Spaces:
Paused
Paused
Update index.html
Browse files- index.html +20 -118
index.html
CHANGED
|
@@ -6,124 +6,26 @@
|
|
| 6 |
<title>AI Chatbot</title>
|
| 7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
| 8 |
<style>
|
|
|
|
| 9 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 10 |
body { background: white; height: 100vh; width: 100%; }
|
| 11 |
-
|
| 12 |
-
.chat-icon {
|
| 13 |
-
position: fixed;
|
| 14 |
-
bottom: 25px;
|
| 15 |
-
right: 25px;
|
| 16 |
-
width: 60px;
|
| 17 |
-
height: 60px;
|
| 18 |
-
background-color: #25D366;
|
| 19 |
-
border-radius: 50%;
|
| 20 |
-
display: flex;
|
| 21 |
-
align-items: center;
|
| 22 |
-
justify-content: center;
|
| 23 |
-
cursor: pointer;
|
| 24 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
| 25 |
-
transition: 0.3s;
|
| 26 |
-
z-index: 1000;
|
| 27 |
-
}
|
| 28 |
.chat-icon:hover { transform: scale(1.1); background-color: #128C7E; }
|
| 29 |
.chat-icon i { font-size: 30px; color: white; }
|
| 30 |
-
|
| 31 |
-
.chat-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
overflow: hidden;
|
| 43 |
-
z-index: 1001;
|
| 44 |
-
border: 1px solid #ddd;
|
| 45 |
-
}
|
| 46 |
-
.chat-header {
|
| 47 |
-
background: #075E54;
|
| 48 |
-
color: white;
|
| 49 |
-
padding: 12px;
|
| 50 |
-
font-weight: bold;
|
| 51 |
-
display: flex;
|
| 52 |
-
justify-content: space-between;
|
| 53 |
-
}
|
| 54 |
-
.chat-messages {
|
| 55 |
-
flex: 1;
|
| 56 |
-
padding: 10px;
|
| 57 |
-
overflow-y: auto;
|
| 58 |
-
background: #ECE5DD;
|
| 59 |
-
display: flex;
|
| 60 |
-
flex-direction: column;
|
| 61 |
-
}
|
| 62 |
-
.message {
|
| 63 |
-
margin: 8px 0;
|
| 64 |
-
padding: 8px 12px;
|
| 65 |
-
border-radius: 10px;
|
| 66 |
-
max-width: 80%;
|
| 67 |
-
}
|
| 68 |
-
.user-msg {
|
| 69 |
-
background: #DCF8C6;
|
| 70 |
-
margin-left: auto;
|
| 71 |
-
text-align: right;
|
| 72 |
-
}
|
| 73 |
-
.bot-msg {
|
| 74 |
-
background: white;
|
| 75 |
-
margin-right: auto;
|
| 76 |
-
}
|
| 77 |
-
.questions-container {
|
| 78 |
-
display: flex;
|
| 79 |
-
flex-wrap: wrap;
|
| 80 |
-
gap: 8px;
|
| 81 |
-
margin: 10px 0;
|
| 82 |
-
justify-content: flex-start;
|
| 83 |
-
}
|
| 84 |
-
.question-bubble {
|
| 85 |
-
background: #e4e6eb;
|
| 86 |
-
color: #050505;
|
| 87 |
-
padding: 6px 12px;
|
| 88 |
-
border-radius: 18px;
|
| 89 |
-
font-size: 12px;
|
| 90 |
-
cursor: pointer;
|
| 91 |
-
transition: 0.2s;
|
| 92 |
-
}
|
| 93 |
-
.question-bubble:hover {
|
| 94 |
-
background: #d1d3d8;
|
| 95 |
-
transform: scale(1.02);
|
| 96 |
-
}
|
| 97 |
-
.chat-input-area {
|
| 98 |
-
display: flex;
|
| 99 |
-
padding: 10px;
|
| 100 |
-
background: #f0f0f0;
|
| 101 |
-
}
|
| 102 |
-
.chat-input-area input {
|
| 103 |
-
flex: 1;
|
| 104 |
-
padding: 8px;
|
| 105 |
-
border: 1px solid #ccc;
|
| 106 |
-
border-radius: 20px;
|
| 107 |
-
outline: none;
|
| 108 |
-
}
|
| 109 |
-
.chat-input-area button {
|
| 110 |
-
margin-left: 8px;
|
| 111 |
-
background: #25D366;
|
| 112 |
-
border: none;
|
| 113 |
-
color: white;
|
| 114 |
-
border-radius: 50%;
|
| 115 |
-
width: 36px;
|
| 116 |
-
height: 36px;
|
| 117 |
-
cursor: pointer;
|
| 118 |
-
}
|
| 119 |
.close-btn { cursor: pointer; background: none; border: none; color: white; font-size: 18px; }
|
| 120 |
-
.typing-indicator {
|
| 121 |
-
background: white;
|
| 122 |
-
padding: 8px 12px;
|
| 123 |
-
border-radius: 10px;
|
| 124 |
-
display: inline-block;
|
| 125 |
-
margin: 8px 0;
|
| 126 |
-
}
|
| 127 |
</style>
|
| 128 |
</head>
|
| 129 |
<body>
|
|
@@ -145,8 +47,8 @@
|
|
| 145 |
</div>
|
| 146 |
</div>
|
| 147 |
<script>
|
| 148 |
-
//
|
| 149 |
-
const
|
| 150 |
const DEFAULT_QUESTIONS = [
|
| 151 |
"Mera order status kya hai?",
|
| 152 |
"Main refund kaise le sakta hoon?",
|
|
@@ -210,13 +112,13 @@
|
|
| 210 |
userInput.value = '';
|
| 211 |
showTyping();
|
| 212 |
try {
|
| 213 |
-
const response = await fetch(
|
| 214 |
method: 'POST',
|
| 215 |
headers: { 'Content-Type': 'application/json' },
|
| 216 |
-
body: JSON.stringify({
|
| 217 |
});
|
| 218 |
const result = await response.json();
|
| 219 |
-
const botReply = result.
|
| 220 |
hideTyping();
|
| 221 |
addMessage(botReply, 'bot');
|
| 222 |
} catch (err) {
|
|
|
|
| 6 |
<title>AI Chatbot</title>
|
| 7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
| 8 |
<style>
|
| 9 |
+
/* same CSS as before, copy from your previous code */
|
| 10 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 11 |
body { background: white; height: 100vh; width: 100%; }
|
| 12 |
+
.chat-icon { position: fixed; bottom: 25px; right: 25px; width: 60px; height: 60px; background-color: #25D366; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.2); transition: 0.3s; z-index: 1000; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
.chat-icon:hover { transform: scale(1.1); background-color: #128C7E; }
|
| 14 |
.chat-icon i { font-size: 30px; color: white; }
|
| 15 |
+
.chat-modal { position: fixed; bottom: 100px; right: 25px; width: 350px; height: 500px; background: white; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.3); display: none; flex-direction: column; overflow: hidden; z-index: 1001; border: 1px solid #ddd; }
|
| 16 |
+
.chat-header { background: #075E54; color: white; padding: 12px; font-weight: bold; display: flex; justify-content: space-between; }
|
| 17 |
+
.chat-messages { flex: 1; padding: 10px; overflow-y: auto; background: #ECE5DD; display: flex; flex-direction: column; }
|
| 18 |
+
.message { margin: 8px 0; padding: 8px 12px; border-radius: 10px; max-width: 80%; }
|
| 19 |
+
.user-msg { background: #DCF8C6; margin-left: auto; text-align: right; }
|
| 20 |
+
.bot-msg { background: white; margin-right: auto; }
|
| 21 |
+
.questions-container { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; justify-content: flex-start; }
|
| 22 |
+
.question-bubble { background: #e4e6eb; color: #050505; padding: 6px 12px; border-radius: 18px; font-size: 12px; cursor: pointer; transition: 0.2s; }
|
| 23 |
+
.question-bubble:hover { background: #d1d3d8; transform: scale(1.02); }
|
| 24 |
+
.chat-input-area { display: flex; padding: 10px; background: #f0f0f0; }
|
| 25 |
+
.chat-input-area input { flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 20px; outline: none; }
|
| 26 |
+
.chat-input-area button { margin-left: 8px; background: #25D366; border: none; color: white; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
.close-btn { cursor: pointer; background: none; border: none; color: white; font-size: 18px; }
|
| 28 |
+
.typing-indicator { background: white; padding: 8px 12px; border-radius: 10px; display: inline-block; margin: 8px 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</style>
|
| 30 |
</head>
|
| 31 |
<body>
|
|
|
|
| 47 |
</div>
|
| 48 |
</div>
|
| 49 |
<script>
|
| 50 |
+
// Flask API endpoint (same origin)
|
| 51 |
+
const API_URL = "/api/chat";
|
| 52 |
const DEFAULT_QUESTIONS = [
|
| 53 |
"Mera order status kya hai?",
|
| 54 |
"Main refund kaise le sakta hoon?",
|
|
|
|
| 112 |
userInput.value = '';
|
| 113 |
showTyping();
|
| 114 |
try {
|
| 115 |
+
const response = await fetch(API_URL, {
|
| 116 |
method: 'POST',
|
| 117 |
headers: { 'Content-Type': 'application/json' },
|
| 118 |
+
body: JSON.stringify({ message: msg, session_id: "default_user" })
|
| 119 |
});
|
| 120 |
const result = await response.json();
|
| 121 |
+
const botReply = result.reply;
|
| 122 |
hideTyping();
|
| 123 |
addMessage(botReply, 'bot');
|
| 124 |
} catch (err) {
|