ErNewdev0 commited on
Commit
8dd43e4
·
verified ·
1 Parent(s): ba323a6

fix: fixes example tabs

Browse files
Files changed (1) hide show
  1. app.py +99 -17
app.py CHANGED
@@ -15,6 +15,7 @@ import dotenv
15
 
16
  # Load environment variables
17
  dotenv.load_dotenv()
 
18
 
19
  # Metadata
20
  CURRENT_TIME = "2025-05-23 12:57:22"
@@ -301,7 +302,6 @@ class RepoAnalyzer:
301
  continue
302
  return False, "Tidak dapat membaca file dengan encoding yang didukung"
303
 
304
- analyzer = RepoAnalyzer()
305
 
306
  async def handle_chat(
307
  message,
@@ -396,32 +396,43 @@ def create_ui():
396
  background: #f8f9fa;
397
  border-radius: 8px;
398
  border: 1px solid #e9ecef;
 
399
  }
400
  .example-list h3 {
401
  color: #2c3e50;
402
  margin-top: 20px;
403
  margin-bottom: 10px;
 
404
  }
405
  .example-list h4 {
406
  color: #34495e;
407
  margin-top: 15px;
408
  margin-bottom: 5px;
 
409
  }
410
  .example-list ul {
411
- margin-bottom: 15px;
 
412
  }
413
  .example-list li {
414
  margin: 8px 0;
415
  line-height: 1.5;
 
416
  }
417
  .example-list code {
418
  background: #e9ecef;
419
  padding: 2px 5px;
420
  border-radius: 4px;
421
  font-family: monospace;
 
422
  }
423
  .example-list strong {
424
  color: #2c3e50;
 
 
 
 
 
425
  }
426
  @media (max-width: 768px) {
427
  .gr-form { flex-direction: column !important; }
@@ -541,7 +552,7 @@ def create_ui():
541
  with gr.Tab("💡 Examples"):
542
  example_output = gr.HTML(
543
  value="Pilih file di tab Analisis Repository untuk melihat contoh pertanyaan.",
544
- label="Contoh Pertanyaan",
545
  )
546
 
547
  # Chat Interface (outside tabs)
@@ -599,17 +610,85 @@ def create_ui():
599
  html += "</div>"
600
  return html
601
 
602
- def generate_examples(selected_files):
603
- if not selected_files:
604
- return "Pilih file terlebih dahulu di tab Analisis Repository untuk mendapatkan contoh pertanyaan yang relevan."
605
-
606
- examples = "<div class='example-list'>"
607
-
608
- # Add example generation logic here (as shown in previous example)
609
- # ...
610
-
611
- examples += "</div>"
612
- return examples
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
 
614
  def clear_chat_history():
615
  return []
@@ -642,11 +721,14 @@ def create_ui():
642
  fn=generate_examples,
643
  inputs=[file_selector],
644
  outputs=[example_output],
645
- api_name=False,
646
  )
647
-
 
648
  file_selector.change(
649
- fn=generate_examples, inputs=[file_selector], outputs=[example_output]
 
 
650
  )
651
 
652
  # Chat events
 
15
 
16
  # Load environment variables
17
  dotenv.load_dotenv()
18
+ analyzer = RepoAnalyzer()
19
 
20
  # Metadata
21
  CURRENT_TIME = "2025-05-23 12:57:22"
 
302
  continue
303
  return False, "Tidak dapat membaca file dengan encoding yang didukung"
304
 
 
305
 
306
  async def handle_chat(
307
  message,
 
396
  background: #f8f9fa;
397
  border-radius: 8px;
398
  border: 1px solid #e9ecef;
399
+ margin: 10px 0;
400
  }
401
  .example-list h3 {
402
  color: #2c3e50;
403
  margin-top: 20px;
404
  margin-bottom: 10px;
405
+ font-size: 1.2em;
406
  }
407
  .example-list h4 {
408
  color: #34495e;
409
  margin-top: 15px;
410
  margin-bottom: 5px;
411
+ font-size: 1.1em;
412
  }
413
  .example-list ul {
414
+ margin: 10px 0;
415
+ padding-left: 20px;
416
  }
417
  .example-list li {
418
  margin: 8px 0;
419
  line-height: 1.5;
420
+ list-style-type: disc;
421
  }
422
  .example-list code {
423
  background: #e9ecef;
424
  padding: 2px 5px;
425
  border-radius: 4px;
426
  font-family: monospace;
427
+ font-size: 0.9em;
428
  }
429
  .example-list strong {
430
  color: #2c3e50;
431
+ font-weight: bold;
432
+ }
433
+ .example-list p {
434
+ margin: 10px 0;
435
+ line-height: 1.5;
436
  }
