Zain437 commited on
Commit
5490769
·
verified ·
1 Parent(s): e50a7e7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +64 -19
index.html CHANGED
@@ -1,19 +1,64 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width" />
6
+ <title>AI Chat App</title>
7
+ <link rel="stylesheet" href="style.css" />
8
+ <script src="https://js.puter.com/v2/"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="chat-container">
13
+ <div id="messages"></div>
14
+ <div id="chat-input">
15
+ <input type="text" id="input-message" placeholder="Type a message..." />
16
+ <button id="send-btn">Send</button>
17
+ </div>
18
+ </div>
19
+
20
+ <p class="footer-text">Created using <strong>Puter.JS</strong></p>
21
+
22
+ <script>
23
+ const messages = [];
24
+ const messagesDiv = document.getElementById('messages');
25
+ const input = document.getElementById('input-message');
26
+ const sendBtn = document.getElementById('send-btn');
27
+
28
+ // Function to display messages
29
+ function addMessage(text, sender) {
30
+ const msg = document.createElement('div');
31
+ msg.classList.add('message', sender);
32
+ msg.textContent = text;
33
+ messagesDiv.appendChild(msg);
34
+ messagesDiv.scrollTop = messagesDiv.scrollHeight;
35
+ }
36
+
37
+ // Function to send message
38
+ async function sendMessage() {
39
+ const userText = input.value.trim();
40
+ if (!userText) return;
41
+
42
+ addMessage(userText, 'user');
43
+ messages.push({ role: 'user', content: userText });
44
+ input.value = '';
45
+
46
+ addMessage('Thinking...', 'ai');
47
+ try {
48
+ const response = await puter.ai.chat(messages);
49
+ const reply = response.message.content || "No response from AI.";
50
+ messages.push(response.message);
51
+ messagesDiv.lastChild.textContent = reply;
52
+ } catch (err) {
53
+ console.error(err);
54
+ messagesDiv.lastChild.textContent = "Error: Failed to get response.";
55
+ }
56
+ }
57
+
58
+ sendBtn.addEventListener('click', sendMessage);
59
+ input.addEventListener('keypress', e => {
60
+ if (e.key === 'Enter') sendMessage();
61
+ });
62
+ </script>
63
+ </body>
64
+ </html>