File size: 7,708 Bytes
ce11b44
1e2eab9
 
 
 
ce11b44
 
 
 
 
 
4ea3c92
ce11b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbc8183
 
 
 
 
 
 
 
 
 
 
94cc28f
 
ce11b44
 
94cc28f
 
ce11b44
 
 
94cc28f
 
 
 
ce11b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ea3c92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27a8072
 
 
 
 
 
ce11b44
1e2eab9
 
 
94cc28f
1e2eab9
 
 
 
 
 
 
 
 
 
 
 
 
ce11b44
4ea3c92
 
ce11b44
 
 
 
94cc28f
ce11b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ea3c92
ce11b44
 
 
 
 
 
 
 
 
 
94cc28f
 
 
 
 
4ea3c92
 
 
3fe3ba2
4ea3c92
 
 
 
ce11b44
 
1e2eab9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Emma's Genie</title>
    <style>
      body {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        min-height: 100vh;
        margin: 0;
        font-family: "Inter", system-ui, -apple-system, sans-serif;
        background: linear-gradient(135deg, #f6f8fb 0%, #e9eef5 100%);
      }

      .chat-container {
        width: 100%;
        max-width: 400px;
        border-radius: 16px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12),
          0 2px 8px rgba(0, 0, 0, 0.08);
        overflow: hidden;
        display: flex;
        flex-direction: column;
        background-color: white;
        height: 600px;
        transition: transform 0.2s ease;
      }

      .chat-container:hover {
        transform: translateY(-2px);
      }

      .messages {
        flex-grow: 1;
        padding: 20px;
        overflow-y: auto;
        background-color: #ffffff;
        scroll-behavior: smooth;
      }

      .messages::-webkit-scrollbar {
        width: 6px;
      }

      .messages::-webkit-scrollbar-thumb {
        background-color: #cbd5e1;
        border-radius: 3px;
      }

      .message {
        margin-bottom: 16px;
        max-width: 80%;
        padding: 12px 16px;
        border-radius: 12px;
        font-size: 14px;
        line-height: 1.5;
        animation: fadeIn 0.3s ease;
      }

      @keyframes fadeIn {
        from {
          opacity: 0;
          transform: translateY(10px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .message.user {
        margin-left: auto;
        background-color: #2563eb;
        color: white;
        border-bottom-right-radius: 4px;
      }

      .message.ai {
        background-color: #f3f4f6;
        color: #1f2937;
        border-bottom-left-radius: 4px;
      }

      .typing-indicator {
        margin-bottom: 16px;
        padding: 12px 16px;
        background-color: #f3f4f6;
        border-radius: 12px;
        border-bottom-left-radius: 4px;
        width: fit-content;
      }

      .typing-indicator span {
        display: inline-block;
        width: 8px;
        height: 8px;
        background-color: #94a3b8;
        border-radius: 50%;
        margin-right: 4px;
        animation: bounce 1.4s infinite ease-in-out;
      }

      .typing-indicator span:nth-child(1) {
        animation-delay: -0.32s;
      }
      .typing-indicator span:nth-child(2) {
        animation-delay: -0.16s;
      }
      .typing-indicator span:nth-child(3) {
        animation-delay: 0s;
      }

      @keyframes bounce {
        0%,
        80%,
        100% {
          transform: translateY(0);
        }
        40% {
          transform: translateY(-6px);
        }
      }

      @keyframes subtleBounce {
        0%, 100% {
          transform: translateY(0);
        }
        50% {
          transform: translateY(-1px);
        }
      }

      .subtle-bounce {
        animation: subtleBounce 0.1s ease;
      }

      #chat-form {
        display: flex;
        padding: 16px;
        gap: 8px;
        background-color: #fff;
        border-top: 1px solid #eef2f6;
      }

      #user-input {
        flex-grow: 1;
        padding: 12px 16px;
        border: 2px solid #e5e7eb;
        border-radius: 8px;
        font-size: 14px;
        transition: border-color 0.2s ease;
        outline: none;
      }

      #user-input:focus {
        border-color: #2563eb;
      }

      button {
        padding: 12px 24px;
        background-color: #2563eb;
        color: white;
        border: none;
        border-radius: 8px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
      }

      button:hover {
        background-color: #1d4ed8;
        transform: translateY(-1px);
      }

      button:active {
        transform: translateY(0);
      }

      #copy-iframe-btn {
        margin-top: 20px;
        cursor: pointer;
        color: #6b7280;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        transition: all 0.3s ease;
      }

      #copy-iframe-btn:hover {
        background-color: rgba(0, 0, 0, 0.1);
        color: #2563eb;
        padding: 4px;
        border-radius: 4px;
      }

      @media (width <= 300px) {
        .chat-container {
          border-radius: 16px;
        }
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="chat-container" id="chat-container">
        <div id="messages" class="messages"></div>
        <form id="chat-form">
          <input
            type="text"
            id="user-input"
            placeholder="Ask anything.."
            autocomplete="off"
            required
          />
          <button type="submit">Send</button>
        </form>
      </div>
    </div>

    <div id="copy-iframe-btn"><img src="https://cdn-icons-png.flaticon.com/512/10146/10146565.png" style="width: 21px; padding-right: 4px; filter: opacity(0.6);">Copy embed code</div>

    <script type="module">
      import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";

      document.addEventListener("DOMContentLoaded", async () => {
        const chatContainer = document.getElementById("chat-container");
        const messagesDiv = document.getElementById("messages");
        const chatForm = document.getElementById("chat-form");
        const userInput = document.getElementById("user-input");

        const client = await Client.connect("nroggendorff/not-my-emma");

        chatForm.addEventListener("submit", async (e) => {
          e.preventDefault();
          const userMessage = userInput.value;
          if (!userMessage) return;

          userInput.value = "";
          addMessage(userMessage, "user");

          const typingIndicator = document.createElement("div");
          typingIndicator.className = "typing-indicator";
          typingIndicator.innerHTML = `
            <span></span>
            <span></span>
            <span></span>
          `;
          messagesDiv.appendChild(typingIndicator);
          messagesDiv.scrollTop = messagesDiv.scrollHeight;

          try {
            const result = await client.predict("/chat", {
              message: userMessage,
            });

            typingIndicator.remove();
            addMessage(result.data, "ai");
          } catch (error) {
            typingIndicator.remove();
            addMessage("Sorry, I encountered an error. Please try again.", "ai");
          }
        });

        function addMessage(message, sender) {
          const messageElement = document.createElement("div");
          messageElement.classList.add("message", sender);
          messageElement.textContent = message;
          messagesDiv.appendChild(messageElement);
          messagesDiv.scrollTop = messagesDiv.scrollHeight;
        }

        userInput.addEventListener("input", () => {
          chatContainer.classList.add("subtle-bounce");
          setTimeout(() => chatContainer.classList.remove("subtle-bounce"), 100);
        });

        const copyButton = document.getElementById("copy-iframe-btn");
        copyButton.addEventListener("click", () => {
          const iframeCode = `<iframe src="https://emma.eduzs.link" width="300" height="600" frameborder="0" scrolling="no"></iframe>`;
          navigator.clipboard.writeText(iframeCode).then(() => {
            alert("Embed code copied to clipboard!");
          });
        });
      });
    </script>
  </body>
</html>