iohaijg commited on
Commit
58b9777
·
verified ·
1 Parent(s): 8b295c3

make it to automatically scan all the code and tell what language it is an then automatically start cleaning it

Browse files
Files changed (1) hide show
  1. index.html +50 -30
index.html CHANGED
@@ -272,24 +272,15 @@ model.save_pretrained("code_cleaner_model")</code></pre>
272
  </div>
273
  </div>
274
  </div>
275
- <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
276
- <div class="flex flex-col">
277
- <label class="text-gray-300 mb-2">Choose Language</label>
278
- <select id="language-select" class="bg-gray-700 text-white p-2 rounded">
279
- <option value="python">Python</option>
280
- <option value="javascript">JavaScript</option>
281
- <option value="java">Java</option>
282
- <option value="csharp">C#</option>
283
- <option value="php">PHP</option>
284
- </select>
285
- </div>
286
- <div class="flex items-end">
287
- <button id="process-btn" class="bg-blue-600 hover:bg-blue-700 px-8 py-3 rounded-lg font-bold text-lg transition w-full">
288
- Clean This Code
289
- </button>
290
- </div>
291
  </div>
292
- <div class="text-center">
 
 
 
293
  <p class="text-gray-400 mb-2">OR</p>
294
  <button id="repo-btn" class="border border-blue-500 text-blue-400 hover:bg-blue-500/10 px-6 py-2 rounded-lg transition">
295
  <i data-feather="github" class="inline mr-2"></i> Clean Entire Repository
@@ -334,8 +325,17 @@ model.save_pretrained("code_cleaner_model")</code></pre>
334
  </div>
335
  </footer>
336
  <script>
 
 
 
 
 
 
 
 
 
337
  // Initialize Vanta.js globe
338
- VANTA.GLOBE({
339
  el: "#globe-bg",
340
  mouseControls: true,
341
  touchControls: true,
@@ -356,20 +356,42 @@ model.save_pretrained("code_cleaner_model")</code></pre>
356
  const repoInput = document.getElementById('repo-input');
357
  const resultContainer = document.getElementById('result-container');
358
  const repoUrl = document.getElementById('repo-url');
359
- const languageSelect = document.getElementById('language-select');
 
360
 
361
- // Toggle repository input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  repoBtn.addEventListener('click', () => {
363
  repoInput.classList.toggle('hidden');
364
  if (!repoInput.classList.contains('hidden')) {
365
  codeEditor.value = '';
366
  }
367
  });
368
-
369
  // Process single code snippet
