|
|
|
|
|
|
|
""" |
|
Gradio Application for Code Review Agent |
|
|
|
This module defines the Gradio web interface for the Code Review Agent. |
|
It creates a professional UI with components for repository input, language selection, |
|
progress tracking, and results display. |
|
""" |
|
|
|
import os |
|
import gradio as gr |
|
import logging |
|
|
|
from src.ui.components.repo_input import create_repo_input |
|
from src.ui.components.language_selector import create_language_selector |
|
from src.ui.components.progress_tracker import create_progress_tracker |
|
from src.ui.components.results_dashboard import create_results_dashboard |
|
from src.ui.components.export_manager import create_export_manager |
|
from src.ui.styles.themes import get_theme |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
def create_gradio_app(agent_manager): |
|
""" |
|
Create and configure the Gradio application. |
|
|
|
Args: |
|
agent_manager: The AgentManager instance that handles the business logic. |
|
|
|
Returns: |
|
gr.Blocks: The configured Gradio application. |
|
""" |
|
|
|
css_path = os.path.join(os.path.dirname(__file__), 'styles', 'custom.css') |
|
with open(css_path, 'r') as f: |
|
custom_css = f.read() |
|
|
|
|
|
theme = get_theme() |
|
|
|
with gr.Blocks(css=custom_css, theme=theme, title="Code Review Agent") as app: |
|
gr.Markdown( |
|
""" |
|
# π Professional Code Review Agent |
|
|
|
Upload a GitHub repository URL and get comprehensive code analysis with actionable recommendations. |
|
""" |
|
) |
|
|
|
with gr.Row(): |
|
with gr.Column(scale=3): |
|
|
|
repo_url, github_token, submit_btn = create_repo_input() |
|
|
|
|
|
selected_languages = create_language_selector() |
|
|
|
with gr.Column(scale=1): |
|
|
|
gr.Markdown( |
|
""" |
|
### π Features |
|
- Multi-language support (15+ languages) |
|
- Security vulnerability detection |
|
- Performance analysis |
|
- Code quality metrics |
|
- Actionable recommendations |
|
""" |
|
) |
|
|
|
|
|
with gr.Group(visible=False) as progress_group: |
|
gr.Markdown("### β³ Analysis Progress") |
|
overall_progress, status_message, step_progress = create_progress_tracker() |
|
|
|
|
|
results_dashboard = create_results_dashboard() |
|
|
|
|
|
export_buttons = create_export_manager() |
|
|
|
|
|
def start_review_with_progress(repo_url, github_token, selected_languages): |
|
|
|
|
|
progress_group.visible = True |
|
results_dashboard.visible = False |
|
|
|
|
|
progress_components = (progress_group, overall_progress, status_message, step_progress) |
|
try: |
|
_, _, _, results = agent_manager.start_review(repo_url, github_token, selected_languages, progress_components) |
|
|
|
|
|
progress_group.visible = False |
|
results_dashboard.visible = True |
|
|
|
return [ |
|
0, |
|
"*Analysis complete!*", |
|
results |
|
] |
|
except Exception as e: |
|
|
|
return [ |
|
0, |
|
f"*Error: {str(e)}*", |
|
results_dashboard |
|
] |
|
|
|
submit_btn.click( |
|
fn=start_review_with_progress, |
|
inputs=[repo_url, github_token, selected_languages], |
|
outputs=[overall_progress, status_message, results_dashboard] |
|
) |
|
|
|
for export_btn, export_format in export_buttons: |
|
export_btn.click( |
|
fn=agent_manager.export_report, |
|
inputs=[results_dashboard, export_format], |
|
outputs=[] |
|
) |
|
|
|
|
|
app.queue() |
|
|
|
return app |