Spaces:
Running
Running
Update index.html
Browse files- index.html +108 -38
index.html
CHANGED
|
@@ -1,61 +1,131 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: Arial, sans-serif;
|
| 10 |
-
|
| 11 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
-
|
|
|
|
| 14 |
width: 80%;
|
| 15 |
-
|
| 16 |
-
margin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
padding: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
</style>
|
|
|
|
|
|
|
| 23 |
</head>
|
|
|
|
| 24 |
<body>
|
| 25 |
-
<
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
<script>
|
| 33 |
-
const
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
});
|
| 45 |
}
|
| 46 |
|
| 47 |
-
function
|
| 48 |
-
const
|
| 49 |
-
const
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
</script>
|
| 60 |
</body>
|
| 61 |
-
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>AI Chat App</title>
|
| 8 |
<style>
|
| 9 |
body {
|
| 10 |
font-family: Arial, sans-serif;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
display: flex;
|
| 14 |
+
justify-content: center;
|
| 15 |
+
align-items: center;
|
| 16 |
+
height: 100vh;
|
| 17 |
+
background-color: #f0f0f0;
|
| 18 |
+
flex-direction: column;
|
| 19 |
}
|
| 20 |
+
|
| 21 |
+
#chat-container {
|
| 22 |
width: 80%;
|
| 23 |
+
max-width: 600px;
|
| 24 |
+
margin: auto;
|
| 25 |
+
background: white;
|
| 26 |
+
border: 1px solid #ddd;
|
| 27 |
+
border-radius: 4px;
|
| 28 |
+
padding: 20px;
|
| 29 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
#messages {
|
| 33 |
+
height: 300px;
|
| 34 |
+
overflow-y: auto;
|
| 35 |
+
border-bottom: 1px solid #ddd;
|
| 36 |
+
margin-bottom: 20px;
|
| 37 |
+
padding: 10px;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.message {
|
| 41 |
+
padding: 5px;
|
| 42 |
+
margin: 5px 0;
|
| 43 |
+
border-radius: 4px;
|
| 44 |
+
background: #2c7aef;
|
| 45 |
+
color: white;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.user-message {
|
| 49 |
+
text-align: right;
|
| 50 |
+
background: #f9f9f9;
|
| 51 |
+
color: black;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.user-message .message {
|
| 55 |
+
background: #e0f7fa;
|
| 56 |
}
|
| 57 |
+
|
| 58 |
+
#chat-input {
|
| 59 |
+
display: flex;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
#chat-input input {
|
| 63 |
+
flex-grow: 1;
|
| 64 |
padding: 10px;
|
| 65 |
+
margin-right: 10px;
|
| 66 |
+
border: 1px solid #ddd;
|
| 67 |
+
border-radius: 4px;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
#chat-input button {
|
| 71 |
+
padding: 10px 20px;
|
| 72 |
+
background: #007bff;
|
| 73 |
+
color: white;
|
| 74 |
+
border: none;
|
| 75 |
+
border-radius: 4px;
|
| 76 |
+
cursor: pointer;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
#chat-input button:hover {
|
| 80 |
+
background: #0056b3;
|
| 81 |
}
|
| 82 |
</style>
|
| 83 |
+
<script src="https://js.puter.com/v2/"></script>
|
| 84 |
+
|
| 85 |
</head>
|
| 86 |
+
|
| 87 |
<body>
|
| 88 |
+
<div id="chat-container">
|
| 89 |
+
<div id="messages"></div>
|
| 90 |
+
<div id="chat-input">
|
| 91 |
+
<input type="text" id="input-message" placeholder="Type a message...">
|
| 92 |
+
<button onclick="sendMessage()">Send</button>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
<p>Created using Puter.JS</p>
|
| 96 |
|
| 97 |
<script>
|
| 98 |
+
const messages = [];
|
| 99 |
+
function addMessage(msg, isUser) {
|
| 100 |
+
const messagesDiv = document.getElementById("messages");
|
| 101 |
+
const messageDiv = document.createElement("div");
|
| 102 |
+
messageDiv.classList.add("message");
|
| 103 |
+
if (isUser) {
|
| 104 |
+
messageDiv.classList.add("user-message");
|
| 105 |
+
}
|
| 106 |
+
messageDiv.textContent = msg;
|
| 107 |
+
messagesDiv.appendChild(messageDiv);
|
| 108 |
+
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
|
|
|
| 109 |
}
|
| 110 |
|
| 111 |
+
function sendMessage() {
|
| 112 |
+
const input = document.getElementById("input-message");
|
| 113 |
+
const message = input.value.trim();
|
| 114 |
+
if (message) {
|
| 115 |
+
addMessage(message, true);
|
| 116 |
+
input.value = '';
|
| 117 |
+
// Record the message in array of messages
|
| 118 |
+
messages.push({ content: message, role: 'user' });
|
| 119 |
+
// Call the AI chat function
|
| 120 |
+
puter.ai.chat(messages).then(response => {
|
| 121 |
+
addMessage(response, false);
|
| 122 |
+
messages.push(response.message);
|
| 123 |
+
}).catch(error => {
|
| 124 |
+
console.error("AI response error:", error);
|
| 125 |
+
});
|
| 126 |
+
}
|
| 127 |
}
|
| 128 |
</script>
|
| 129 |
</body>
|
| 130 |
+
|
| 131 |
+
</html>
|