Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
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. | |
""" | |
# Load custom CSS | |
css_path = os.path.join(os.path.dirname(__file__), 'styles', 'custom.css') | |
with open(css_path, 'r') as f: | |
custom_css = f.read() | |
# Create the Gradio app with custom theme | |
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): | |
# Repository input component | |
repo_url, github_token, submit_btn = create_repo_input() | |
# Language selector component | |
selected_languages = create_language_selector() | |
with gr.Column(scale=1): | |
# Information panel | |
gr.Markdown( | |
""" | |
### π Features | |
- Multi-language support (15+ languages) | |
- Security vulnerability detection | |
- Performance analysis | |
- Code quality metrics | |
- Actionable recommendations | |
""" | |
) | |
# Progress tracker component | |
with gr.Group(visible=False) as progress_group: | |
gr.Markdown("### β³ Analysis Progress") | |
overall_progress, status_message, step_progress = create_progress_tracker() | |
# Results dashboard component | |
results_dashboard = create_results_dashboard() | |
# Export options component | |
export_buttons = create_export_manager() | |
# Set up event handlers | |
submit_btn.click( | |
fn=agent_manager.start_review, | |
inputs=[repo_url, github_token, selected_languages], | |
outputs=[progress_group, 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=[] | |
) | |
# Add WebSocket for real-time updates | |
app.queue() | |
return app |