ErNewdev0 commited on
Commit
a50342d
·
verified ·
1 Parent(s): 73a4f15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -147
app.py CHANGED
@@ -305,7 +305,7 @@ class RepoAnalyzer:
305
  def create_ui():
306
  analyzer = RepoAnalyzer()
307
 
308
- with gr.Blocks(title="Repository Chat Analysis", theme=gr.themes.Soft()) as app:
309
  gr.Markdown("""
310
  <style>
311
  .container { max-width: 100% !important; padding: 1rem; }
@@ -375,6 +375,7 @@ def create_ui():
375
  repo_url = gr.Textbox(
376
  label="URL Repository GitHub",
377
  placeholder="https://github.com/username/repository",
 
378
  )
379
 
380
  with gr.Row():
@@ -383,15 +384,23 @@ def create_ui():
383
  label="Token GitHub",
384
  type="password",
385
  placeholder="Klik icon (?) untuk panduan",
 
386
  )
 
387
  with gr.Column(scale=1):
388
  branch = gr.Textbox(
389
- label="Branch (opsional)", placeholder="main"
 
 
390
  )
391
 
392
- clone_button = gr.Button("🔄 Clone Repository", variant="primary")
 
 
393
 
394
- clone_status = gr.Markdown(value="", label="Status Repository")
 
 
395
 
396
  # File Selection
397
  with gr.Group():
@@ -403,6 +412,8 @@ def create_ui():
403
  choices=[],
404
  multiselect=True,
405
  value=[], # Initialize with empty list
 
 
406
  )
407
 
408
  file_list = gr.HTML(
@@ -410,13 +421,23 @@ def create_ui():
410
  label="Daftar File Terpilih",
411
  )
412
 
 
 
 
 
 
 
 
 
 
413
  # Chat Interface
414
  with gr.Group():
415
  chat_history = gr.Chatbot(
416
  label="📝 Riwayat Chat",
417
  height=500,
418
  show_label=True,
419
- type="messages", # Fix deprecation warning
 
420
  )
421
 
422
  with gr.Row():
@@ -424,6 +445,7 @@ def create_ui():
424
  label="💭 Tanyakan tentang Repository",
425
  placeholder="Ketik pertanyaan Anda di sini...",
426
  lines=3,
 
427
  )
428
  send_button = gr.Button("📤 Kirim", variant="primary")
429
 
@@ -431,105 +453,33 @@ def create_ui():
431
  '<div id="loading" style="display:none">Memproses permintaan...</div>'
432
  )
433
 
434
- # Event Handlers
435
- def handle_clone(repo_url, github_token, branch):
436
- if not repo_url:
437
- return "⚠️ URL repository diperlukan!", [], []
438
-
439
- success, message = analyzer.clone_repository(repo_url, github_token, branch)
440
-
441
- if success:
442
- # Get list of files from cloned repository
443
- files = sorted(
444
- list(analyzer.repo_content.keys())
445
- ) # Sort files alphabetically
446
- return message, files, []
447
-
448
- return message, [], []
449
-
450
- def update_file_list(selected):
451
- if not selected:
452
- return "<div class='file-list'>Belum ada file yang dipilih</div>"
453
-
454
- html = "<div class='file-list'>"
455
- for file in selected:
456
- html += f"<div class='file-item'><span>{file}</span></div>"
457
- html += "</div>"
458
- return html
459
-
460
- def update_model_list(provider_choice):
461
- if provider_choice == AIProvider.XAI:
462
- return gr.Dropdown(choices=XAI_MODELS, value="grok-2-latest")
463
- elif provider_choice == AIProvider.GEMINI:
464
- return gr.Dropdown(choices=GEMINI_MODELS, value="gemini-1.5-mini")
465
- else: # OLLAMA
466
- return gr.Dropdown(choices=OLLAMA_MODELS, value="llama2")
467
-
468
- # Connect Events
469
- provider.change(
470
- fn=update_model_list, inputs=[provider], outputs=[model_dropdown]
471
- )
472
-
473
- clone_button.click(
474
- fn=handle_clone,
475
- inputs=[repo_url, github_token, branch],
476
- outputs=[clone_status, file_selector, file_list],
477
- )
478
-
479
- file_selector.change(
480
- fn=update_file_list, inputs=[file_selector], outputs=[file_list]
481
- )
482
-
483
- with gr.Tab("📊 Analisis Repository", elem_classes="mobile-full"):
484
- with gr.Group():
485
- with gr.Row():
486
- repo_url = gr.Textbox(
487
- label="URL Repository GitHub",
488
- placeholder="https://github.com/username/repository",
489
- elem_classes="mobile-full",
490
- )
491
-
492
- with gr.Row():
493
- with gr.Column(scale=2):
494
- github_token = gr.Textbox(
495
- label="Token GitHub",
496
- type="password",
497
- placeholder="Klik icon (?) untuk panduan",
498
- elem_classes="mobile-full",
499
- )
500
- with gr.Column(scale=1):
501
- branch = gr.Textbox(
502
- label="Branch (opsional)",
503
- placeholder="main",
504
- elem_classes="mobile-full",
505
- )
506
-
507
- clone_button = gr.Button(
508
- "🔄 Clone Repository", variant="primary", elem_classes="mobile-full"
509
- )
510
-
511
- clone_status = gr.Markdown(
512
- value="", label="Status Repository", elem_classes="mobile-full"
513
- )
514
 
515
- # Add file selection components
516
- with gr.Group():
517
- gr.Markdown("### 📎 File yang Dipilih")
518
 
519
- with gr.Row():
520
- file_selector = gr.Dropdown(
521
- label="Pilih File dari Repository",
522
- choices=[],
523
- multiselect=True,
524
- elem_classes="mobile-full",
 
 
 
525
  )
526
 
527
- file_list = gr.HTML(
528
- value="<div class='file-list'>Belum ada file yang dipilih</div>",
529
- label="Daftar File Terpilih",
 
530
  )
531
 
532
- def update_file_list(selected: List[str]) -> str:
533
  if not selected:
534
  return "<div class='file-list'>Belum ada file yang dipilih</div>"
535
 
@@ -539,64 +489,17 @@ def create_ui():
539
  html += "</div>"
540
  return html
541
 
542
- def handle_clone(repo_url, github_token, branch):
543
- if not repo_url:
544
- return "⚠️ URL repository diperlukan!", [], []
545
-
546
- success, message = analyzer.clone_repository(
547
- repo_url, github_token, branch
548
- )
549
-
550
- if success:
551
- # Get list of files from cloned repository
552
- files = list(analyzer.repo_content.keys())
553
- return message, files, []
554
-
555
- return message, [], []
556
-
557
- # Connect clone button click event
558
  clone_button.click(
559
  fn=handle_clone,
560
  inputs=[repo_url, github_token, branch],
561
  outputs=[clone_status, file_selector, file_list],
562
  )
563
 
564
- # Update file list when selection changes
565
  file_selector.change(
566
  fn=update_file_list, inputs=[file_selector], outputs=[file_list]
567
  )
568
 
569
- gr.Markdown("""
570
- ### 💡 Contoh Pertanyaan:
571
- - "Jelaskan struktur utama dari repository ini"
572
- - "Analisis kode di file yang dipilih"
573
- - "Bagaimana cara memperbaiki [masalah specific] di file-file ini?"
574
- - "Bandingkan implementasi di file-file yang dipilih"
575
- """)
576
-
577
- # Improved chat interface
578
- with gr.Group():
579
- chat_input = gr.Textbox(
580
- label="💭 Tanyakan tentang Repository",
581
- placeholder="Ketik pertanyaan Anda di sini...",
582
- lines=3,
583
- elem_classes="mobile-full",
584
- )
585
- send_button = gr.Button(
586
- "📤 Kirim", variant="primary", elem_classes="mobile-full"
587
- )
588
-
589
- chat_history = gr.Chatbot(
590
- label="📝 Riwayat Chat",
591
- height=500,
592
- show_label=True,
593
- elem_classes="mobile-full",
594
- )
595
-
596
- loading_indicator = gr.HTML(
597
- '<div id="loading" style="display:none">Memproses permintaan...</div>'
598
- )
599
-
600
  async def handle_chat(
601
  message,
602
  history,
@@ -704,4 +607,4 @@ if __name__ == "__main__":
704
  """)
