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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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html lang="en" class="has-navbar-fixed-top has-navbar-fixed-bottom">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.4/css/bulma.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css">
 <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <title>914IA</title>
    

    <style>




   /* Loading Animation Styles */
   .loader {
            border: 8px solid #f3f3f3; /* Light grey */
            border-top: 8px solid #3498db; /* Blue */
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 1000; /* Ensure it is on top of other content */
            display: none; /* Hidden by default */
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .textarea {
            field-sizing: content;
            max-width: 25rem;
            max-height: 25rem;
            display: flex;
            align-items: center; /* Centers items vertically */
            justify-content: center; /* Centers items horizontally */

           resize: none;
           border: none;
           outline: none;
           box-shadow: none; 
           overflow: hidden;  /* Hide scrollbar  */
           height: min-content;
           min-height: 0.1rem;
           min-width: 0.5rem; /*makes the buttons get inside the container*/
           margin: none; /* Remove margin */
           flex-direction: row; /* Aligns children in a row */
       
           
            
            
        }
        .textarea-container {
            display: flex;
            align-items: center; /* Aligns items vertically in the center */
            justify-content: center; /* Centers items horizontally */
            border: 5px solid #dbdbdb;
            border-radius: 20px;
            padding: 0.5rem;
            background-color: white;
            width: 30rem; /* Adjust width as needed */
            flex-direction: row; /* Aligns children in a row */
        }


        .buttons-container {
            display: flex; /* Aligns buttons horizontally */
        }

        .icon-button {
            background: none;
            border: none;
            cursor: pointer;
            margin-left: 0.5rem; /* Space between buttons */
        }


            
            
        .custom-margin {
        margin-left: 10px; /* Adjust as needed */
        margin-right: 10px; /* Adjust as needed */
        }
        .no-border {
            border: none!important;
            outline: none!important;
        }
        button:active, button:focus {
        outline: none!important;
        box-shadow: none!important;
        }
        .card-footer {
        border-top: none!important;
        }
        .centered-input {
             display: flex;
             justify-content: center;
             width: 100%;
         }
        .centered-input-container {
               display: flex;
               justify-content: center;
               align-items: center;
               width: 100%;
               padding: 10px 0;
               
           }
        .input-with-icons {
               display: flex;
               align-items: center;
               width: 100%;
               max-width: 600px;
               margin: auto;
               border: 3px solid #000000; /* Match Bulma's default input border */
               border-radius: 20px; /* Rounded corners */
               overflow: hidden; /* Ensures rounded corners encompass the whole component */
               background-color: #fff; /* Background color matching Bulma's input */
           }
        .input-with-icons input {
               flex-grow: 1;
               border: none;
               box-shadow: none;
               outline: none;
               padding-left: 5px;
               transition: background-color 0.3s; /* Smooth transition for focus effect */
           }
   
        .icon-button {
               background-color: transparent;
               border: none;
               cursor: pointer;
               padding: 0 10px;
           }
      
            .input-with-icons input {
            flex-grow: 1;
            border: none; /* Removes input border */
            outline: none; /* Removes focus outline */
            box-shadow: none; /* Removes box-shadow */
            padding-left: 5px;
            background-color: inherit; /* Matches container background */
        }
         
        .input-with-icons input:focus {
            outline: none; /* Removes the outline */
            box-shadow: none; /* Removes any box-shadow */
            border: none; /* Ensures no border appears */
        }
        .card {
        border-radius: 20px; /* Adjusts the roundness of the corners */
        }
      
                :root {
        --bulma-scheme-main: #fff;
        /* Define other light mode variables */
        }

        :root.dark {
        --bulma-scheme-main: #000;
        /* Define other dark mode variables */
        }
                

    </style>
</head>
<body >

<!-- Fixed Menu and Title -->
<nav class="navbar is-fixed-top" style="margin: 0.5rem;" role="navigation" aria-label="main navigation">
    <div class="navbar-brand" >
        <!-- Hamburger Menu on the Left -->
        <a role="button" class="navbar-burger ml-0 burger" aria-label="menu" aria-expanded="false" onclick="toggleMenu()">
            <span aria-hidden="true"></span>
            <span aria-hidden="true"></span>
            <span aria-hidden="true"></span>
        </a>
        
     <!-- Brand Title -->
        <span class="navbar-item">
             914IA
        </span>
    </div>

    <!-- Navigation Menu Items -->
    <div id="navbarBasicExample" class="navbar-menu">
        <div class="navbar-start">
            <a class="navbar-item">Home</a>
            <!-- <a class="navbar-item">Documentation</a>
            <a class="navbar-item">Examples</a> -->
        </div>
    </div>
</nav>


<!-- End of Fixed Menu and Title -->





<!-- Main Content -->
<div class="container px-4" style="padding-top: 60px; padding-bottom: 50px; min-width: 3rem;  margin-bottom: 3rem;">
    <!-- List of Messages -->
    <div id="messageList" class="columns is-multiline">
        <div class="column is-full">
            
            
            
                    <!-- message -->
                    <div class="card">
                        <div class="card-content mb-3 ">
                            <h2 class="title is-4">This is a scaled down version of efexzium. </h2>
                            <p>If you want the full powerful AI chat PDF solutions please contact john@efexzium.com we will repply 24/7 we are here to help you. </p>
                            
                            <br>
                            <p><b>John@efexzium.com</b> - <i>CEO of efexzium</i></p>
                            <br>
                         
                            <footer class="card-footer">
                                <div style="display: flex; align-items: center;">
                                    <!-- Clipboard Icon -->
                                    <button class="button is-small no-border no-outline mr-2">
                                        <span class="icon is-small">
                                            <i class="fas fa-clipboard"></i>
                                        </span>
                                    </button>
                                    <!-- Like Icon -->
                                    <button class="button is-small no-border no-outline mr-2">
                                        <span class="icon is-small">
                                            <i class="fas fa-thumbs-up"></i>
                                        </span>
                                    </button>
                                    <!-- Dislike Icon -->
                                    <button class="button is-small no-border no-outline">
                                        <span class="icon is-small">
                                            <i class="fas fa-thumbs-down"></i>
                                        </span>
                                    </button>
                                </div>
                            </footer>
                        </div>
                    </div>

                       
        </div>
    </div>
</div>

<div class="loader" id="loadingSpinner" class="columns"></div>
<div style="display: flex; flex-direction: column;">

    <!-- Fixed Footer with Auto-Growing Textarea and Buttons -->
    <nav class="column is-half is-offset-by-three-quarters is-flex is-justify-content-center is-align-items-center   is-fixed-bottom columns is-vcentered" style="display: flex; background-color: transparent;  justify-content: center; align-items: center;  bottom: 0; "  >
        <div class="container px-4 centered-input-container"  >
            <div class="field" >
                <div class="textarea-container" style="width: fit-content; justify-content: center;" >
                    <!-- oninput="autoResize(this)" -->
    
                    <textarea class="textarea"  id="messageInput" placeholder="Type a message..." oninput="autoResize(this)" rows="1" style="min-width: 0.5rem !important; width: 60vw !important; min-height: 1rem;" ></textarea>
                    <div class="buttons-container">
                        <!-- Upload Icon Button -->
                        <input type="file" id="fileInput" style="display:none;" />
                        <button class="icon-button" onclick="triggerFileInput()">
                            <i class="fas fa-upload"></i>
                        </button>
                        
                        <!-- Send Message Icon Button -->
                        <button id="sendMessageButton" class="icon-button">
                            <i class="fas fa-paper-plane"></i>
                        </button>
                    </div>
                </div>
                
            </div>
        </div>
    </nav>
</div>


<script>
    function triggerFileInput() {
    // Get the file input element
    var fileInput = document.getElementById('fileInput');

    // Trigger the click event on the file input
    fileInput.click();
}

// Listen for changes on the file input
document.getElementById('fileInput').onchange = function(e) {
    var file = e.target.files[0];
    console.log(file); // Do something with the selected file here
};
let messages = []; // Array to hold messages
function showLoader() {
            document.getElementById('loadingSpinner').style.display = 'block';
        }

        function hideLoader() {
            document.getElementById('loadingSpinner').style.display = 'none';
        }
// Add event listener to the Send Message button
document.getElementById('sendMessageButton').addEventListener('click', sendMessage);

function renderMessages() {
    const messageList = document.getElementById('messageList');
    messageList.innerHTML = ''; // Clear existing messages
    messages.forEach((msg) => {
        const messageCard = document.createElement('div');
        messageCard.className = 'column is-full';
        messageCard.innerHTML = `
            <div class="card">
                <div class="card-content mb-3">
                    <h2 class="title is-4">${msg.role === 'user' ? 'You' : 'AI'}</h2>
                    <div class="content">${marked.parse(msg.content)}</div>
                </div>
            </div>
        `;
        messageList.appendChild(messageCard);
    });
}

function sendMessage() {
    var textarea = document.getElementById('messageInput');
    var messageContent = textarea.value;

    if (!messageContent.trim()) return; // Avoid sending empty messages

    showLoader(); // Show loader

    // Add user message to messages array
    messages.push({ role: 'user', content: messageContent });
    renderMessages(); // Update the message list UI

    var xhr = new XMLHttpRequest();
    var url = "https://openrouter.ai/api/v1/chat/completions";

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Authorization", "Bearer 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");
    xhr.setRequestHeader("HTTP-Referer", "YOUR_SITE_URL"); // Optional
    xhr.setRequestHeader("X-Title", "YOUR_SITE_NAME"); // Optional
    xhr.setRequestHeader("Content-Type", "application/json");

    var data = JSON.stringify({
        "model": "meta-llama/llama-3.1-8b-instruct:free",
        "messages": messages // Send all messages
    });

    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) { // Request is complete
            hideLoader(); // Hide loader when done

            if (xhr.status === 200) { // Success
                const response = JSON.parse(xhr.responseText);
                const aiMessage = response.choices[0].message.content; // Adjust this based on your API response

                // Add AI response to messages array
                messages.push({ role: 'ai', content: aiMessage });
                renderMessages(); // Update the message list UI

                textarea.value = ''; // Clear the textarea after sending
                autoResize(textarea); // Adjust textarea height
            } else {
                // Handle errors
                const errorResponse = JSON.parse(xhr.responseText);
                const errorMessage = errorResponse.error ? errorResponse.error.message : "An unexpected error occurred";

                // Add error message to messages array
                messages.push({ role: 'error', content: errorMessage });
                renderMessages(); // Update the message list UI
                hideLoader(); // Hide loader when done
                console.error("Error:", xhr.status, xhr.statusText, errorMessage);
            }
        }
    };

    xhr.send(data);
}



function toggleMenu() {
    var navbar = document.getElementById('navbarBasicExample');
    navbar.classList.toggle('is-active');    
}

function autoResize(textarea) {
    const measureDiv = document.querySelector('.textarea-measure');
    measureDiv.innerText = textarea.value + '\n'; // Add content to the measure div
    textarea.style.height = 'auto'; // Reset height to auto
    textarea.style.height = measureDiv.offsetHeight + 'px'; // Set textarea height to match measure div
}

// Initialize textarea height on page load
window.onload = function() {
    const textarea = document.querySelector('.textarea');
    autoResize(textarea); // Adjust based on content
    textarea.addEventListener('input', () => autoResize(textarea)); // Adjust on input
};



</script>

</body>
</html>