Spaces:
Sleeping
Sleeping
chore: improvement and naming
Browse files
app.py
CHANGED
|
@@ -184,7 +184,7 @@ class RepoAnalyzer:
|
|
| 184 |
return
|
| 185 |
|
| 186 |
genai.configure(api_key=api_key)
|
| 187 |
-
model = genai.GenerativeModel("gemini-
|
| 188 |
|
| 189 |
# Tambahkan konteks repository jika ada
|
| 190 |
if self.current_repo:
|
|
@@ -347,7 +347,7 @@ async def handle_chat(
|
|
| 347 |
):
|
| 348 |
full_response += chunk
|
| 349 |
# Add delay between chunks for readability
|
| 350 |
-
await asyncio.sleep(
|
| 351 |
history[-1]["content"] = full_response
|
| 352 |
yield history
|
| 353 |
|
|
@@ -357,7 +357,7 @@ async def handle_chat(
|
|
| 357 |
):
|
| 358 |
full_response += chunk
|
| 359 |
# Add delay between chunks for readability
|
| 360 |
-
await asyncio.sleep(0.
|
| 361 |
history[-1]["content"] = full_response
|
| 362 |
yield history
|
| 363 |
|
|
@@ -367,7 +367,7 @@ async def handle_chat(
|
|
| 367 |
words = response.split()
|
| 368 |
for i in range(len(words)):
|
| 369 |
full_response = " ".join(words[: i + 1])
|
| 370 |
-
await asyncio.sleep(0.
|
| 371 |
history[-1]["content"] = full_response
|
| 372 |
yield history
|
| 373 |
|
|
@@ -379,7 +379,7 @@ async def handle_chat(
|
|
| 379 |
def create_ui():
|
| 380 |
# Gunakan analyzer global
|
| 381 |
global analyzer
|
| 382 |
-
current_time = datetime.now().strftime("%Y-%m-%d %H:%M
|
| 383 |
|
| 384 |
with gr.Blocks(title="Open Repo AI", theme=gr.themes.Soft()) as app:
|
| 385 |
# CSS Styling
|
|
@@ -445,26 +445,25 @@ def create_ui():
|
|
| 445 |
gr.Markdown(f"""
|
| 446 |
# AI Github Repository Chat
|
| 447 |
|
| 448 |
-
|
| 449 |
-
π€ User: {CURRENT_USER}
|
| 450 |
""")
|
| 451 |
|
| 452 |
# Main Tabs Container
|
| 453 |
with gr.Tabs() as tabs:
|
| 454 |
# Configuration Tab
|
| 455 |
-
with gr.Tab("
|
| 456 |
provider = gr.Radio(
|
| 457 |
choices=[AIProvider.XAI, AIProvider.GEMINI, AIProvider.OLLAMA],
|
| 458 |
-
label="
|
| 459 |
value=AIProvider.XAI,
|
| 460 |
)
|
| 461 |
|
| 462 |
with gr.Group() as api_settings:
|
| 463 |
with gr.Row():
|
| 464 |
xai_key = gr.Textbox(
|
| 465 |
-
label="X.AI (Grok) API Key",
|
| 466 |
type="password",
|
| 467 |
-
placeholder="
|
| 468 |
show_label=True,
|
| 469 |
scale=3,
|
| 470 |
)
|
|
@@ -491,7 +490,7 @@ def create_ui():
|
|
| 491 |
)
|
| 492 |
|
| 493 |
# Repository Analysis Tab
|
| 494 |
-
with gr.Tab("
|
| 495 |
with gr.Group():
|
| 496 |
# Repository URL and Token inputs
|
| 497 |
with gr.Row():
|
|
@@ -504,9 +503,9 @@ def create_ui():
|
|
| 504 |
with gr.Row():
|
| 505 |
with gr.Column(scale=2):
|
| 506 |
github_token = gr.Textbox(
|
| 507 |
-
label="Token GitHub",
|
| 508 |
type="password",
|
| 509 |
-
placeholder="
|
| 510 |
elem_classes="mobile-full",
|
| 511 |
)
|
| 512 |
gr.Markdown(GITHUB_TOKEN_HELP)
|
|
@@ -517,9 +516,9 @@ def create_ui():
|
|
| 517 |
elem_classes="mobile-full",
|
| 518 |
)
|
| 519 |
|
| 520 |
-
|
| 521 |
clone_button = gr.Button(
|
| 522 |
-
"
|
| 523 |
variant="primary",
|
| 524 |
elem_classes="mobile-full",
|
| 525 |
)
|
|
@@ -548,7 +547,7 @@ def create_ui():
|
|
| 548 |
)
|
| 549 |
|
| 550 |
# Examples Tab
|
| 551 |
-
with gr.Tab("
|
| 552 |
example_output = gr.HTML(
|
| 553 |
value="Pilih file di tab Analisis Repository untuk melihat contoh pertanyaan.",
|
| 554 |
label="Contoh Pertanyaan",
|
|
@@ -557,8 +556,8 @@ def create_ui():
|
|
| 557 |
# Chat Interface (outside tabs)
|
| 558 |
with gr.Group():
|
| 559 |
chat_history = gr.Chatbot(
|
| 560 |
-
label="
|
| 561 |
-
height=
|
| 562 |
show_label=True,
|
| 563 |
type="messages",
|
| 564 |
elem_classes="mobile-full",
|
|
@@ -566,19 +565,19 @@ def create_ui():
|
|
| 566 |
|
| 567 |
with gr.Row():
|
| 568 |
chat_input = gr.Textbox(
|
| 569 |
-
label="
|
| 570 |
-
placeholder="Ketik
|
| 571 |
lines=3,
|
| 572 |
elem_classes="mobile-full",
|
| 573 |
)
|
| 574 |
-
send_button = gr.Button("
|
| 575 |
-
clear_button = gr.Button("
|
| 576 |
|
| 577 |
# Event Handlers
|
| 578 |
def handle_clone(repo_url, github_token, branch):
|
| 579 |
if not repo_url:
|
| 580 |
return (
|
| 581 |
-
"
|
| 582 |
gr.Dropdown(choices=[]),
|
| 583 |
"<div class='file-list'>Belum ada file yang dipilih</div>",
|
| 584 |
)
|
|
@@ -680,7 +679,7 @@ def create_ui():
|
|
| 680 |
examples += "</ul>"
|
| 681 |
|
| 682 |
examples += """
|
| 683 |
-
<h3>Tips
|
| 684 |
<ul>
|
| 685 |
<li>Gunakan pertanyaan yang spesifik dan fokus pada bagian tertentu</li>
|
| 686 |
<li>Sebutkan nama file jika bertanya tentang file tertentu</li>
|
|
|
|
| 184 |
return
|
| 185 |
|
| 186 |
genai.configure(api_key=api_key)
|
| 187 |
+
model = genai.GenerativeModel("gemini-1.5-mini")
|
| 188 |
|
| 189 |
# Tambahkan konteks repository jika ada
|
| 190 |
if self.current_repo:
|
|
|
|
| 347 |
):
|
| 348 |
full_response += chunk
|
| 349 |
# Add delay between chunks for readability
|
| 350 |
+
await asyncio.sleep(1)
|
| 351 |
history[-1]["content"] = full_response
|
| 352 |
yield history
|
| 353 |
|
|
|
|
| 357 |
):
|
| 358 |
full_response += chunk
|
| 359 |
# Add delay between chunks for readability
|
| 360 |
+
await asyncio.sleep(0.5)
|
| 361 |
history[-1]["content"] = full_response
|
| 362 |
yield history
|
| 363 |
|
|
|
|
| 367 |
words = response.split()
|
| 368 |
for i in range(len(words)):
|
| 369 |
full_response = " ".join(words[: i + 1])
|
| 370 |
+
await asyncio.sleep(0.5)
|
| 371 |
history[-1]["content"] = full_response
|
| 372 |
yield history
|
| 373 |
|
|
|
|
| 379 |
def create_ui():
|
| 380 |
# Gunakan analyzer global
|
| 381 |
global analyzer
|
| 382 |
+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 383 |
|
| 384 |
with gr.Blocks(title="Open Repo AI", theme=gr.themes.Soft()) as app:
|
| 385 |
# CSS Styling
|
|
|
|
| 445 |
gr.Markdown(f"""
|
| 446 |
# AI Github Repository Chat
|
| 447 |
|
| 448 |
+
- Current Date and Time (UTC): {current_time}
|
|
|
|
| 449 |
""")
|
| 450 |
|
| 451 |
# Main Tabs Container
|
| 452 |
with gr.Tabs() as tabs:
|
| 453 |
# Configuration Tab
|
| 454 |
+
with gr.Tab("Konfigurasi"):
|
| 455 |
provider = gr.Radio(
|
| 456 |
choices=[AIProvider.XAI, AIProvider.GEMINI, AIProvider.OLLAMA],
|
| 457 |
+
label="AI Providers",
|
| 458 |
value=AIProvider.XAI,
|
| 459 |
)
|
| 460 |
|
| 461 |
with gr.Group() as api_settings:
|
| 462 |
with gr.Row():
|
| 463 |
xai_key = gr.Textbox(
|
| 464 |
+
label="X.AI (Grok) API Key (opsional)",
|
| 465 |
type="password",
|
| 466 |
+
placeholder="Memakai Apikey Kamu Sendiri",
|
| 467 |
show_label=True,
|
| 468 |
scale=3,
|
| 469 |
)
|
|
|
|
| 490 |
)
|
| 491 |
|
| 492 |
# Repository Analysis Tab
|
| 493 |
+
with gr.Tab("Analisis Repository"):
|
| 494 |
with gr.Group():
|
| 495 |
# Repository URL and Token inputs
|
| 496 |
with gr.Row():
|
|
|
|
| 503 |
with gr.Row():
|
| 504 |
with gr.Column(scale=2):
|
| 505 |
github_token = gr.Textbox(
|
| 506 |
+
label="Token GitHub (opsional)",
|
| 507 |
type="password",
|
| 508 |
+
placeholder="Masukkan github token jika repo private",
|
| 509 |
elem_classes="mobile-full",
|
| 510 |
)
|
| 511 |
gr.Markdown(GITHUB_TOKEN_HELP)
|
|
|
|
| 516 |
elem_classes="mobile-full",
|
| 517 |
)
|
| 518 |
|
| 519 |
+
|
| 520 |
clone_button = gr.Button(
|
| 521 |
+
"Analisa Repo",
|
| 522 |
variant="primary",
|
| 523 |
elem_classes="mobile-full",
|
| 524 |
)
|
|
|
|
| 547 |
)
|
| 548 |
|
| 549 |
# Examples Tab
|
| 550 |
+
with gr.Tab("Ide Cepat"):
|
| 551 |
example_output = gr.HTML(
|
| 552 |
value="Pilih file di tab Analisis Repository untuk melihat contoh pertanyaan.",
|
| 553 |
label="Contoh Pertanyaan",
|
|
|
|
| 556 |
# Chat Interface (outside tabs)
|
| 557 |
with gr.Group():
|
| 558 |
chat_history = gr.Chatbot(
|
| 559 |
+
label="Open Repo AI Assistant",
|
| 560 |
+
height=300,
|
| 561 |
show_label=True,
|
| 562 |
type="messages",
|
| 563 |
elem_classes="mobile-full",
|
|
|
|
| 565 |
|
| 566 |
with gr.Row():
|
| 567 |
chat_input = gr.Textbox(
|
| 568 |
+
label="Chat Dengan Repository",
|
| 569 |
+
placeholder="Ketik di sini...",
|
| 570 |
lines=3,
|
| 571 |
elem_classes="mobile-full",
|
| 572 |
)
|
| 573 |
+
send_button = gr.Button("Kirim", variant="primary")
|
| 574 |
+
clear_button = gr.Button("Bersihkan", variant="secondary")
|
| 575 |
|
| 576 |
# Event Handlers
|
| 577 |
def handle_clone(repo_url, github_token, branch):
|
| 578 |
if not repo_url:
|
| 579 |
return (
|
| 580 |
+
"URL repository diperlukan!",
|
| 581 |
gr.Dropdown(choices=[]),
|
| 582 |
"<div class='file-list'>Belum ada file yang dipilih</div>",
|
| 583 |
)
|
|
|
|
| 679 |
examples += "</ul>"
|
| 680 |
|
| 681 |
examples += """
|
| 682 |
+
<h3>Tips:</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>
|