protae5544 commited on
Commit
06468f4
·
verified ·
1 Parent(s): ee2ad1a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +168 -130
index.html CHANGED
@@ -964,59 +964,54 @@ function solution() {
964
 
965
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
966
  <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
967
- <script>
968
  // Global variables
969
- let isLoading = false;
970
  let currentCarouselIndex = 0;
 
971
  let isDragging = false;
972
- let startX = 0;
973
 
974
  // Initialize the application
975
  document.addEventListener('DOMContentLoaded', function() {
976
  loadSettings();
977
  setupEventListeners();
978
- setupSimpleCarousel();
 
979
  hljs.highlightAll();
980
-
981
- // Dark mode detection
982
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
983
- document.documentElement.classList.add('dark');
984
- }
985
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
986
- if (event.matches) {
987
- document.documentElement.classList.add('dark');
988
- } else {
989
- document.documentElement.classList.remove('dark');
990
- }
991
- });
992
  });
993
 
994
  // Settings management
995
  function loadSettings() {
996
  const settings = {
997
- model: localStorage.getItem('selectedModel') || 'mistralai/Mistral-7B-Instruct-v0.1',
998
- apiKey: localStorage.getItem('apiKey') || '',
999
- maxTokens: localStorage.getItem('maxTokens') || '512',
1000
- primarySystemPrompt: localStorage.getItem('primarySystemPrompt') || 'You are a helpful AI assistant that provides clear, accurate, and helpful responses. Focus on practical solutions and detailed explanations.',
1001
- codeTemplate: localStorage.getItem('codeTemplate') || '```javascript\n// Code implementation\nfunction solution() {\n // Your code here\n return result;\n}\n```',
1002
- additionalInstructions: localStorage.getItem('additionalInstructions') || 'Provide working code examples when possible. Explain complex concepts step by step. Use modern best practices.'
 
 
1003
  };
1004
 
1005
  document.getElementById('modelSelect').value = settings.model;
1006
- document.getElementById('apiKeyInput').value = settings.apiKey;
1007
- document.getElementById('maxTokensInput').value = settings.maxTokens;
1008
  document.getElementById('primarySystemPrompt').value = settings.primarySystemPrompt;
 
1009
  document.getElementById('codeTemplate').value = settings.codeTemplate;
1010
  document.getElementById('additionalInstructions').value = settings.additionalInstructions;
 
 
1011
  }
1012
 
1013
  function saveSettings() {
1014
  localStorage.setItem('selectedModel', document.getElementById('modelSelect').value);
1015
- localStorage.setItem('apiKey', document.getElementById('apiKeyInput').value);
1016
- localStorage.setItem('maxTokens', document.getElementById('maxTokensInput').value);
1017
  localStorage.setItem('primarySystemPrompt', document.getElementById('primarySystemPrompt').value);
 
1018
  localStorage.setItem('codeTemplate', document.getElementById('codeTemplate').value);
1019
  localStorage.setItem('additionalInstructions', document.getElementById('additionalInstructions').value);
 
 
1020
  showNotification('Settings saved successfully!', 'success');
1021
  }
1022
 
@@ -1030,19 +1025,15 @@ function solution() {
1030
  document.getElementById('saveSettingsBtn').addEventListener('click', saveSettings);
1031
  document.getElementById('settingsToggle').addEventListener('click', toggleSettings);
1032
 
1033
- // Carousel controls - simple direct rotation
1034
- document.getElementById('prevCard').addEventListener('click', () => {
1035
- rotateCarousel(-1);
1036
- });
1037
-
1038
- document.getElementById('nextCard').addEventListener('click', () => {
1039
- rotateCarousel(1);
1040
- });
1041
-
1042
  document.getElementById('applyPromptBtn').addEventListener('click', applyPromptsAndSwitchToChat);
1043
 
1044
  // Chat controls
1045
  document.getElementById('sendButton').addEventListener('click', sendMessage);
 
 
1046
  document.getElementById('userInput').addEventListener('keydown', handleKeyDown);
1047
 
1048
  // Other controls
@@ -1058,7 +1049,7 @@ function solution() {
1058
  });
1059
  });
1060
 
1061
- // Carousel dots - simple direct navigation
1062
  document.querySelectorAll('.carousel-dot').forEach(dot => {
1063
  dot.addEventListener('click', (e) => {
1064
  const index = parseInt(e.target.getAttribute('data-index'));
@@ -1066,39 +1057,6 @@ function solution() {
1066
  });
1067
  });
1068
  }
