File size: 3,452 Bytes
aa300a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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