370
  processBtn.addEventListener('click', async () => {
371
- const code = codeEditor.value;
372
- if (!code.trim()) return;
 
 
 
 
 
373
 
374
  processBtn.disabled = true;
375
  processBtn.innerHTML = '<i data-feather="loader" class="animate-spin"></i> Processing...';
@@ -378,7 +400,6 @@ const code = codeEditor.value;
378
  try {
379
  // Using a mock API for demonstration
380
  // In production, replace with your actual API endpoint
381
- const language = languageSelect.value;
382
  const response = await fetch('/api/clean', {
383
  method: 'POST',
384
  headers: {
@@ -386,11 +407,10 @@ const code = codeEditor.value;
386
  },
387
  body: JSON.stringify({
388
  code: code,
389
- language: language
390
  })
391
  });
392
-
393
- const data = await response.json();
394
  resultContainer.innerHTML = `
395
  <div class="mb-4 flex justify-between items-center">
396
  <h4 class="font-bold text-blue-400">Cleaned Code</h4>
@@ -426,11 +446,11 @@ const code = codeEditor.value;
426
  },
427
  body: JSON.stringify({
428
  repo_url: url,
429
- language: languageSelect.value
 
430
  })
431
  });
432
-
433
- const data = await response.json();
434
  resultContainer.innerHTML = `
435
  <div class="mb-4">
436
  <h4 class="font-bold text-blue-400">Repository Analysis</h4>
 
272
  </div>
273
  </div>
274
  </div>
275
+ <div class="flex justify-center mb-4">
276
+ <button id="process-btn" class="bg-blue-600 hover:bg-blue-700 px-8 py-3 rounded-lg font-bold text-lg transition w-full md:w-auto">
277
+ Clean This Code
278
+ </button>
 
 
 
 
 
 
 
 
 
 
 
 
279
  </div>
280
+ <div id="detected-language" class="text-center text-gray-400 mb-4 hidden">
281
+ Detected: <span class="text-blue-400 font-medium"></span>
282
+ </div>
283
+ <div class="text-center">
284
  <p class="text-gray-400 mb-2">OR</p>
285
  <button id="repo-btn" class="border border-blue-500 text-blue-400 hover:bg-blue-500/10 px-6 py-2 rounded-lg transition">
286
  <i data-feather="github" class="inline mr-2"></i> Clean Entire Repository
 
325
  </div>
326
  </footer>
327
  <script>
328
+ // Auto-process when code is pasted
329
+ codeEditor.addEventListener('paste', (e) => {
330
+ setTimeout(() => {
331
+ if (codeEditor.value.trim()) {
332
+ processBtn.click();
333
+ }
334
+ }, 100);
335
+ });
336
+
337
  // Initialize Vanta.js globe
338
+ VANTA.GLOBE({
339
  el: "#globe-bg",
340
  mouseControls: true,
341
  touchControls: true,
 
356
  const repoInput = document.getElementById('repo-input');
357
  const resultContainer = document.getElementById('result-container');
358
  const repoUrl = document.getElementById('repo-url');
359
+ const detectedLangEl = document.getElementById('detected-language');
360
+ const detectedLangText = detectedLangEl.querySelector('span');
361
 
362
+ // Language detection patterns
363
+ const languagePatterns = {
364
+ python: /^(def |import |from |print\(|#)/m,
365
+ javascript: /^(function |const |let |var |\/\/)/m,
366
+ java: /^(public |private |class |import |\/\/)/m,
367
+ csharp: /^(using |namespace |class |\/\/)/m,
368
+ php: /^(<\?php|\$|function )/m
369
+ };
370
+
371
+ function detectLanguage(code) {
372
+ for (const [lang, pattern] of Object.entries(languagePatterns)) {
373
+ if (pattern.test(code)) {
374
+ return lang;
375
+ }
376
+ }
377
+ return 'python'; // default fallback
378
+ }
379
+ // Toggle repository input
380
  repoBtn.addEventListener('click', () => {
381
  repoInput.classList.toggle('hidden');
382
  if (!repoInput.classList.contains('hidden')) {
383
  codeEditor.value = '';
384
  }
385
  });
 
386
  // Process single code snippet
387
  processBtn.addEventListener('click', async () => {
388
+ const code = codeEditor.value.trim();
389
+ if (!code) return;
390
+
391
+ // Detect language
392
+ const detectedLanguage = detectLanguage(code);
393
+ detectedLangText.textContent = detectedLanguage;
394
+ detectedLangEl.classList.remove('hidden');
395
 
396
  processBtn.disabled = true;
397
  processBtn.innerHTML = '<i data-feather="loader" class="animate-spin"></i> Processing...';
 
400
  try {
401
  // Using a mock API for demonstration
402
  // In production, replace with your actual API endpoint
 
403
  const response = await fetch('/api/clean', {
404
  method: 'POST',
405
  headers: {
 
407
  },
408
  body: JSON.stringify({
409
  code: code,
410
+ language: detectedLanguage
411
  })
412
  });
413
+ const data = await response.json();
 
414
  resultContainer.innerHTML = `
415
  <div class="mb-4 flex justify-between items-center">
416
  <h4 class="font-bold text-blue-400">Cleaned Code</h4>
 
446
  },
447
  body: JSON.stringify({
448
  repo_url: url,
449
+ // Auto-detect will happen on server for repos
450
+ language: 'auto'
451
  })
452
  });
453
+ const data = await response.json();
 
454
  resultContainer.innerHTML = `
455
  <div class="mb-4">
456
  <h4 class="font-bold text-blue-400">Repository Analysis</h4>