1069
-
1070
- // Simple carousel functions with direct animations
1071
- function setupSimpleCarousel() {
1072
- // Initial setup
1073
- updateCarouselPosition();
1074
-
1075
- // Add touch handling for mobile/tablet
1076
- const carousel = document.getElementById('promptCarousel');
1077
-
1078
- // Touch events for swiping
1079
- carousel.addEventListener('touchstart', handleTouchStart, { passive: true });
1080
- carousel.addEventListener('touchend', handleTouchEnd, { passive: true });
1081
- }
1082
-
1083
- function handleTouchStart(e) {
1084
- startX = e.touches[0].clientX;
1085
- }
1086
-
1087
- function handleTouchEnd(e) {
1088
- const endX = e.changedTouches[0].clientX;
1089
- const diffX = endX - startX;
1090
-
1091
- // If swipe distance is significant, rotate carousel
1092
- if (Math.abs(diffX) > 50) {
1093
- if (diffX > 0) {
1094
- // Swipe right - go to previous card
1095
- rotateCarousel(-1);
1096
- } else {
1097
- // Swipe left - go to next card
1098
- rotateCarousel(1);
1099
- }
1100
- }
1101
- }
1102
 
1103
  // Mode switching
1104
  function switchMode(mode) {
@@ -1125,9 +1083,13 @@ function solution() {
1125
  }
1126
  }
1127
 
1128
- // Simplified carousel functionality
 
 
 
 
1129
  function rotateCarousel(direction) {
1130
- const totalCards = 3;
1131
  currentCarouselIndex = (currentCarouselIndex + direction + totalCards) % totalCards;
1132
  updateCarouselPosition();
1133
  }
