Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +193 -58
index.html
CHANGED
|
@@ -3,52 +3,128 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
</head>
|
| 9 |
-
<body
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
<
|
| 15 |
-
|
| 16 |
-
<
|
| 17 |
-
<div class="border-2 border-dashed border-gray-300 rounded-lg p-4">
|
| 18 |
-
<input type="file" id="files" multiple class="w-full">
|
| 19 |
-
</div>
|
| 20 |
-
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
|
| 21 |
-
Upload Documents
|
| 22 |
-
</button>
|
| 23 |
-
</form>
|
| 24 |
-
<div id="botId" class="mt-4 text-green-600 font-medium"></div>
|
| 25 |
</div>
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
class="w-full p-2 border rounded h-24"></textarea>
|
| 35 |
-
<button type="submit" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600">
|
| 36 |
-
Send Query
|
| 37 |
-
</button>
|
| 38 |
-
</form>
|
| 39 |
-
<div id="response" class="mt-4 p-4 bg-gray-50 rounded-lg hidden">
|
| 40 |
-
<h3 class="font-semibold mb-2">Response:</h3>
|
| 41 |
-
<p id="responseText" class="whitespace-pre-wrap"></p>
|
| 42 |
-
</div>
|
| 43 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</div>
|
| 45 |
|
| 46 |
<script>
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
const files = document.getElementById('files').files;
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
for (let file of files) {
|
| 53 |
formData.append('files', file);
|
| 54 |
}
|
|
@@ -58,36 +134,95 @@
|
|
| 58 |
method: 'POST',
|
| 59 |
body: formData
|
| 60 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
const data = await response.json();
|
| 62 |
-
document.getElementById('
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
} catch (error) {
|
| 65 |
console.error('Error:', error);
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
-
}
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
try {
|
| 77 |
-
const response = await fetch(
|
| 78 |
-
method: 'POST',
|
| 79 |
-
body: formData
|
| 80 |
-
});
|
| 81 |
const data = await response.json();
|
| 82 |
-
|
| 83 |
-
const responseText = document.getElementById('responseText');
|
| 84 |
-
responseDiv.classList.remove('hidden');
|
| 85 |
-
responseText.textContent = data.response;
|
| 86 |
} catch (error) {
|
| 87 |
-
console.error('Error:', error);
|
| 88 |
-
alert('Error sending query');
|
| 89 |
}
|
| 90 |
-
}
|
| 91 |
</script>
|
| 92 |
</body>
|
| 93 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>SmartlyQ Chatbot Demo</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
max-width: 800px;
|
| 11 |
+
margin: 0 auto;
|
| 12 |
+
padding: 20px;
|
| 13 |
+
}
|
| 14 |
+
.demo-section {
|
| 15 |
+
margin: 40px 0;
|
| 16 |
+
padding: 20px;
|
| 17 |
+
border: 1px solid #ddd;
|
| 18 |
+
border-radius: 8px;
|
| 19 |
+
background: white;
|
| 20 |
+
}
|
| 21 |
+
pre {
|
| 22 |
+
background: #f5f5f5;
|
| 23 |
+
padding: 15px;
|
| 24 |
+
border-radius: 4px;
|
| 25 |
+
overflow-x: auto;
|
| 26 |
+
}
|
| 27 |
+
.upload-area {
|
| 28 |
+
border: 2px dashed #ddd;
|
| 29 |
+
padding: 20px;
|
| 30 |
+
text-align: center;
|
| 31 |
+
margin: 20px 0;
|
| 32 |
+
border-radius: 8px;
|
| 33 |
+
}
|
| 34 |
+
button {
|
| 35 |
+
background: #007bff;
|
| 36 |
+
color: white;
|
| 37 |
+
border: none;
|
| 38 |
+
padding: 8px 16px;
|
| 39 |
+
border-radius: 4px;
|
| 40 |
+
cursor: pointer;
|
| 41 |
+
margin: 5px;
|
| 42 |
+
}
|
| 43 |
+
button:hover {
|
| 44 |
+
background: #0056b3;
|
| 45 |
+
}
|
| 46 |
+
input[type="text"] {
|
| 47 |
+
padding: 8px;
|
| 48 |
+
border: 1px solid #ddd;
|
| 49 |
+
border-radius: 4px;
|
| 50 |
+
margin: 5px;
|
| 51 |
+
}
|
| 52 |
+
.success-message {
|
| 53 |
+
color: #28a745;
|
| 54 |
+
margin: 10px 0;
|
| 55 |
+
font-weight: bold;
|
| 56 |
+
}
|
| 57 |
+
.error-message {
|
| 58 |
+
color: #dc3545;
|
| 59 |
+
margin: 10px 0;
|
| 60 |
+
font-weight: bold;
|
| 61 |
+
}
|
| 62 |
+
#demo-container {
|
| 63 |
+
margin-top: 20px;
|
| 64 |
+
}
|
| 65 |
+
.bot-link {
|
| 66 |
+
display: block;
|
| 67 |
+
margin: 10px 0;
|
| 68 |
+
color: #007bff;
|
| 69 |
+
text-decoration: none;
|
| 70 |
+
}
|
| 71 |
+
.bot-link:hover {
|
| 72 |
+
text-decoration: underline;
|
| 73 |
+
}
|
| 74 |
+
.copy-button {
|
| 75 |
+
background: #6c757d;
|
| 76 |
+
font-size: 0.9em;
|
| 77 |
+
}
|
| 78 |
+
.copy-button:hover {
|
| 79 |
+
background: #5a6268;
|
| 80 |
+
}
|
| 81 |
+
</style>
|
| 82 |
</head>
|
| 83 |
+
<body>
|
| 84 |
+
<h1>SmartlyQ Chatbot Demo</h1>
|
| 85 |
+
|
| 86 |
+
<div class="demo-section">
|
| 87 |
+
<h2>1. Create New Bot</h2>
|
| 88 |
+
<p>Upload your documents (PDFs, text files) to create a new bot:</p>
|
| 89 |
+
<div class="upload-area">
|
| 90 |
+
<input type="file" id="files" multiple>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
</div>
|
| 92 |
+
<button onclick="uploadDocuments()">Create Bot</button>
|
| 93 |
+
<div id="upload-result" class="success-message"></div>
|
| 94 |
+
</div>
|
| 95 |
|
| 96 |
+
<div class="demo-section">
|
| 97 |
+
<h2>2. Test Your Bot</h2>
|
| 98 |
+
<p>Enter your botid below to test the chatbot:</p>
|
| 99 |
+
<div style="margin-bottom: 20px;">
|
| 100 |
+
<input type="text" id="botid-input" placeholder="Enter your botid">
|
| 101 |
+
<button onclick="loadChatbot()">Load Chatbot</button>
|
| 102 |
+
<button onclick="openBotPage()" class="copy-button">Open Bot Page</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
</div>
|
| 104 |
+
<div id="bot-link"></div>
|
| 105 |
+
<div id="demo-container"></div>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div class="demo-section">
|
| 109 |
+
<h2>3. Embed Code</h2>
|
| 110 |
+
<p>To embed this chatbot on your website, add the following code to your HTML:</p>
|
| 111 |
+
<pre id="embed-code">
|
| 112 |
+
<!-- Add your botid to see the embed code -->
|
| 113 |
+
</pre>
|
| 114 |
</div>
|
| 115 |
|
| 116 |
<script>
|
| 117 |
+
// Keep track of current bot ID
|
| 118 |
+
let currentBotId = null;
|
| 119 |
+
|
| 120 |
+
async function uploadDocuments() {
|
| 121 |
const files = document.getElementById('files').files;
|
| 122 |
+
if (files.length === 0) {
|
| 123 |
+
alert('Please select at least one file');
|
| 124 |
+
return;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
const formData = new FormData();
|
| 128 |
for (let file of files) {
|
| 129 |
formData.append('files', file);
|
| 130 |
}
|
|
|
|
| 134 |
method: 'POST',
|
| 135 |
body: formData
|
| 136 |
});
|
| 137 |
+
|
| 138 |
+
if (!response.ok) {
|
| 139 |
+
throw new Error('Upload failed');
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
const data = await response.json();
|
| 143 |
+
const uploadResult = document.getElementById('upload-result');
|
| 144 |
+
uploadResult.textContent = `Success! Your Bot ID: ${data.botid}`;
|
| 145 |
+
uploadResult.className = 'success-message';
|
| 146 |
+
|
| 147 |
+
// Automatically fill the test bot ID
|
| 148 |
+
document.getElementById('botid-input').value = data.botid;
|
| 149 |
+
currentBotId = data.botid;
|
| 150 |
+
|
| 151 |
+
// Update embed code and bot link
|
| 152 |
+
updateEmbedCode(data.botid);
|
| 153 |
+
updateBotLink(data.botid);
|
| 154 |
} catch (error) {
|
| 155 |
console.error('Error:', error);
|
| 156 |
+
const uploadResult = document.getElementById('upload-result');
|
| 157 |
+
uploadResult.textContent = 'Error uploading files. Please try again.';
|
| 158 |
+
uploadResult.className = 'error-message';
|
| 159 |
}
|
| 160 |
+
}
|
| 161 |
|
| 162 |
+
function loadChatbot() {
|
| 163 |
+
const botid = document.getElementById('botid-input').value.trim();
|
| 164 |
+
if (!botid) {
|
| 165 |
+
alert('Please enter a botid');
|
| 166 |
+
return;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
currentBotId = botid;
|
| 170 |
|
| 171 |
+
// Update embed code and bot link
|
| 172 |
+
updateEmbedCode(botid);
|
| 173 |
+
updateBotLink(botid);
|
| 174 |
+
|
| 175 |
+
// Clear previous chatbot if exists
|
| 176 |
+
const container = document.getElementById('demo-container');
|
| 177 |
+
container.innerHTML = '';
|
| 178 |
+
|
| 179 |
+
// Create new container for this instance
|
| 180 |
+
const chatbotContainer = document.createElement('div');
|
| 181 |
+
chatbotContainer.id = 'smartlyq-chatbot-container';
|
| 182 |
+
container.appendChild(chatbotContainer);
|
| 183 |
+
|
| 184 |
+
// Create and append script
|
| 185 |
+
const script = document.createElement('script');
|
| 186 |
+
script.src = `/static/chatbot.js?botid=${botid}`;
|
| 187 |
+
container.appendChild(script);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
function updateBotLink(botid) {
|
| 191 |
+
const botLink = document.getElementById('bot-link');
|
| 192 |
+
const botUrl = `${window.location.origin}/bot.html?botid=${botid}`;
|
| 193 |
+
botLink.innerHTML = `
|
| 194 |
+
<p>Direct bot link:</p>
|
| 195 |
+
<a href="${botUrl}" target="_blank" class="bot-link">${botUrl}</a>
|
| 196 |
+
<button onclick="copyToClipboard('${botUrl}')" class="copy-button">Copy Link</button>
|
| 197 |
+
`;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
function openBotPage() {
|
| 201 |
+
const botid = document.getElementById('botid-input').value.trim();
|
| 202 |
+
if (!botid) {
|
| 203 |
+
alert('Please enter a botid');
|
| 204 |
+
return;
|
| 205 |
+
}
|
| 206 |
+
window.open(`/bot.html?botid=${botid}`, '_blank');
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
function copyToClipboard(text) {
|
| 210 |
+
navigator.clipboard.writeText(text).then(() => {
|
| 211 |
+
alert('Link copied to clipboard!');
|
| 212 |
+
}).catch(err => {
|
| 213 |
+
console.error('Failed to copy:', err);
|
| 214 |
+
});
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
async function updateEmbedCode(botid) {
|
| 218 |
try {
|
| 219 |
+
const response = await fetch(`/embed-code?botid=${botid}`);
|
|
|
|
|
|
|
|
|
|
| 220 |
const data = await response.json();
|
| 221 |
+
document.getElementById('embed-code').textContent = data.embed_code;
|
|
|
|
|
|
|
|
|
|
| 222 |
} catch (error) {
|
| 223 |
+
console.error('Error fetching embed code:', error);
|
|
|
|
| 224 |
}
|
| 225 |
+
}
|
| 226 |
</script>
|
| 227 |
</body>
|
| 228 |
</html>
|