|
<!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">
|
|
|
|
</div>
|
|
<div class="content-preview" id="content-preview">
|
|
|
|
</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">
|
|
|
|
</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 = '';
|
|
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> |