@@ -1140,38 +1102,20 @@ function solution() {
1140
  function updateCarouselPosition() {
1141
  const carousel = document.getElementById('promptCarousel');
1142
  const cards = carousel.querySelectorAll('.carousel-card');
 
1143
 
1144
- // Update indicator dots
1145
- document.querySelectorAll('.carousel-dot').forEach((dot, index) => {
1146
- dot.classList.toggle('active', index === currentCarouselIndex);
1147
- });
1148
-
1149
- // Apply smooth transition
1150
- carousel.style.transition = 'transform 0.5s ease-out';
1151
-
1152
- // Apply new rotation
1153
- const newRotation = -currentCarouselIndex * 60;
1154
- carousel.style.transform = `rotateY(${newRotation}deg)`;
1155
-
1156
- // Update each card position
1157
  cards.forEach((card, index) => {
1158
  const angle = (index - currentCarouselIndex) * 60;
1159
  const isActive = index === currentCarouselIndex;
1160
 
1161
- // Add smooth transition to cards
1162
- card.style.transition = 'all 0.5s ease-out';
1163
  card.style.transform = `rotateY(${angle}deg) translateZ(500px)`;
1164
  card.style.opacity = isActive ? '1' : '0.6';
1165
  card.style.zIndex = isActive ? '10' : '1';
1166
  });
1167
-
1168
- // Remove transition after animation completes for better performance
1169
- setTimeout(() => {
1170
- carousel.style.transition = '';
1171
- cards.forEach(card => {
1172
- card.style.transition = '';
1173
- });
1174
- }, 500);
1175
  }
1176
 
1177
  function applyPromptsAndSwitchToChat() {
@@ -1180,6 +1124,58 @@ function solution() {
1180
  showNotification('Prompts applied successfully!', 'success');
1181
  }
1182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
  // Chat functionality
1184
  function handleKeyDown(e) {
1185
  if (e.key === 'Enter' && !e.shiftKey) {
@@ -1192,19 +1188,31 @@ function solution() {
1192
  const userInput = document.getElementById('userInput');
1193
  const message = userInput.value.trim();
1194
 
1195
- if (!message) return;
1196
  if (isLoading) return;
1197
 
1198
  const chatContainer = document.getElementById('chatContainer');
1199
 
1200
  // Add user message
1201
- addMessage(message, 'user');
 
 
 
 
 
 
 
 
 
 
 
 
1202
 
1203
  userInput.value = '';
1204
  setLoading(true);
1205
 
1206
  try {
1207
- const response = await callHuggingFaceAPI(message);
1208
  addMessage(response, 'ai');
1209
  } catch (error) {
1210
  console.error('Error:', error);
@@ -1212,44 +1220,57 @@ function solution() {
1212
  showNotification('Error: ' + error.message, 'error');
1213
  } finally {
1214
  setLoading(false);
 
 
1215
  }
1216
 
1217
  chatContainer.scrollTop = chatContainer.scrollHeight;
1218
  }
1219
 
1220
- async function callHuggingFaceAPI(message) {
1221
  const model = document.getElementById('modelSelect').value;
1222
- const apiKey = document.getElementById('apiKeyInput').value;
1223
- const maxTokens = parseInt(document.getElementById('maxTokensInput').value);
1224
  const primaryPrompt = document.getElementById('primarySystemPrompt').value;
 
 
1225
 
1226
- if (!apiKey) {
1227
- throw new Error('Please enter your HuggingFace API key in settings');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1228
  }
1229
 
1230
- const fullPrompt = `${primaryPrompt}\n\nUser: ${message}\n\nAssistant:`;
1231
-
1232
  const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {
1233
  method: 'POST',
1234
  headers: {
1235
- 'Authorization': `Bearer ${apiKey}`,
1236
  'Content-Type': 'application/json',
1237
  },
1238
  body: JSON.stringify({
1239
  inputs: fullPrompt,
1240
  parameters: {
1241
- max_new_tokens: maxTokens,
1242
  temperature: 0.7,
1243
  top_p: 0.9,
1244
- do_sample: true,
1245
- return_full_text: false
1246
  }
1247
  })
1248
  });
1249
 
1250
  if (!response.ok) {
1251
- const errorData = await response.json();
1252
- throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
1253
  }
1254
 
1255
  const data = await response.json();
@@ -1258,7 +1279,27 @@ function solution() {
1258
  throw new Error(data.error);
1259
  }
1260
 
1261
- return data[0]?.generated_text || 'No response generated';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1262
  }
1263
 
1264
  function addMessage(content, sender) {
@@ -1281,6 +1322,21 @@ function solution() {
1281
  chatContainer.scrollTop = chatContainer.scrollHeight;
1282
  }
1283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1284
  function addCodeTools(preElement) {
1285
  const toolsDiv = document.createElement('div');
1286
  toolsDiv.className = 'code-tools';
@@ -1348,22 +1404,4 @@ function solution() {
1348
  }
1349
  </script>
1350
  </body>
1351
- </html>
1352
- <select id="modelSelect">
1353
- <option value="Qwen/Qwen2.5-Coder-32B-Instruct">Qwen2.5-Coder 32B (Code/Text)</option>
1354
- <option value="Qwen/Qwen2-VL-72B-Instruct">Qwen2-VL 72B (Text/Image)</option>
1355
- <option value="microsoft/Florence-2-large">Florence-2 Large (Text/Image)</option>
1356
- <option value="mistralai/Mixtral-8x7B-Instruct-v0.1">Mixtral 8x7B (Text)</option>
1357
- <option value="meta-llama/Llama-2-70b-chat-hf">Llama-2 70B (Chat)</option>
1358
- </select>
1359
- <p style="font-size: 0.8rem; color: var(--text-secondary); margin-top: 8px;">
1360
- 💡 Choose a model. Use VL or Florence for image processing.
1361
- </p>
1362
- </div>
1363
- <div class="form-field">
1364
- <label>👁️ OCR Model (for images):</label>
1365
- <select id="ocrModelSelect">
1366
- <option value="none">None</option>
1367
- <option value="scb10x/typhoon-v1.5x-72b-instruct">Typhoon 1.5x 72B</option>
1368
- <option value="microsoft/trocr-base-printed">TrOCR Base</option>
1369
- </select>
 
964
 
965
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
966
  <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
967
+ <script>
968
  // Global variables
969
+ let attachedFiles = [];
970
  let currentCarouselIndex = 0;
971
+ let isLoading = false;
972
  let isDragging = false;
 
973
 
974
  // Initialize the application
975
  document.addEventListener('DOMContentLoaded', function() {
976
  loadSettings();
977
  setupEventListeners();
978
+ setupCarousel();
979
+ setupDropzone();
980
  hljs.highlightAll();
 
 
 
 
 
 
 
 
 
 
 
 
981
  });
982
 
983
  // Settings management
984
  function loadSettings() {
985
  const settings = {
986
+ model: localStorage.getItem('selectedModel') || 'Qwen/Qwen2.5-Coder-32B-Instruct',
987
+ ocrModel: localStorage.getItem('selectedOcrModel') || 'none',
988
+ primarySystemPrompt: localStorage.getItem('primarySystemPrompt') || 'You are a powerful AI assistant that excels at understanding code, images, and technical content. Provide clear, accurate, and helpful responses. Focus on practical solutions and detailed explanations.',
989
+ ocrSystemPrompt: localStorage.getItem('ocrSystemPrompt') || 'Extract all text from the provided image clearly and accurately. Preserve formatting, structure, and layout when possible. If text is unclear, indicate uncertain parts.',
990
+ codeTemplate: localStorage.getItem('codeTemplate') || '```javascript\n// Enhanced code implementation\nfunction solution() {\n // Your optimized code here\n return result;\n}\n```',
991
+ additionalInstructions: localStorage.getItem('additionalInstructions') || 'Always provide working, tested code examples. Include error handling and optimization suggestions. Explain complex concepts step by step. Use modern best practices.',
992
+ promptPrefix: localStorage.getItem('promptPrefix') || 'Please analyze the following request carefully and provide a comprehensive solution:',
993
+ promptSuffix: localStorage.getItem('promptSuffix') || 'Ensure your response is complete, accurate, and includes practical examples where applicable.'
994
  };
995
 
996
  document.getElementById('modelSelect').value = settings.model;
997
+ document.getElementById('ocrModelSelect').value = settings.ocrModel;
 
998
  document.getElementById('primarySystemPrompt').value = settings.primarySystemPrompt;
999
+ document.getElementById('ocrSystemPrompt').value = settings.ocrSystemPrompt;
1000
  document.getElementById('codeTemplate').value = settings.codeTemplate;
1001
  document.getElementById('additionalInstructions').value = settings.additionalInstructions;
1002
+ document.getElementById('promptPrefix').value = settings.promptPrefix;
1003
+ document.getElementById('promptSuffix').value = settings.promptSuffix;
1004
  }
1005
 
1006
  function saveSettings() {
1007
  localStorage.setItem('selectedModel', document.getElementById('modelSelect').value);
1008
+ localStorage.setItem('selectedOcrModel', document.getElementById('ocrModelSelect').value);
 
1009
  localStorage.setItem('primarySystemPrompt', document.getElementById('primarySystemPrompt').value);
1010
+ localStorage.setItem('ocrSystemPrompt', document.getElementById('ocrSystemPrompt').value);
1011
  localStorage.setItem('codeTemplate', document.getElementById('codeTemplate').value);
1012
  localStorage.setItem('additionalInstructions', document.getElementById('additionalInstructions').value);
1013
+ localStorage.setItem('promptPrefix', document.getElementById('promptPrefix').value);
1014
+ localStorage.setItem('promptSuffix', document.getElementById('promptSuffix').value);
1015
  showNotification('Settings saved successfully!', 'success');
1016
  }
1017
 
 
1025
  document.getElementById('saveSettingsBtn').addEventListener('click', saveSettings);
1026
  document.getElementById('settingsToggle').addEventListener('click', toggleSettings);
1027
 
1028
+ // Carousel controls
1029
+ document.getElementById('prevCard').addEventListener('click', () => rotateCarousel(-1));
1030
+ document.getElementById('nextCard').addEventListener('click', () => rotateCarousel(1));
 
 
 
 
 
 
1031
  document.getElementById('applyPromptBtn').addEventListener('click', applyPromptsAndSwitchToChat);
1032
 
1033
  // Chat controls
1034
  document.getElementById('sendButton').addEventListener('click', sendMessage);
1035
+ document.getElementById('attachButton').addEventListener('click', () => document.getElementById('fileInput').click());
1036
+ document.getElementById('fileInput').addEventListener('change', handleFileSelect);
1037
  document.getElementById('userInput').addEventListener('keydown', handleKeyDown);
1038
 
1039
  // Other controls
 
1049
  });
1050
  });
1051
 
1052
+ // Carousel dots
1053
  document.querySelectorAll('.carousel-dot').forEach(dot => {
1054
  dot.addEventListener('click', (e) => {
1055
  const index = parseInt(e.target.getAttribute('data-index'));
 
1057
  });
1058
  });
1059
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1060
 
1061
  // Mode switching
1062
  function switchMode(mode) {
 
1083
  }
1084
  }
1085
 
1086
+ // Carousel functionality
1087
+ function setupCarousel() {
1088
+ updateCarouselPosition();
1089
+ }
1090
+
1091
  function rotateCarousel(direction) {
1092
+ const totalCards = 6;
1093
  currentCarouselIndex = (currentCarouselIndex + direction + totalCards) % totalCards;
1094
  updateCarouselPosition();
1095
  }
 
1102
  function updateCarouselPosition() {
1103
  const carousel = document.getElementById('promptCarousel');
1104
  const cards = carousel.querySelectorAll('.carousel-card');
1105
+ const dots = document.querySelectorAll('.carousel-dot');
1106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  cards.forEach((card, index) => {
1108
  const angle = (index - currentCarouselIndex) * 60;
1109
  const isActive = index === currentCarouselIndex;
1110
 
 
 
1111
  card.style.transform = `rotateY(${angle}deg) translateZ(500px)`;
1112
  card.style.opacity = isActive ? '1' : '0.6';
1113
  card.style.zIndex = isActive ? '10' : '1';
1114
  });
1115
+
1116
+ dots.forEach((dot, index) => {
1117
+ dot.classList.toggle('active', index === currentCarouselIndex);
1118
+ });
 
 
 
 
1119
  }
1120
 
1121
  function applyPromptsAndSwitchToChat() {
 
1124
  showNotification('Prompts applied successfully!', 'success');
1125
  }
1126
 
1127
+ // File handling
1128
+ function setupDropzone() {
1129
+ const dropzone = document.getElementById('dropzone');
1130
+ const chatMode = document.getElementById('chatMode');
1131
+
1132
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
1133
+ chatMode.addEventListener(eventName, preventDefaults, false);
1134
+ });
1135
+
1136
+ function preventDefaults(e) {
1137
+ e.preventDefault();
1138
+ e.stopPropagation();
1139
+ }
1140
+
1141
+ ['dragenter', 'dragover'].forEach(eventName => {
1142
+ chatMode.addEventListener(eventName, () => dropzone.classList.add('active'), false);
1143
+ });
1144
+
1145
+ ['dragleave', 'drop'].forEach(eventName => {
1146
+ chatMode.addEventListener(eventName, () => dropzone.classList.remove('active'), false);
1147
+ });
1148
+
1149
+ chatMode.addEventListener('drop', handleDrop, false);
1150
+ }
1151
+
1152
+ function handleDrop(e) {
1153
+ const dt = e.dataTransfer;
1154
+ const files = dt.files;
1155
+ handleFiles(files);
1156
+ }
1157
+
1158
+ function handleFileSelect(e) {
1159
+ const files = e.target.files;
1160
+ handleFiles(files);
1161
+ }
1162
+
1163
+ function handleFiles(files) {
1164
+ attachedFiles = Array.from(files);
1165
+ updateFileDisplay();
1166
+ }
1167
+
1168
+ function updateFileDisplay() {
1169
+ const fileName = document.getElementById('fileName');
1170
+ if (attachedFiles.length === 0) {
1171
+ fileName.textContent = '';
1172
+ } else if (attachedFiles.length === 1) {
1173
+ fileName.textContent = attachedFiles[0].name;
1174
+ } else {
1175
+ fileName.textContent = `${attachedFiles.length} files selected`;
1176
+ }
1177
+ }
1178
+
1179
  // Chat functionality