705
 
706
  app = create_ui()
707
- app.launch(share=True)
 
305
  def create_ui():
306
  analyzer = RepoAnalyzer()
307
 
308
+ with gr.Blocks(title="Open Repo AI", theme=gr.themes.Soft()) as app:
309
  gr.Markdown("""
310
  <style>
311
  .container { max-width: 100% !important; padding: 1rem; }
 
375
  repo_url = gr.Textbox(
376
  label="URL Repository GitHub",
377
  placeholder="https://github.com/username/repository",
378
+ elem_classes="mobile-full",
379
  )
380
 
381
  with gr.Row():
 
384
  label="Token GitHub",
385
  type="password",
386
  placeholder="Klik icon (?) untuk panduan",
387
+ elem_classes="mobile-full",
388
  )
389
+ gr.Markdown(GITHUB_TOKEN_HELP) # Add help text
390
  with gr.Column(scale=1):
391
  branch = gr.Textbox(
392
+ label="Branch (opsional)",
393
+ placeholder="main",
394
+ elem_classes="mobile-full",
395
  )
396
 
397
+ clone_button = gr.Button(
398
+ "🔄 Clone Repository", variant="primary", elem_classes="mobile-full"
399
+ )
400
 
401
+ clone_status = gr.Markdown(
402
+ value="", label="Status Repository", elem_classes="mobile-full"
403
+ )
404
 
405
  # File Selection
406
  with gr.Group():
 
412
  choices=[],
413
  multiselect=True,
414
  value=[], # Initialize with empty list
415
+ elem_classes="mobile-full",
416
+ allow_custom_value=False, # Prevent custom values
417
  )
418
 
419
  file_list = gr.HTML(
 
421
  label="Daftar File Terpilih",
422
  )
423
 
424
+ # Example questions
425
+ gr.Markdown("""
426
+ ### 💡 Contoh Pertanyaan:
427
+ - "Jelaskan struktur utama dari repository ini"
428
+ - "Analisis kode di file yang dipilih"
429
+ - "Bagaimana cara memperbaiki [masalah specific] di file-file ini?"
430
+ - "Bandingkan implementasi di file-file yang dipilih"
431
+ """)
432
+
433
  # Chat Interface
434
  with gr.Group():
435
  chat_history = gr.Chatbot(
436
  label="📝 Riwayat Chat",
437
  height=500,
438
  show_label=True,
439
+ type="messages",
440
+ elem_classes="mobile-full",
441
  )
442
 
443
  with gr.Row():
 
445
  label="💭 Tanyakan tentang Repository",
446
  placeholder="Ketik pertanyaan Anda di sini...",
447
  lines=3,
448
+ elem_classes="mobile-full",
449
  )
450
  send_button = gr.Button("📤 Kirim", variant="primary")
451
 
 
453
  '<div id="loading" style="display:none">Memproses permintaan...</div>'
454
  )
455
 
456
+ # Event Handlers
457
+ def handle_clone(repo_url, github_token, branch):
458
+ if not repo_url:
459
+ return "⚠️ URL repository diperlukan!", [], ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
 
461
+ success, message = analyzer.clone_repository(
462
+ repo_url, github_token, branch
463
+ )
464
 
465
+ if success:
466
+ # Get list of files from cloned repository
467
+ files = sorted(
468
+ list(analyzer.repo_content.keys())
469
+ ) # Sort files alphabetically
470
+ return (
471
+ message,
472
+ files,
473
+ "<div class='file-list'>Belum ada file yang dipilih</div>",
474
  )
475
 
476
+ return (
477
+ message,
478
+ [],
479
+ "<div class='file-list'>Belum ada file yang dipilih</div>",
480
  )
481
 
482
+ def update_file_list(selected):
483
  if not selected:
484
  return "<div class='file-list'>Belum ada file yang dipilih</div>"
485
 
 
489
  html += "</div>"
490
  return html
491
 
492
+ # Connect Events
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  clone_button.click(
494
  fn=handle_clone,
495
  inputs=[repo_url, github_token, branch],
496
  outputs=[clone_status, file_selector, file_list],
497
  )
498
 
 
499
  file_selector.change(
500
  fn=update_file_list, inputs=[file_selector], outputs=[file_list]
501
  )
502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  async def handle_chat(
504
  message,
505
  history,
 
607
  """)
608
 
609
  app = create_ui()
610
+ app.launch(share=True)