File size: 10,370 Bytes
a8269a5 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chatbot</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-top: 50px;
}
h1 {
text-align: center;
color: #333;
}
form {
text-align: center;
margin-top: 20px;
}
input[type="text"], input[type="file"] {
width: 70%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin-bottom: 10px;
}
input[type="submit"] {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-bottom: 10px;
}
.chat-history {
margin-top: 20px;
border-top: 1px solid #ccc;
padding-top: 20px;
overflow-y: scroll;
height: 300px;
}
.chat-message {
margin-bottom: 10px;
display: grid;
grid-template-columns: auto auto;
column-gap: 10px;
}
.user-message {
text-align: right;
color: #007bff;
}
.system-message {
text-align: left;
color: #333;
}
.content-preview {
margin-top: 20px;
text-align: center;
}
img {
max-width: 100%;
height: auto;
margin-top: 10px;
}
video {
max-width: 100%;
height: auto;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to the Chatbot</h1>
<div class="chat-history" id="chat-history">
<!-- Chat messages will be displayed here -->
</div>
<div class="content-preview" id="content-preview">
<!-- Content preview will be displayed here -->
</div>
<form id="chat-form">
<input type="text" id="question" placeholder="Type your question here...">
<input type="submit" value="Ask">
</form>
<form id="audio-form" enctype="multipart/form-data">
<input type="file" id="audio-file" accept="audio/*">
<input type="submit" value="Upload Audio">
</form>
<form id="image-form">
<input type="text" id="image-prompt" placeholder="Describe the image you want...">
<input type="submit" value="Generate Image">
</form>
<form id="video-form">
<input type="text" id="video-prompt" placeholder="Describe the video you want...">
<input type="submit" value="Generate Video">
</form>
<form id="summarize-text-form">
<input type="text" id="text-to-summarize" placeholder="Enter text to summarize...">
<input type="submit" value="Summarize Text">
</form>
<form id="summarize-file-form" enctype="multipart/form-data">
<input type="file" id="file-to-summarize" accept=".txt,.pdf,.docx">
<input type="submit" value="Summarize File">
</form>
<div id="response-container">
<!-- Response content will be displayed here -->
</div>
</div>
<script>
const chatForm = document.getElementById('chat-form');
const audioForm = document.getElementById('audio-form');
const imageForm = document.getElementById('image-form');
const videoForm = document.getElementById('video-form');
const summarizeTextForm = document.getElementById('summarize-text-form');
const summarizeFileForm = document.getElementById('summarize-file-form');
const chatHistory = document.getElementById('chat-history');
const contentPreview = document.getElementById('content-preview');
const responseContainer = document.getElementById('response-container');
function displayMessage(message, type) {
const messageElement = document.createElement('div');
messageElement.classList.add('chat-message');
messageElement.innerHTML = `<span class="${type}-message">${message}</span>`;
chatHistory.appendChild(messageElement);
chatHistory.scrollTop = chatHistory.scrollHeight;
}
function displayResponse(response) {
responseContainer.innerHTML = ''; // Clear previous response
if (typeof response === 'string') {
displayMessage(response, 'system');
} else if (response instanceof Blob) {
const url = URL.createObjectURL(response);
if (response.type.startsWith('image/')) {
const img = document.createElement('img');
img.src = url;
responseContainer.appendChild(img);
} else if (response.type.startsWith('video/')) {
const video = document.createElement('video');
video.src = url;
video.controls = true;
responseContainer.appendChild(video);
} else {
displayMessage('Unsupported file type received.', 'system');
}
} else {
displayMessage('Invalid response received.', 'system');
}
}
chatForm.addEventListener('submit', async (event) => {
event.preventDefault();
const question = document.getElementById('question').value;
displayMessage(question, 'user');
const response = await fetch('/ask', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `question=${question}`
}).then(res => res.text());
displayMessage(response, 'system');
});
audioForm.addEventListener('submit', async (event) => {
event.preventDefault();
const audioFile = document.getElementById('audio-file').files[0];
const formData = new FormData();
formData.append('file', audioFile);
const response = await fetch('/upload-audio', {
method: 'POST',
body: formData
}).then(res => res.json());
displayMessage(response.transcription, 'user');
displayMessage(response.response, 'system');
const audio = new Audio(response.tts_audio);
audio.play();
});
imageForm.addEventListener('submit', async (event) => {
event.preventDefault();
const imagePrompt = document.getElementById('image-prompt').value;
displayMessage(`Generating image for: ${imagePrompt}`, 'user');
const response = await fetch('/generate-image', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `text_prompt=${imagePrompt}`
}).then(res => res.blob());
displayResponse(response);
});
videoForm.addEventListener('submit', async (event) => {
event.preventDefault();
const videoPrompt = document.getElementById('video-prompt').value;
displayMessage(`Generating video for: ${videoPrompt}`, 'user');
const response = await fetch('/generate-video', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `text_prompt=${videoPrompt}`
}).then(res => res.blob());
displayResponse(response);
});
summarizeTextForm.addEventListener('submit', async (event) => {
event.preventDefault();
const textToSummarize = document.getElementById('text-to-summarize').value;
displayMessage(`Summarizing text: ${textToSummarize}`, 'user');
const response = await fetch('/summarize-text', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `text=${textToSummarize}`
}).then(res => res.text());
displayMessage(response, 'system');
});
summarizeFileForm.addEventListener('submit', async (event) => {
event.preventDefault();
const fileToSummarize = document.getElementById('file-to-summarize').files[0];
const formData = new FormData();
formData.append('file', fileToSummarize);
const response = await fetch('/summarize-file', {
method: 'POST',
body: formData
}).then(res => res.text());
displayMessage(response, 'system');
});
function getChatMessages() {
fetch("/messages")
.then(response => response.text())
.then(data => {
chatHistory.innerHTML = data;
});
}
function getContentPreview() {
fetch("/content-preview")
.then(response => response.text())
.then(data => {
contentPreview.innerHTML = data;
});
}
setInterval(getChatMessages, 5000);
setInterval(getContentPreview, 5000);
</script>
</body>
</html> |