abdullahalioo commited on
Commit
dd2acf7
·
verified ·
1 Parent(s): 458209e

Update index.html

Browse files
Files changed (1) hide show
  1. 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>Text to Speech</title>
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
- text-align: center;
11
- padding: 20px;
 
 
 
 
 
 
12
  }
13
- textarea {
 
14
  width: 80%;
15
- height: 100px;
16
- margin-bottom: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
- select, button {
19
- margin: 10px;
 
 
 
 
 
20
  padding: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
  </style>
 
 
23
  </head>
 
24
  <body>
25
- <h1>Text to Speech</h1>
26
- <textarea id="text" placeholder="Enter text to speak..."></textarea>
27
- <br>
28
- <select id="voiceSelect"></select>
29
- <br>
30
- <button onclick="speak()">Speak</button>
 
 
31
 
32
  <script>
33
- const synth = window.speechSynthesis;
34
- const voiceSelect = document.getElementById('voiceSelect');
35
-
36
- function loadVoices() {
37
- const voices = synth.getVoices();
38
- voiceSelect.innerHTML = '';
39
- voices.forEach(voice => {
40
- const option = document.createElement('option');
41
- option.value = voice.name;
42
- option.textContent = `${voice.name} (${voice.lang})`;
43
- voiceSelect.appendChild(option);
44
- });
45
  }
46
 
47
- function speak() {
48
- const text = document.getElementById('text').value;
49
- const utterance = new SpeechSynthesisUtterance(text);
50
- const selectedVoice = voiceSelect.value;
51
- utterance.voice = synth.getVoices().find(voice => voice.name === selectedVoice);
52
- synth.speak(utterance);
53
- }
54
-
55
- loadVoices();
56
- if (speechSynthesis.onvoiceschanged !== undefined) {
57
- speechSynthesis.onvoiceschanged = loadVoices;
 
 
 
 
 
58
  }
59
  </script>
60
  </body>
61
- </html>
 
 
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>