kimhyunwoo commited on
Commit
b352433
·
verified ·
1 Parent(s): 8e1842a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +46 -46
index.html CHANGED
@@ -3,70 +3,70 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Gemma 3 Chatbot</title>
7
  <style>
 
8
  body {
9
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* More modern font */
10
  display: flex;
11
  flex-direction: column;
12
  align-items: center;
13
  justify-content: center;
14
  min-height: 100vh;
15
  margin: 0;
16
- background-color: #f4f7f6; /* Light, neutral background */
17
  }
18
 
19
  h1 {
20
- color: #333; /* Darker heading color */
21
  margin-bottom: 0.5em;
22
  }
23
 
24
  #chat-container {
25
- width: 90%; /* Responsive width */
26
- max-width: 700px; /* Max width for larger screens */
27
- border: none; /* Remove border */
28
- padding: 25px; /* More padding */
29
- border-radius: 15px; /* Rounded corners */
30
  background-color: #fff;
31
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Subtle shadow */
32
- overflow: hidden; /* Hide overflowing content */
33
  }
34
 
35
  #chat-messages {
36
- height: 400px; /* Taller message area */
37
  overflow-y: auto;
38
  margin-bottom: 15px;
39
  padding: 15px;
40
- border: 1px solid #e0e0e0; /* Lighter border */
41
  border-radius: 10px;
42
- background-color: #fafafa; /* Very light gray background */
43
  }
44
 
45
  .message {
46
  margin-bottom: 10px;
47
  padding: 12px;
48
- border-radius: 20px; /* More rounded messages */
49
- max-width: 70%; /* Limit message width */
50
- word-wrap: break-word; /* Wrap long words */
51
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
52
  }
53
- /* User message styling */
54
  .user-message {
55
- background-color: #d4e5ff; /* Light blue */
56
  color: #000;
57
  text-align: right;
58
  align-self: flex-end;
59
- margin-left: auto; /* Push to the right */
60
- margin-right: 10px; /* Consistent margin */
61
  }
62
 
63
- /* Bot message styling */
64
  .bot-message {
65
- background-color: #e5e5ea; /* Light grey */
66
  color: #000;
67
  text-align: left;
68
  align-self: flex-start;
69
- margin-right: auto; /* Push to the left */
70
  margin-left: 10px;
71
  }
72
 
@@ -81,20 +81,19 @@
81
  flex-grow: 1;
82
  padding: 12px;
83
  border: 1px solid #ccc;
84
- border-radius: 20px; /* Rounded input field */
85
- font-size: 16px; /* Larger font size */
86
- outline: none; /* Remove default outline */
87
- transition: border-color 0.2s ease-in-out; /* Smooth transition */
88
  }
89
 
90
  #user-input:focus {
91
- border-color: #007bff; /* Highlight on focus */
92
  }
93
 
94
-
95
  #send-button {
96
  padding: 12px 25px;
97
- background-color: #007bff; /* Blue button */
98
  color: white;
99
  border: none;
100
  border-radius: 20px;
@@ -104,7 +103,7 @@
104
  }
105
 
106
  #send-button:hover {
107
- background-color: #0056b3; /* Darker blue on hover */
108
  }
109
 
110
  #send-button:disabled {
@@ -113,21 +112,20 @@
113
  }
114
 
115
  #loading-indicator {
116
- display: none; /* Hidden by default */
117
  margin-top: 15px;
118
  text-align: center;
119
  color: #888;
120
  font-style: italic;
121
  }
122
 
123
- .system-message{
124
  display: none;
125
  }
126
-
127
  </style>
128
  </head>
129
  <body>
130
- <h1>Gemma 3 Chatbot</h1>
131
 
132
  <div id="chat-container">
133
  <div id="chat-messages">
@@ -148,18 +146,19 @@
148
  const sendButton = document.getElementById('send-button');
149
  const loadingIndicator = document.getElementById('loading-indicator');
150
 
151
- let chatHistory = [
152
- { role: "system", content: "You are a helpful assistant." },
153
- ];
154
 
155
  let generator;
156
 
157
  async function initializePipeline() {
158
  loadingIndicator.style.display = 'block';
159
  try {
 
160
  generator = await pipeline(
161
  "text-generation",
162
- "onnx-community/gemma-3-1b-it-ONNX",
163
  { dtype: "q4" }
164
  );
165
  } catch (error) {
@@ -170,7 +169,7 @@
170
  return;
171
  }
172
  loadingIndicator.style.display = 'none';
173
- addMessage("bot", "Hello! I'm ready to chat. Ask me anything!"); // More welcoming message
174
  }
175
 
176
  initializePipeline();
@@ -182,9 +181,9 @@
182
  chatMessagesDiv.appendChild(messageDiv);
183
  chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
184
 
185
- if (role === 'user' || role === 'assistant') {
186
- chatHistory.push({ role: role, content: content });
187
- }
188
  }
