Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
π
|
| 306 |
""")
|
| 307 |
|
| 308 |
-
with gr.
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 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 |
-
|
| 327 |
-
label="
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
)
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
return gr.Dropdown(choices=GEMINI_MODELS, value="gemini-pro")
|
| 348 |
-
else: # OLLAMA
|
| 349 |
-
return gr.Dropdown(choices=OLLAMA_MODELS, value="llama2")
|
| 350 |
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 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():
|