Spaces:
Sleeping
Sleeping
fix: fixed indentation error
Browse files
app.py
CHANGED
|
@@ -552,7 +552,7 @@ def create_ui():
|
|
| 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,85 +610,87 @@ def create_ui():
|
|
| 610 |
html += "</div>"
|
| 611 |
return html
|
| 612 |
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
|
|
|
|
|
|
| 692 |
|
| 693 |
def clear_chat_history():
|
| 694 |
return []
|
|
@@ -721,14 +723,12 @@ def create_ui():
|
|
| 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
|
|
@@ -773,4 +773,4 @@ if __name__ == "__main__":
|
|
| 773 |
""")
|
| 774 |
|
| 775 |
app = create_ui()
|
| 776 |
-
app.launch(share=True)
|
|
|
|
| 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(
|
| 631 |
+
[f"<code>{f.split('/')[-1]}</code>" for f in selected_files]
|
| 632 |
+
)
|
| 633 |
+
examples += f"""
|
| 634 |
+
<li><strong>Analisis Kode:</strong> "Jelaskan logika dan fungsi utama dari {file_names}"</li>
|
| 635 |
+
<li><strong>Deteksi Bug:</strong> "Apakah ada potensi bug atau masalah keamanan di file-file ini?"</li>
|
| 636 |
+
<li><strong>Best Practices:</strong> "Bagaimana cara mengoptimalkan kode di file-file ini?"</li>
|
| 637 |
+
"""
|
| 638 |
+
|
| 639 |
+
# Specific examples based on file types
|
| 640 |
+
for file in selected_files:
|
| 641 |
+
filename = file.split("/")[-1]
|
| 642 |
+
ext = filename.split(".")[-1].lower() if "." in filename else ""
|
| 643 |
+
examples += f"<h4>Contoh untuk {filename}:</h4><ul>"
|
| 644 |
+
|
| 645 |
+
if ext in ["py", "js", "java", "cpp", "c", "go"]:
|
| 646 |
+
examples += f"""
|
| 647 |
+
<li>"Jelaskan fungsi-fungsi utama di {filename}"</li>
|
| 648 |
+
<li>"Bagaimana cara mengoptimalkan performa di {filename}?"</li>
|
| 649 |
+
<li>"Buat unit test untuk fungsi-fungsi di {filename}"</li>
|
| 650 |
+
"""
|
| 651 |
+
elif ext in ["html", "css"]:
|
| 652 |
+
examples += f"""
|
| 653 |
+
<li>"Analisis struktur dan layout dari {filename}"</li>
|
| 654 |
+
<li>"Bagaimana cara membuat {filename} lebih responsif?"</li>
|
| 655 |
+
<li>"Optimasi untuk mobile view di {filename}"</li>
|
| 656 |
+
"""
|
| 657 |
+
elif ext == "md":
|
| 658 |
+
examples += f"""
|
| 659 |
+
<li>"Ringkas isi dokumentasi dari {filename}"</li>
|
| 660 |
+
<li>"Buat tabel konten untuk {filename}"</li>
|
| 661 |
+
<li>"Perbaiki formatting di {filename}"</li>
|
| 662 |
+
"""
|
| 663 |
+
elif ext in ["json", "yaml", "yml"]:
|
| 664 |
+
examples += f"""
|
| 665 |
+
<li>"Validasi struktur data di {filename}"</li>
|
| 666 |
+
<li>"Jelaskan konfigurasi di {filename}"</li>
|
| 667 |
+
<li>"Optimasi format di {filename}"</li>
|
| 668 |
+
"""
|
| 669 |
+
elif ext == "dockerfile":
|
| 670 |
+
examples += f"""
|
| 671 |
+
<li>"Analisis keamanan dari {filename}"</li>
|
| 672 |
+
<li>"Optimasi multi-stage build di {filename}"</li>
|
| 673 |
+
<li>"Best practices untuk {filename}"</li>
|
| 674 |
+
"""
|
| 675 |
+
else:
|
| 676 |
+
examples += f"""
|
| 677 |
+
<li>"Analisis isi dari {filename}"</li>
|
| 678 |
+
<li>"Jelaskan struktur dan tujuan {filename}"</li>
|
| 679 |
+
<li>"Saran perbaikan untuk {filename}"</li>
|
| 680 |
+
"""
|
| 681 |
+
examples += "</ul>"
|
| 682 |
+
|
| 683 |
+
examples += """
|
| 684 |
+
<h3>Tips Bertanya:</h3>
|
| 685 |
+
<ul>
|
| 686 |
+
<li>Gunakan pertanyaan yang spesifik dan fokus pada bagian tertentu</li>
|
| 687 |
+
<li>Sebutkan nama file jika bertanya tentang file tertentu</li>
|
| 688 |
+
<li>Jelaskan konteks atau masalah yang ingin diselesaikan</li>
|
| 689 |
+
</ul>
|
| 690 |
+
"""
|
| 691 |
+
|
| 692 |
+
examples += "</div>"
|
| 693 |
+
return examples
|
| 694 |
|
| 695 |
def clear_chat_history():
|
| 696 |
return []
|
|
|
|
| 723 |
fn=generate_examples,
|
| 724 |
inputs=[file_selector],
|
| 725 |
outputs=[example_output],
|
| 726 |
+
api_name=False,
|
| 727 |
)
|
| 728 |
+
|
| 729 |
# Also update when file selection changes
|
| 730 |
file_selector.change(
|
| 731 |
+
fn=generate_examples, inputs=[file_selector], outputs=[example_output]
|
|
|
|
|
|
|
| 732 |
)
|
| 733 |
|
| 734 |
# Chat events
|
|
|
|
| 773 |
""")
|
| 774 |
|
| 775 |
app = create_ui()
|
| 776 |
+
app.launch(share=True)
|