437
  @media (max-width: 768px) {
438
  .gr-form { flex-direction: column !important; }
 
552
  with gr.Tab("💡 Examples"):
553
  example_output = gr.HTML(
554
  value="Pilih file di tab Analisis Repository untuk melihat contoh pertanyaan.",
555
+ label="Contoh Pertanyaan"
556
  )
557
 
558
  # Chat Interface (outside tabs)
 
610
  html += "</div>"
611
  return html
612
 
613
+ def generate_examples(selected_files):
614
+ if not selected_files:
615
+ return """
616
+ <div class='example-list'>
617
+ <h3>Pilih File Terlebih Dahulu</h3>
618
+ <p>Silakan pilih file di tab Analisis Repository untuk melihat contoh pertanyaan yang relevan.</p>
619
+ </div>
620
+ """
621
+
622
+ examples = "<div class='example-list'>"
623
+
624
+ # General examples for any file
625
+ examples += """
626
+ <h3>Contoh Pertanyaan Umum:</h3>
627
+ <ul>
628
+ """
629
+
630
+ file_names = ", ".join([f"<code>{f.split('/')[-1]}</code>" for f in selected_files])
631
+ examples += f"""
632
+ <li><strong>Analisis Kode:</strong> "Jelaskan logika dan fungsi utama dari {file_names}"</li>
633
+ <li><strong>Deteksi Bug:</strong> "Apakah ada potensi bug atau masalah keamanan di file-file ini?"</li>
634
+ <li><strong>Best Practices:</strong> "Bagaimana cara mengoptimalkan kode di file-file ini?"</li>
635
+ """
636
+
637
+ # Specific examples based on file types
638
+ for file in selected_files:
639
+ filename = file.split('/')[-1]
640
+ ext = filename.split('.')[-1].lower() if '.' in filename else ''
641
+ examples += f"<h4>Contoh untuk {filename}:</h4><ul>"
642
+
643
+ if ext in ['py', 'js', 'java', 'cpp', 'c', 'go']:
644
+ examples += f"""
645
+ <li>"Jelaskan fungsi-fungsi utama di {filename}"</li>
646
+ <li>"Bagaimana cara mengoptimalkan performa di {filename}?"</li>
647
+ <li>"Buat unit test untuk fungsi-fungsi di {filename}"</li>
648
+ """
649
+ elif ext in ['html', 'css']:
650
+ examples += f"""
651
+ <li>"Analisis struktur dan layout dari {filename}"</li>
652
+ <li>"Bagaimana cara membuat {filename} lebih responsif?"</li>
653
+ <li>"Optimasi untuk mobile view di {filename}"</li>
654
+ """
655
+ elif ext == 'md':
656
+ examples += f"""
657
+ <li>"Ringkas isi dokumentasi dari {filename}"</li>
658
+ <li>"Buat tabel konten untuk {filename}"</li>
659
+ <li>"Perbaiki formatting di {filename}"</li>
660
+ """
661
+ elif ext in ['json', 'yaml', 'yml']:
662
+ examples += f"""
663
+ <li>"Validasi struktur data di {filename}"</li>
664
+ <li>"Jelaskan konfigurasi di {filename}"</li>
665
+ <li>"Optimasi format di {filename}"</li>
666
+ """
667
+ elif ext == 'dockerfile':
668
+ examples += f"""
669
+ <li>"Analisis keamanan dari {filename}"</li>
670
+ <li>"Optimasi multi-stage build di {filename}"</li>
671
+ <li>"Best practices untuk {filename}"</li>
672
+ """
673
+ else:
674
+ examples += f"""
675
+ <li>"Analisis isi dari {filename}"</li>
676
+ <li>"Jelaskan struktur dan tujuan {filename}"</li>
677
+ <li>"Saran perbaikan untuk {filename}"</li>
678
+ """
679
+ examples += "</ul>"
680
+
681
+ examples += """
682
+ <h3>Tips Bertanya:</h3>
683
+ <ul>
684
+ <li>Gunakan pertanyaan yang spesifik dan fokus pada bagian tertentu</li>
685
+ <li>Sebutkan nama file jika bertanya tentang file tertentu</li>
686
+ <li>Jelaskan konteks atau masalah yang ingin diselesaikan</li>
687
+ </ul>
688
+ """
689
+
690
+ examples += "</div>"
691
+ return examples
692
 
693
  def clear_chat_history():
694
  return []
 
721
  fn=generate_examples,
722
  inputs=[file_selector],
723
  outputs=[example_output],
724
+ api_name=False
725
  )
726
+
727
+ # Also update when file selection changes
728
  file_selector.change(
729
+ fn=generate_examples,
730
+ inputs=[file_selector],
731
+ outputs=[example_output]
732
  )
733
 
734
  # Chat events