Spaces:
Paused
Paused
Update index.html
Browse files- index.html +8 -43
index.html
CHANGED
|
@@ -9,7 +9,6 @@
|
|
| 9 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 10 |
body { background: white; height: 100vh; width: 100%; }
|
| 11 |
|
| 12 |
-
/* Chat Icon */
|
| 13 |
.chat-icon {
|
| 14 |
position: fixed;
|
| 15 |
bottom: 25px;
|
|
@@ -29,7 +28,6 @@
|
|
| 29 |
.chat-icon:hover { transform: scale(1.1); background-color: #128C7E; }
|
| 30 |
.chat-icon i { font-size: 30px; color: white; }
|
| 31 |
|
| 32 |
-
/* Chat Modal */
|
| 33 |
.chat-modal {
|
| 34 |
position: fixed;
|
| 35 |
bottom: 100px;
|
|
@@ -76,8 +74,6 @@
|
|
| 76 |
background: white;
|
| 77 |
margin-right: auto;
|
| 78 |
}
|
| 79 |
-
|
| 80 |
-
/* Default Questions Bubbles Container */
|
| 81 |
.questions-container {
|
| 82 |
display: flex;
|
| 83 |
flex-wrap: wrap;
|
|
@@ -93,15 +89,11 @@
|
|
| 93 |
font-size: 12px;
|
| 94 |
cursor: pointer;
|
| 95 |
transition: 0.2s;
|
| 96 |
-
user-select: none;
|
| 97 |
-
max-width: 100%;
|
| 98 |
-
word-break: break-word;
|
| 99 |
}
|
| 100 |
.question-bubble:hover {
|
| 101 |
background: #d1d3d8;
|
| 102 |
transform: scale(1.02);
|
| 103 |
}
|
| 104 |
-
|
| 105 |
.chat-input-area {
|
| 106 |
display: flex;
|
| 107 |
padding: 10px;
|
|
@@ -125,8 +117,6 @@
|
|
| 125 |
cursor: pointer;
|
| 126 |
}
|
| 127 |
.close-btn { cursor: pointer; background: none; border: none; color: white; font-size: 18px; }
|
| 128 |
-
|
| 129 |
-
/* Typing indicator */
|
| 130 |
.typing-indicator {
|
| 131 |
background: white;
|
| 132 |
padding: 8px 12px;
|
|
@@ -140,7 +130,6 @@
|
|
| 140 |
<div class="chat-icon" id="chatIcon">
|
| 141 |
<i class="fas fa-comment-dots"></i>
|
| 142 |
</div>
|
| 143 |
-
|
| 144 |
<div class="chat-modal" id="chatModal">
|
| 145 |
<div class="chat-header">
|
| 146 |
<span>AI Assistant 🤖</span>
|
|
@@ -148,7 +137,6 @@
|
|
| 148 |
</div>
|
| 149 |
<div class="chat-messages" id="chatMessages">
|
| 150 |
<div class="message bot-msg">Assalam-o-Alaikum! Main aapki madad kaise kar sakta hoon?</div>
|
| 151 |
-
<!-- Default questions will be injected here via JavaScript -->
|
| 152 |
<div id="defaultQuestionsContainer" class="questions-container"></div>
|
| 153 |
</div>
|
| 154 |
<div class="chat-input-area">
|
|
@@ -156,13 +144,9 @@
|
|
| 156 |
<button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
|
| 157 |
</div>
|
| 158 |
</div>
|
| 159 |
-
|
| 160 |
<script>
|
| 161 |
-
//
|
| 162 |
-
|
| 163 |
-
const GRADIO_API_URL = "https://aapka-space-name.hf.space/api/predict";
|
| 164 |
-
|
| 165 |
-
// Default questions (aap is list ko edit kar sakte hain)
|
| 166 |
const DEFAULT_QUESTIONS = [
|
| 167 |
"Mera order status kya hai?",
|
| 168 |
"Main refund kaise le sakta hoon?",
|
|
@@ -172,7 +156,6 @@
|
|
| 172 |
"Kya aap COD provide karte hain?"
|
| 173 |
];
|
| 174 |
|
| 175 |
-
// ========== DOM ELEMENTS ==========
|
| 176 |
const chatIcon = document.getElementById('chatIcon');
|
| 177 |
const chatModal = document.getElementById('chatModal');
|
| 178 |
const closeChat = document.getElementById('closeChat');
|
|
@@ -181,8 +164,6 @@
|
|
| 181 |
const chatMessages = document.getElementById('chatMessages');
|
| 182 |
const questionsContainer = document.getElementById('defaultQuestionsContainer');
|
| 183 |
|
| 184 |
-
// ========== FUNCTIONS ==========
|
| 185 |
-
// Function to render default question bubbles
|
| 186 |
function renderQuestionBubbles() {
|
| 187 |
questionsContainer.innerHTML = '';
|
| 188 |
DEFAULT_QUESTIONS.forEach(question => {
|
|
@@ -190,15 +171,13 @@
|
|
| 190 |
bubble.className = 'question-bubble';
|
| 191 |
bubble.innerText = question;
|
| 192 |
bubble.onclick = () => {
|
| 193 |
-
// Jab bubble click ho, to automatically send that question
|
| 194 |
userInput.value = question;
|
| 195 |
-
sendMessage();
|
| 196 |
};
|
| 197 |
questionsContainer.appendChild(bubble);
|
| 198 |
});
|
| 199 |
}
|
| 200 |
|
| 201 |
-
// Add message to chat window
|
| 202 |
function addMessage(text, sender) {
|
| 203 |
const msgDiv = document.createElement('div');
|
| 204 |
msgDiv.className = `message ${sender === 'user' ? 'user-msg' : 'bot-msg'}`;
|
|
@@ -207,7 +186,6 @@
|
|
| 207 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 208 |
}
|
| 209 |
|
| 210 |
-
// Remove typing indicator (if any)
|
| 211 |
let typingDiv = null;
|
| 212 |
function showTyping() {
|
| 213 |
if (typingDiv) return;
|
|
@@ -224,20 +202,13 @@
|
|
| 224 |
}
|
| 225 |
}
|
| 226 |
|
| 227 |
-
// Send message to Gradio backend
|
| 228 |
async function sendMessage() {
|
| 229 |
const msg = userInput.value.trim();
|
| 230 |
if (!msg) return;
|
| 231 |
-
|
| 232 |
-
// Hide questions container after first interaction? (optional)
|
| 233 |
-
if (questionsContainer && questionsContainer.style.display !== 'none') {
|
| 234 |
-
questionsContainer.style.display = 'none';
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
addMessage(msg, 'user');
|
| 238 |
userInput.value = '';
|
| 239 |
showTyping();
|
| 240 |
-
|
| 241 |
try {
|
| 242 |
const response = await fetch(GRADIO_API_URL, {
|
| 243 |
method: 'POST',
|
|
@@ -250,24 +221,18 @@
|
|
| 250 |
addMessage(botReply, 'bot');
|
| 251 |
} catch (err) {
|
| 252 |
hideTyping();
|
| 253 |
-
addMessage("Error: Server se baat nahi ho pa rahi.
|
| 254 |
console.error(err);
|
| 255 |
}
|
| 256 |
}
|
| 257 |
|
| 258 |
-
|
| 259 |
-
chatIcon.onclick = () => {
|
| 260 |
chatModal.style.display = 'flex';
|
| 261 |
-
|
| 262 |
-
if (questionsContainer.children.length === 0) {
|
| 263 |
-
renderQuestionBubbles();
|
| 264 |
-
}
|
| 265 |
};
|
| 266 |
-
closeChat.onclick = () =>
|
| 267 |
sendBtn.onclick = sendMessage;
|
| 268 |
userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
|
| 269 |
-
|
| 270 |
-
// Initially render bubbles (so they appear when chat opens)
|
| 271 |
renderQuestionBubbles();
|
| 272 |
</script>
|
| 273 |
</body>
|
|
|
|
| 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;
|
|
|
|
| 28 |
.chat-icon:hover { transform: scale(1.1); background-color: #128C7E; }
|
| 29 |
.chat-icon i { font-size: 30px; color: white; }
|
| 30 |
|
|
|
|
| 31 |
.chat-modal {
|
| 32 |
position: fixed;
|
| 33 |
bottom: 100px;
|
|
|
|
| 74 |
background: white;
|
| 75 |
margin-right: auto;
|
| 76 |
}
|
|
|
|
|
|
|
| 77 |
.questions-container {
|
| 78 |
display: flex;
|
| 79 |
flex-wrap: wrap;
|
|
|
|
| 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;
|
|
|
|
| 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;
|
|
|
|
| 130 |
<div class="chat-icon" id="chatIcon">
|
| 131 |
<i class="fas fa-comment-dots"></i>
|
| 132 |
</div>
|
|
|
|
| 133 |
<div class="chat-modal" id="chatModal">
|
| 134 |
<div class="chat-header">
|
| 135 |
<span>AI Assistant 🤖</span>
|
|
|
|
| 137 |
</div>
|
| 138 |
<div class="chat-messages" id="chatMessages">
|
| 139 |
<div class="message bot-msg">Assalam-o-Alaikum! Main aapki madad kaise kar sakta hoon?</div>
|
|
|
|
| 140 |
<div id="defaultQuestionsContainer" class="questions-container"></div>
|
| 141 |
</div>
|
| 142 |
<div class="chat-input-area">
|
|
|
|
| 144 |
<button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
|
| 145 |
</div>
|
| 146 |
</div>
|
|
|
|
| 147 |
<script>
|
| 148 |
+
// IMPORTANT: Same Space ke API endpoint ka relative URL
|
| 149 |
+
const GRADIO_API_URL = "/api/predict";
|
|
|
|
|
|
|
|
|
|
| 150 |
const DEFAULT_QUESTIONS = [
|
| 151 |
"Mera order status kya hai?",
|
| 152 |
"Main refund kaise le sakta hoon?",
|
|
|
|
| 156 |
"Kya aap COD provide karte hain?"
|
| 157 |
];
|
| 158 |
|
|
|
|
| 159 |
const chatIcon = document.getElementById('chatIcon');
|
| 160 |
const chatModal = document.getElementById('chatModal');
|
| 161 |
const closeChat = document.getElementById('closeChat');
|
|
|
|
| 164 |
const chatMessages = document.getElementById('chatMessages');
|
| 165 |
const questionsContainer = document.getElementById('defaultQuestionsContainer');
|
| 166 |
|
|
|
|
|
|
|
| 167 |
function renderQuestionBubbles() {
|
| 168 |
questionsContainer.innerHTML = '';
|
| 169 |
DEFAULT_QUESTIONS.forEach(question => {
|
|
|
|
| 171 |
bubble.className = 'question-bubble';
|
| 172 |
bubble.innerText = question;
|
| 173 |
bubble.onclick = () => {
|
|
|
|
| 174 |
userInput.value = question;
|
| 175 |
+
sendMessage();
|
| 176 |
};
|
| 177 |
questionsContainer.appendChild(bubble);
|
| 178 |
});
|
| 179 |
}
|
| 180 |
|
|
|
|
| 181 |
function addMessage(text, sender) {
|
| 182 |
const msgDiv = document.createElement('div');
|
| 183 |
msgDiv.className = `message ${sender === 'user' ? 'user-msg' : 'bot-msg'}`;
|
|
|
|
| 186 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 187 |
}
|
| 188 |
|
|
|
|
| 189 |
let typingDiv = null;
|
| 190 |
function showTyping() {
|
| 191 |
if (typingDiv) return;
|
|
|
|
| 202 |
}
|
| 203 |
}
|
| 204 |
|
|
|
|
| 205 |
async function sendMessage() {
|
| 206 |
const msg = userInput.value.trim();
|
| 207 |
if (!msg) return;
|
| 208 |
+
if (questionsContainer) questionsContainer.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
addMessage(msg, 'user');
|
| 210 |
userInput.value = '';
|
| 211 |
showTyping();
|
|
|
|
| 212 |
try {
|
| 213 |
const response = await fetch(GRADIO_API_URL, {
|
| 214 |
method: 'POST',
|
|
|
|
| 221 |
addMessage(botReply, 'bot');
|
| 222 |
} catch (err) {
|
| 223 |
hideTyping();
|
| 224 |
+
addMessage("Error: Server se baat nahi ho pa rahi.", 'bot');
|
| 225 |
console.error(err);
|
| 226 |
}
|
| 227 |
}
|
| 228 |
|
| 229 |
+
chatIcon.onclick = () => {
|
|
|
|
| 230 |
chatModal.style.display = 'flex';
|
| 231 |
+
if (questionsContainer.children.length === 0) renderQuestionBubbles();
|
|
|
|
|
|
|
|
|
|
| 232 |
};
|
| 233 |
+
closeChat.onclick = () => chatModal.style.display = 'none';
|
| 234 |
sendBtn.onclick = sendMessage;
|
| 235 |
userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
|
|
|
|
|
|
|
| 236 |
renderQuestionBubbles();
|
| 237 |
</script>
|
| 238 |
</body>
|