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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
| 8 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap" rel="stylesheet">
|
| 11 |
+
<title>AI Chat Interface</title>
|
| 12 |
+
<style>
|
| 13 |
+
*{
|
| 14 |
+
padding: 0;
|
| 15 |
+
margin: 0;
|
| 16 |
+
font-family: 'Poppins', sans-serif;
|
| 17 |
+
box-sizing: border-box;
|
| 18 |
+
}
|
| 19 |
+
body {
|
| 20 |
+
overflow: hidden;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* Hide scrollbar only for Webkit browsers (Chrome, Safari, Opera) */
|
| 24 |
+
::-webkit-scrollbar {
|
| 25 |
+
display: none;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
body{
|
| 29 |
+
width: 100%;
|
| 30 |
+
height: 100vh;
|
| 31 |
+
background-color: #212121;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.chat{
|
| 35 |
+
display: flex;
|
| 36 |
+
gap: 20px;
|
| 37 |
+
padding: 25px;
|
| 38 |
+
color: #fff;
|
| 39 |
+
font-size: 15px;
|
| 40 |
+
font-weight: 300;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.chat img{
|
| 44 |
+
width: 35px;
|
| 45 |
+
height: 35px;
|
| 46 |
+
border-radius: 50px;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.response{
|
| 50 |
+
background-color: #212121;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.messagebar{
|
| 54 |
+
position: fixed;
|
| 55 |
+
bottom: 0;
|
| 56 |
+
height: 5rem;
|
| 57 |
+
width: 100%;
|
| 58 |
+
display: flex;
|
| 59 |
+
align-items: center;
|
| 60 |
+
justify-content: center;
|
| 61 |
+
background-color: #212121;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.messagebar .bar-wrapper{
|
| 65 |
+
background-color: #2f2f2f;
|
| 66 |
+
border-radius: 20px;
|
| 67 |
+
width: 70vw;
|
| 68 |
+
padding: 10px;
|
| 69 |
+
display: flex;
|
| 70 |
+
align-items: center;
|
| 71 |
+
justify-content: space-between;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.bar-wrapper input{
|
| 75 |
+
width: 100%;
|
| 76 |
+
padding: 5px;
|
| 77 |
+
border: none;
|
| 78 |
+
outline: none;
|
| 79 |
+
font-size: 14px;
|
| 80 |
+
background: none;
|
| 81 |
+
color: #ccc;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.bar-wrapper input::placeholder{
|
| 85 |
+
color: #ccc;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.messagebar button{
|
| 89 |
+
display: flex;
|
| 90 |
+
align-items: center;
|
| 91 |
+
justify-content: center;
|
| 92 |
+
background: none;
|
| 93 |
+
border: none;
|
| 94 |
+
color: #fff;
|
| 95 |
+
cursor: pointer;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.message-box{
|
| 99 |
+
height: calc(100vh - 5rem);
|
| 100 |
+
overflow-y: auto;
|
| 101 |
+
}
|
| 102 |
+
</style>
|
| 103 |
+
</head>
|
| 104 |
+
<body>
|
| 105 |
+
<div class="chatbox-wrapper">
|
| 106 |
+
<div class="message-box" id="chat-container">
|
| 107 |
+
<div class="chat response">
|
| 108 |
+
<img src="https://freelogopng.com/images/all_img/1681038800chatgpt-logo-black.png" alt="AI">
|
| 109 |
+
<span>こんにちは! <br>
|
| 110 |
+
どのようにお手伝いできますか?
|
| 111 |
+
</span>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
<div class="messagebar">
|
| 115 |
+
<div class="bar-wrapper">
|
| 116 |
+
<input type="text" id="user-input" placeholder="Enter your message...">
|
| 117 |
+
<button onclick="sendMessage()">
|
| 118 |
+
<span class="material-symbols-rounded">
|
| 119 |
+
send
|
| 120 |
+
</span>
|
| 121 |
+
</button>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<script>
|
| 127 |
+
const messageBar = document.querySelector("#user-input");
|
| 128 |
+
const sendBtn = document.querySelector(".bar-wrapper button");
|
| 129 |
+
const messageBox = document.querySelector("#chat-container");
|
| 130 |
+
|
| 131 |
+
function addMessage(message, isUser) {
|
| 132 |
+
const messageElement = document.createElement('div');
|
| 133 |
+
messageElement.classList.add('chat');
|
| 134 |
+
if (!isUser) messageElement.classList.add('response');
|
| 135 |
+
|
| 136 |
+
const imgElement = document.createElement('img');
|
| 137 |
+
imgElement.src = isUser ? "https://wallpaperaccess.com/full/1595920.jpg" : "https://freelogopng.com/images/all_img/1681038800chatgpt-logo-black.png";
|
| 138 |
+
imgElement.alt = isUser ? "User" : "AI";
|
| 139 |
+
|
| 140 |
+
const spanElement = document.createElement('span');
|
| 141 |
+
spanElement.textContent = message;
|
| 142 |
+
|
| 143 |
+
messageElement.appendChild(imgElement);
|
| 144 |
+
messageElement.appendChild(spanElement);
|
| 145 |
+
|
| 146 |
+
messageBox.appendChild(messageElement);
|
| 147 |
+
messageBox.scrollTop = messageBox.scrollHeight;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
function sendMessage() {
|
| 151 |
+
const message = messageBar.value.trim();
|
| 152 |
+
if (message) {
|
| 153 |
+
addMessage(message, true);
|
| 154 |
+
messageBar.value = '';
|
| 155 |
+
|
| 156 |
+
const eventSource = new EventSource(`/chat?message=${encodeURIComponent(message)}`);
|
| 157 |
+
let aiResponse = '';
|
| 158 |
+
|
| 159 |
+
eventSource.onmessage = function(event) {
|
| 160 |
+
if (event.data === '[DONE]') {
|
| 161 |
+
eventSource.close();
|
| 162 |
+
} else {
|
| 163 |
+
aiResponse += event.data;
|
| 164 |
+
const aiMessageElement = document.querySelector('.chat.response:last-child span');
|
| 165 |
+
if (aiMessageElement) {
|
| 166 |
+
aiMessageElement.textContent = aiResponse;
|
| 167 |
+
} else {
|
| 168 |
+
addMessage(aiResponse, false);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
};
|
| 172 |
+
|
| 173 |
+
eventSource.onerror = function(error) {
|
| 174 |
+
console.error('EventSource failed:', error);
|
| 175 |
+
eventSource.close();
|
| 176 |
+
};
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
messageBar.addEventListener('keypress', function(event) {
|
| 181 |
+
if (event.key === 'Enter') {
|
| 182 |
+
sendMessage();
|
| 183 |
+
}
|
| 184 |
+
});
|
| 185 |
+
</script>
|
| 186 |
+
</body>
|
| 187 |
+
</html>
|