189
 
190
  async function sendMessage() {
@@ -197,11 +196,12 @@
197
  sendButton.disabled = true;
198
 
199
  try {
200
- const output = await generator(chatHistory, {
201
  max_new_tokens: 512,
202
- do_sample: false // Consider setting to true for more varied responses.
203
  });
204
 
 
205
  const botResponse = output[0].generated_text.at(-1).content;
206
  addMessage('assistant', botResponse);
207
 
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Gemma Chatbot</title>
7
  <style>
8
+ /* (Same CSS as in the previous, well-styled response) */
9
  body {
10
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
  display: flex;
12
  flex-direction: column;
13
  align-items: center;
14
  justify-content: center;
15
  min-height: 100vh;
16
  margin: 0;
17
+ background-color: #f4f7f6;
18
  }
19
 
20
  h1 {
21
+ color: #333;
22
  margin-bottom: 0.5em;
23
  }
24
 
25
  #chat-container {
26
+ width: 90%;
27
+ max-width: 700px;
28
+ border: none;
29
+ padding: 25px;
30
+ border-radius: 15px;
31
  background-color: #fff;
32
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
33
+ overflow: hidden;
34
  }
35
 
36
  #chat-messages {
37
+ height: 400px;
38
  overflow-y: auto;
39
  margin-bottom: 15px;
40
  padding: 15px;
41
+ border: 1px solid #e0e0e0;
42
  border-radius: 10px;
43
+ background-color: #fafafa;
44
  }
45
 
46
  .message {
47
  margin-bottom: 10px;
48
  padding: 12px;
49
+ border-radius: 20px;
50
+ max-width: 70%;
51
+ word-wrap: break-word;
52
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
53
  }
54
+
55
  .user-message {
56
+ background-color: #d4e5ff;
57
  color: #000;
58
  text-align: right;
59
  align-self: flex-end;
60
+ margin-left: auto;
61
+ margin-right: 10px;
62
  }
63
 
 
64
  .bot-message {
65
+ background-color: #e5e5ea;
66
  color: #000;
67
  text-align: left;
68
  align-self: flex-start;
69
+ margin-right: auto;
70
  margin-left: 10px;
71
  }
72
 
 
81
  flex-grow: 1;
82
  padding: 12px;
83
  border: 1px solid #ccc;
84
+ border-radius: 20px;
85
+ font-size: 16px;
86
+ outline: none;
87
+ transition: border-color 0.2s ease-in-out;
88
  }
89
 
90
  #user-input:focus {
91
+ border-color: #007bff;
92
  }
93
 
 
94
  #send-button {
95
  padding: 12px 25px;
96
+ background-color: #007bff;
97
  color: white;
98
  border: none;
99
  border-radius: 20px;
 
103
  }
104
 
105
  #send-button:hover {
106
+ background-color: #0056b3;
107
  }
108
 
109
  #send-button:disabled {
 
112
  }
113
 
114
  #loading-indicator {
115
+ display: none;
116
  margin-top: 15px;
117
  text-align: center;
118
  color: #888;
119
  font-style: italic;
120
  }
121
 
122
+ .system-message {
123
  display: none;
124
  }
 
125
  </style>
126
  </head>
127
  <body>
128
+ <h1>Gemma Chatbot</h1>
129
 
130
  <div id="chat-container">
131
  <div id="chat-messages">
 
146
  const sendButton = document.getElementById('send-button');
147
  const loadingIndicator = document.getElementById('loading-indicator');
148
 
149
+ let chatHistory = [
150
+ { role: "system", content: "You are a helpful assistant." },
151
+ ];
152
 
153
  let generator;
154
 
155
  async function initializePipeline() {
156
  loadingIndicator.style.display = 'block';
157
  try {
158
+ // Use the correct model name for text generation with Gemma.
159
  generator = await pipeline(
160
  "text-generation",
161
+ "Xenova/gemma-1b-it-quantized", // Corrected model name
162
  { dtype: "q4" }
163
  );
164
  } catch (error) {
 
169
  return;
170
  }
171
  loadingIndicator.style.display = 'none';
172
+ addMessage("bot", "Hello! I'm ready to chat. Ask me anything!");
173
  }
174
 
175
  initializePipeline();
 
181
  chatMessagesDiv.appendChild(messageDiv);
182
  chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
183
 
184
+ if (role === 'user' || role === 'assistant') {
185
+ chatHistory.push({ role: role, content: content });
186
+ }
187
  }
188
 
189
  async function sendMessage() {
 
196
  sendButton.disabled = true;
197
 
198
  try {
199
+ const output = await generator(chatHistory, {
200
  max_new_tokens: 512,
201
+ do_sample: false
202
  });
203
 
204
+ // Correctly access the last message in the generated text.
205
  const botResponse = output[0].generated_text.at(-1).content;
206
  addMessage('assistant', botResponse);
207