1180
  function handleKeyDown(e) {
1181
  if (e.key === 'Enter' && !e.shiftKey) {
 
1188
  const userInput = document.getElementById('userInput');
1189
  const message = userInput.value.trim();
1190
 
1191
+ if (!message && attachedFiles.length === 0) return;
1192
  if (isLoading) return;
1193
 
1194
  const chatContainer = document.getElementById('chatContainer');
1195
 
1196
  // Add user message
1197
+ if (message) {
1198
+ addMessage(message, 'user');
1199
+ }
1200
+
1201
+ // Add file previews
1202
+ if (attachedFiles.length > 0) {
1203
+ for (const file of attachedFiles) {
1204
+ if (file.type.startsWith('image/')) {
1205
+ const imageUrl = URL.createObjectURL(file);
1206
+ addImageMessage(imageUrl, 'user');
1207
+ }
1208
+ }
1209
+ }
1210
 
1211
  userInput.value = '';
1212
  setLoading(true);
1213
 
1214
  try {
1215
+ const response = await callHuggingFaceAPI(message, attachedFiles);
1216
  addMessage(response, 'ai');
1217
  } catch (error) {
1218
  console.error('Error:', error);
 
1220
  showNotification('Error: ' + error.message, 'error');
1221
  } finally {
1222
  setLoading(false);
1223
+ attachedFiles = [];
1224
+ updateFileDisplay();
1225
  }
1226
 
1227
  chatContainer.scrollTop = chatContainer.scrollHeight;
1228
  }
1229
 
1230
+ async function callHuggingFaceAPI(message, files) {
1231
  const model = document.getElementById('modelSelect').value;
 
 
1232
  const primaryPrompt = document.getElementById('primarySystemPrompt').value;
1233
+ const prefix = document.getElementById('promptPrefix').value;
1234
+ const suffix = document.getElementById('promptSuffix').value;
1235
 
1236
+ let fullPrompt = `${primaryPrompt}\n\n${prefix}\n\n${message}\n\n${suffix}`;
1237
+
1238
+ // Handle OCR for images if needed
1239
+ if (files.length > 0) {
1240
+ const ocrModel = document.getElementById('ocrModelSelect').value;
1241
+ if (ocrModel !== 'none') {
1242
+ for (const file of files) {
1243
+ if (file.type.startsWith('image/')) {
1244
+ try {
1245
+ const ocrText = await performOCR(file, ocrModel);
1246
+ fullPrompt += `\n\nExtracted text from image: ${ocrText}`;
1247
+ } catch (error) {
1248
+ console.warn('OCR failed:', error);
1249
+ }
1250
+ }
1251
+ }
1252
+ }
1253
  }
1254
 
 
 
1255
  const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {
1256
  method: 'POST',
1257
  headers: {
1258
+ 'Authorization': 'Bearer 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', // Replace with actual token
1259
  'Content-Type': 'application/json',
1260
  },
1261
  body: JSON.stringify({
1262
  inputs: fullPrompt,
1263
  parameters: {
1264
+ max_new_tokens: 2048,
1265
  temperature: 0.7,
1266
  top_p: 0.9,
1267
+ do_sample: true
 
1268
  }
1269
  })
1270
  });
1271
 
1272
  if (!response.ok) {
1273
+ throw new Error(`HTTP error! status: ${response.status}`);
 
1274
  }
1275
 
1276
  const data = await response.json();
 
1279
  throw new Error(data.error);
1280
  }
