ErNewdev0 commited on
Commit
49bae1b
Β·
verified Β·
1 Parent(s): 873cfe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -44
app.py CHANGED
@@ -281,7 +281,6 @@ class RepoAnalyzer:
281
 
282
  def create_ui():
283
  analyzer = RepoAnalyzer()
284
- selected_files = []
285
 
286
  with gr.Blocks(title="Repository Chat Analysis", theme=gr.themes.Soft()) as app:
287
  gr.Markdown("""
@@ -302,57 +301,170 @@ def create_ui():
302
  gr.Markdown(f"""
303
  # AI Github Repository Chat
304
 
305
- πŸ“… Waktu: {CURRENT_TIME}
306
  """)
307
 
308
- with gr.Tab("πŸ› οΈ Konfigurasi"):
309
- provider = gr.Radio(
310
- choices=[AIProvider.XAI, AIProvider.GEMINI, AIProvider.OLLAMA],
311
- label="Penyedia AI",
312
- value=AIProvider.XAI
313
- )
314
-
315
- with gr.Group() as api_settings:
316
- with gr.Row():
317
- xai_key = gr.Textbox(
318
- label="X.AI (Grok) API Key",
319
- type="password",
320
- placeholder="Opsional - Klik icon (?) untuk info. Kosongkan untuk gunakan key default",
321
- show_label=True
322
- )
323
- gr.Markdown(XAI_API_HELP)
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  with gr.Row():
326
- gemini_key = gr.Textbox(
327
- label="Gemini API Key",
328
- type="password",
329
- placeholder="Opsional - Kosongkan untuk gunakan key default",
330
- show_label=True
331
  )
332
- gr.Markdown(GEMINI_API_HELP)
333
-
334
- # Model selection based on provider
335
- with gr.Row():
336
- model_dropdown = gr.Dropdown(
337
- label="Model AI",
338
- choices=XAI_MODELS,
339
- value="grok-2-latest",
340
- interactive=True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
- def update_model_list(provider_choice):
344
- if provider_choice == AIProvider.XAI:
345
- return gr.Dropdown(choices=XAI_MODELS, value="grok-2-latest")
346
- elif provider_choice == AIProvider.GEMINI:
347
- return gr.Dropdown(choices=GEMINI_MODELS, value="gemini-pro")
348
- else: # OLLAMA
349
- return gr.Dropdown(choices=OLLAMA_MODELS, value="llama2")
350
 
351
- provider.change(
352
- fn=update_model_list,
353
- inputs=[provider],
354
- outputs=[model_dropdown]
355
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  with gr.Tab("πŸ“Š Analisis Repository", elem_classes="mobile-full"):
358
  with gr.Group():
 
281
 
282
  def create_ui():
283
  analyzer = RepoAnalyzer()
 
284
 
285
  with gr.Blocks(title="Repository Chat Analysis", theme=gr.themes.Soft()) as app:
286
  gr.Markdown("""
 
301
  gr.Markdown(f"""
302
  # AI Github Repository Chat
303
 
304
+ πŸ“… {datetime.now().strftime("%Y-%m-%d %H:%M:%S")} UTC
305
  """)
306
 
307
+ with gr.Tabs() as tabs: # Main tabs container
308
+ # Configuration Tab
309
+ with gr.Tab("πŸ› οΈ Konfigurasi"):
310
+ provider = gr.Radio(
311
+ choices=[AIProvider.XAI, AIProvider.GEMINI, AIProvider.OLLAMA],
312
+ label="Penyedia AI",
313
+ value=AIProvider.XAI
314
+ )
 
 
 
 
 
 
 
 
315
 
316
+ with gr.Group() as api_settings:
317
+ with gr.Row():
318
+ xai_key = gr.Textbox(
319
+ label="X.AI (Grok) API Key",
320
+ type="password",
321
+ placeholder="Opsional - Klik icon (?) untuk info",
322
+ show_label=True,
323
+ scale=3
324
+ )
325
+ with gr.Column(scale=1):
326
+ gr.Markdown(XAI_API_HELP)
327
+
328
+ with gr.Row():
329
+ gemini_key = gr.Textbox(
330
+ label="Gemini API Key",
331
+ type="password",
332
+ placeholder="Opsional - Kosongkan untuk gunakan key default",
333
+ show_label=True,
334
+ scale=3
335
+ )
336
+ with gr.Column(scale=1):
337
+ gr.Markdown(GEMINI_API_HELP)
338
+
339
+ # Model selection
340
  with gr.Row():
341
+ model_dropdown = gr.Dropdown(
342
+ label="Model AI",
343
+ choices=XAI_MODELS,
344
+ value="grok-2-latest",
345
+ interactive=True
346
  )
347
+
348
+ # Repository Analysis Tab
349
+ with gr.Tab("πŸ“Š Analisis Repository"):
350
+ with gr.Group():
351
+ with gr.Row():
352
+ repo_url = gr.Textbox(
353
+ label="URL Repository GitHub",
354
+ placeholder="https://github.com/username/repository"
355
+ )
356
+
357
+ with gr.Row():
358
+ with gr.Column(scale=2):
359
+ github_token = gr.Textbox(
360
+ label="Token GitHub",
361
+ type="password",
362
+ placeholder="Klik icon (?) untuk panduan"
363
+ )
364
+ with gr.Column(scale=1):
365
+ branch = gr.Textbox(
366
+ label="Branch (opsional)",
367
+ placeholder="main"
368
+ )
369
+
370
+ clone_button = gr.Button(
371
+ "πŸ”„ Clone Repository",
372
+ variant="primary"
373
  )
374
+
375
+ clone_status = gr.Markdown(
376
+ value="",
377
+ label="Status Repository"
378
+ )
379
+
380
+ # File Selection
381
+ with gr.Group():
382
+ gr.Markdown("### πŸ“Ž File yang Dipilih")
383
+
384
+ with gr.Row():
385
+ file_selector = gr.Dropdown(
386
+ label="Pilih File dari Repository",
387
+ choices=[],
388
+ multiselect=True,
389
+ value=[] # Initialize with empty list
390
+ )
391
+
392
+ file_list = gr.HTML(
393
+ value="<div class='file-list'>Belum ada file yang dipilih</div>",
394
+ label="Daftar File Terpilih"
395
+ )
396
+
397
+ # Chat Interface
398
+ with gr.Group():
399
+ chat_history = gr.Chatbot(
400
+ label="πŸ“ Riwayat Chat",
401
+ height=500,
402
+ show_label=True,
403
+ type="messages" # Fix deprecation warning
404
+ )
405
+
406
+ with gr.Row():
407
+ chat_input = gr.Textbox(
408
+ label="πŸ’­ Tanyakan tentang Repository",
409
+ placeholder="Ketik pertanyaan Anda di sini...",
410
+ lines=3
411
+ )
412
+ send_button = gr.Button("πŸ“€ Kirim", variant="primary")
413
+
414
+ loading_indicator = gr.HTML(
415
+ '<div id="loading" style="display:none">Memproses permintaan...</div>'
416
+ )
417
 
418
+ # Event Handlers
419
+ def handle_clone(repo_url, github_token, branch):
420
+ if not repo_url:
421
+ return "⚠️ URL repository diperlukan!", [], []
 
 
 
422
 
423
+ success, message = analyzer.clone_repository(repo_url, github_token, branch)
424
+
425
+ if success:
426
+ # Get list of files from cloned repository
427
+ files = sorted(list(analyzer.repo_content.keys())) # Sort files alphabetically
428
+ return message, files, []
429
+
430
+ return message, [], []
431
+
432
+ def update_file_list(selected):
433
+ if not selected:
434
+ return "<div class='file-list'>Belum ada file yang dipilih</div>"
435
+
436
+ html = "<div class='file-list'>"
437
+ for file in selected:
438
+ html += f"<div class='file-item'><span>{file}</span></div>"
439
+ html += "</div>"
440
+ return html
441
+
442
+ def update_model_list(provider_choice):
443
+ if provider_choice == AIProvider.XAI:
444
+ return gr.Dropdown(choices=XAI_MODELS, value="grok-2-latest")
445
+ elif provider_choice == AIProvider.GEMINI:
446
+ return gr.Dropdown(choices=GEMINI_MODELS, value="gemini-1.5-mini")
447
+ else: # OLLAMA
448
+ return gr.Dropdown(choices=OLLAMA_MODELS, value="llama2")
449
+
450
+ # Connect Events
451
+ provider.change(
452
+ fn=update_model_list,
453
+ inputs=[provider],
454
+ outputs=[model_dropdown]
455
+ )
456
+
457
+ clone_button.click(
458
+ fn=handle_clone,
459
+ inputs=[repo_url, github_token, branch],
460
+ outputs=[clone_status, file_selector, file_list]
461
+ )
462
+
463
+ file_selector.change(
464
+ fn=update_file_list,
465
+ inputs=[file_selector],
466
+ outputs=[file_list]
467
+ )
468
 
469
  with gr.Tab("πŸ“Š Analisis Repository", elem_classes="mobile-full"):
470
  with gr.Group():