Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | |
| <title>Flask Chat App</title> | |
| <style> | |
| body, html { | |
| margin: 0; | |
| padding: 0; | |
| width: 100%; | |
| height: 100%; | |
| background-color: #fddde6; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: flex-start; | |
| font-family: Arial, sans-serif; | |
| font-weight: 300; | |
| } | |
| #video-container { | |
| padding-top: 2%; | |
| width: auto; | |
| height: auto; | |
| } | |
| #video-container video { | |
| width: auto; | |
| height: 35vh; | |
| } | |
| #chat-container, #input-container { | |
| width: 90%; | |
| max-width: 1200px; | |
| margin: 10px; | |
| } | |
| #chat-container { | |
| flex: 1; | |
| overflow-y: auto; | |
| background-color: white; | |
| border-radius: 10px; | |
| padding: 2%; | |
| box-shadow: 0 0 10px rgba(0,0,0,0.1); | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .chat-bubble { | |
| margin: 5px; | |
| padding: 10px; | |
| border-radius: 10px; | |
| max-width: 80%; | |
| } | |
| .user-bubble { | |
| align-self: flex-end; | |
| background-color: #e0e0e0; | |
| } | |
| .bot-bubble { | |
| align-self: flex-start; | |
| background-color: #ffb6c1; | |
| color: white; | |
| } | |
| #input-container { | |
| display: flex; | |
| align-items: center; | |
| padding-bottom: 2%; | |
| } | |
| #input-container input { | |
| flex: 1; | |
| padding: 10px; | |
| border: 1px solid #ccc; | |
| border-radius: 5px; | |
| height: 2.5vh; | |
| } | |
| #input-container button { | |
| padding: 0; | |
| margin-left: 10px; | |
| border: none; | |
| background-color: transparent; | |
| cursor: pointer; | |
| height: calc(2.5vh + 15px); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| } | |
| #input-container button img { | |
| height: 100%; | |
| width: auto; | |
| } | |
| /* New styles for the menu */ | |
| .menu { | |
| position: absolute; | |
| top: 10px; | |
| left: 10px; | |
| z-index: 1000; | |
| } | |
| .menu .hamburger { | |
| display: block; | |
| cursor: pointer; | |
| width: 30px; | |
| height: 30px; | |
| } | |
| .menu .hamburger div { | |
| width: 100%; | |
| height: 4px; | |
| background-color: black; | |
| margin: 5px 0; | |
| transition: all 0.3s; | |
| } | |
| .menu-content { | |
| display: none; | |
| position: absolute; | |
| top: 40px; | |
| left: 0; | |
| background-color: white; | |
| box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | |
| border-radius: 5px; | |
| overflow: hidden; | |
| width: 150px; | |
| } | |
| .menu-content a { | |
| display: block; | |
| padding: 5px 10px; | |
| color: black; | |
| text-decoration: none; | |
| transition: background-color 0.3s; | |
| } | |
| .menu-content a:hover { | |
| background-color: #f0f0f0; | |
| } | |
| #audio-recording-container { | |
| display: none; | |
| align-items: center; | |
| justify-content: center; | |
| width: 90%; | |
| max-width: 1200px; | |
| margin: 10px; | |
| padding-top: 7%; | |
| } | |
| #audio-record-button { | |
| width: 150px; | |
| height: 150px; | |
| background-color: #e1fceb; | |
| color: black; | |
| border-radius: 50%; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 16px; | |
| font-weight: bold; | |
| border: 5px solid white; | |
| box-shadow: 0 0 20px 5px rgba(255, 255, 255, 0.8); | |
| } | |
| #audio-record-button.recording { | |
| background-color: #f44336; | |
| box-shadow: 0 0 20px 10px rgba(255, 255, 255, 1); | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="menu"> | |
| <div class="hamburger" onclick="toggleMenu()"> | |
| <div></div> | |
| <div></div> | |
| <div></div> | |
| </div> | |
| <div class="menu-content" id="menu-content"> | |
| <a href="#" onclick="showTextChat()">Text Chat</a> | |
| <a href="#" onclick="showAudioChat()">Audio Chat</a> | |
| <a href="#">Settings</a> | |
| </div> | |
| </div> | |
| <div id="video-container"> | |
| <video src="https://cdn-lfs-us-1.huggingface.co/repos/61/c4/61c4367976a0aef9d7ba3bb5650c0efc98207f17f6d3a4a71d3d7f9b265578a3/159ba43daee671b34e01d65c7b753bac22c139f653eeeaf3c6da1220b7c9ecf0?response-content-disposition=inline%3B+filename*%3DUTF-8%27%27lucy-vid-1.mp4%3B+filename%3D%22lucy-vid-1.mp4%22%3B&response-content-type=video%2Fmp4&Expires=1723399367&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTcyMzM5OTM2N319LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy11cy0xLmh1Z2dpbmdmYWNlLmNvL3JlcG9zLzYxL2M0LzYxYzQzNjc5NzZhMGFlZjlkN2JhM2JiNTY1MGMwZWZjOTgyMDdmMTdmNmQzYTRhNzFkM2Q3ZjliMjY1NTc4YTMvMTU5YmE0M2RhZWU2NzFiMzRlMDFkNjVjN2I3NTNiYWMyMmMxMzlmNjUzZWVlYWYzYzZkYTEyMjBiN2M5ZWNmMD9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSomcmVzcG9uc2UtY29udGVudC10eXBlPSoifV19&Signature=PqaCnSHH9xJ%7E-TgkrZ0mH96bbPf7IJBnJWZHYqNU4hFKRa0N9ibxdFm5HAWySMOCNrVGMVTzGjTWAX8gmcQNfHtDRL%7EfX%7El8zZpP2tErEm4Q8AmjhmYTWDATBG0pXCJQtaSjesQK3q9RQ2yMEiJDC9VWa2OhiBJW25LnL%7EAqPLiNpX8sRs07boI677XDmgRL7qOWEOtrBqvJn5ZCgaLybRhu8ySKvCSUwWtEv1gWQ-XT28NZ6h4nDy5yEqkMw9yVcJs4U8JUCHL2cxgHxGK22FK1o3EMiZ3LvMjzWZNVlLUbJJVFO4XDNqMsumV6oLEmWNZtILyEaD6FfGw6grLJNw__&Key-Pair-Id=K24J24Z295AEI9" playsinline autoplay loop muted></video> | |
| </div> | |
| <div id="chat-container"></div> | |
| <div id="input-container"> | |
| <input type="text" id="user-input" placeholder="Type your message..."> | |
| <button onclick="sendMessage()"> | |
| <img src="https://cdn-uploads.huggingface.co/production/uploads/648a824a8ca6cf9857d1349c/aJO71FyXi40-U_AOjwPmt.png" alt="Send"> | |
| </button> | |
| </div> | |
| <div id="audio-recording-container"> | |
| <button id="audio-record-button">START</button> | |
| </div> | |
| <script> | |
| function sendMessage() { | |
| var userInput = document.getElementById('user-input').value; | |
| if (userInput.trim() === "") return; | |
| var chatContainer = document.getElementById('chat-container'); | |
| // Create user bubble | |
| var userBubble = document.createElement('div'); | |
| userBubble.textContent = userInput; | |
| userBubble.className = 'chat-bubble user-bubble'; | |
| chatContainer.appendChild(userBubble); | |
| // Create bot bubble with "..." text | |
| var botBubble = document.createElement('div'); | |
| botBubble.textContent = ". . ."; | |
| botBubble.className = 'chat-bubble bot-bubble'; | |
| chatContainer.appendChild(botBubble); | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| document.getElementById('user-input').value = ''; | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('POST', '/send_message', true); | |
| xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
| xhr.onload = function () { | |
| if (xhr.status === 200) { | |
| var response = JSON.parse(xhr.responseText); | |
| // Update bot bubble with the actual response | |
| botBubble.textContent = response.response; | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| } | |
| }; | |
| xhr.send('user_input=' + encodeURIComponent(userInput)); | |
| } | |
| document.getElementById('user-input').addEventListener('keydown', function(event) { | |
| if (event.key === 'Enter') { | |
| sendMessage(); | |
| } | |
| }); | |
| function toggleMenu() { | |
| var menuContent = document.getElementById('menu-content'); | |
| if (menuContent.style.display === 'block') { | |
| menuContent.style.display = 'none'; | |
| } else { | |
| menuContent.style.display = 'block'; | |
| } | |
| } | |
| function showTextChat() { | |
| document.getElementById('chat-container').style.display = 'flex'; | |
| document.getElementById('input-container').style.display = 'flex'; | |
| document.getElementById('audio-recording-container').style.display = 'none'; | |
| document.getElementById('menu-content').style.display = 'none'; | |
| } | |
| function showAudioChat() { | |
| document.getElementById('chat-container').style.display = 'none'; | |
| document.getElementById('input-container').style.display = 'none'; | |
| document.getElementById('audio-recording-container').style.display = 'flex'; | |
| document.getElementById('menu-content').style.display = 'none'; | |
| } | |
| let mediaRecorder; | |
| let audioChunks = []; | |
| const recordButton = document.getElementById('audio-record-button'); | |
| let isRecording = false; | |
| recordButton.addEventListener('click', () => { | |
| if (isRecording) { | |
| mediaRecorder.stop(); | |
| recordButton.textContent = 'START'; | |
| recordButton.classList.remove('recording'); | |
| } else { | |
| navigator.mediaDevices.getUserMedia({ audio: true }) | |
| .then(stream => { | |
| mediaRecorder = new MediaRecorder(stream); | |
| mediaRecorder.start(); | |
| mediaRecorder.addEventListener('dataavailable', event => { | |
| audioChunks.push(event.data); | |
| }); | |
| mediaRecorder.addEventListener('stop', () => { | |
| const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); | |
| const formData = new FormData(); | |
| formData.append('file', audioBlob, 'audio.wav'); | |
| fetch('/upload', { | |
| method: 'POST', | |
| body: formData | |
| }) | |
| .then(response => response.json()) | |
| .catch(error => { | |
| console.error('Error:', error); | |
| }); | |
| audioChunks = []; | |
| }); | |
| recordButton.textContent = 'STOP'; | |
| recordButton.classList.add('recording'); | |
| }); | |
| } | |
| isRecording = !isRecording; | |
| }); | |
| </script> | |
| </body> | |
| </html> | |