1281
 
1282
+ return data[0]?.generated_text || data.choices?.[0]?.message?.content || 'No response generated';
1283
+ }
1284
+
1285
+ async function performOCR(file, ocrModel) {
1286
+ const formData = new FormData();
1287
+ formData.append('file', file);
1288
+
1289
+ const response = await fetch(`https://api-inference.huggingface.co/models/${ocrModel}`, {
1290
+ method: 'POST',
1291
+ headers: {
1292
+ 'Authorization': 'Bearer hf_your_token_here', // Replace with actual token
1293
+ },
1294
+ body: formData
1295
+ });
1296
+
1297
+ if (!response.ok) {
1298
+ throw new Error(`OCR failed: ${response.status}`);
1299
+ }
1300
+
1301
+ const data = await response.json();
1302
+ return data.generated_text || data.text || 'Could not extract text';
1303
  }
1304
 
1305
  function addMessage(content, sender) {
 
1322
  chatContainer.scrollTop = chatContainer.scrollHeight;
1323
  }
1324
 
1325
+ function addImageMessage(imageUrl, sender) {
1326
+ const chatContainer = document.getElementById('chatContainer');
1327
+ const messageDiv = document.createElement('div');
1328
+ messageDiv.className = `message ${sender}`;
1329
+
1330
+ const img = document.createElement('img');
1331
+ img.src = imageUrl;
1332
+ img.className = 'image-preview';
1333
+ img.alt = 'Uploaded image';
1334
+
1335
+ messageDiv.appendChild(img);
1336
+ chatContainer.appendChild(messageDiv);
1337
+ chatContainer.scrollTop = chatContainer.scrollHeight;
1338
+ }
1339
+
1340
  function addCodeTools(preElement) {
1341
  const toolsDiv = document.createElement('div');
1342
  toolsDiv.className = 'code-tools';
 
1404
  }
1405
  </script>
1406
  </body>
1407
+ </html>