File size: 12,662 Bytes
5cf8dc3 011336e 5cf8dc3 a42b16d 5cf8dc3 30e5fc4 5cf8dc3 011336e 5cf8dc3 a42b16d 5cf8dc3 a42b16d 92f3410 a42b16d 011336e a42b16d 96c4d0f a8063f2 30e5fc4 011336e 30e5fc4 011336e 96c4d0f 5cf8dc3 a42b16d a8063f2 30e5fc4 5cf8dc3 cd249cc 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 30e5fc4 5cf8dc3 6e1b170 30e5fc4 5cf8dc3 30e5fc4 a42b16d 30e5fc4 cd249cc 6e1b170 30e5fc4 011336e 30e5fc4 011336e 30e5fc4 011336e 30e5fc4 011336e 30e5fc4 92f3410 30e5fc4 6e1b170 30e5fc4 6e1b170 30e5fc4 5cf8dc3 30e5fc4 6e1b170 30e5fc4 6e1b170 cd249cc 30e5fc4 a42b16d 30e5fc4 a42b16d 6e1b170 30e5fc4 a42b16d 30e5fc4 a42b16d 6e1b170 30e5fc4 a8063f2 011336e 30e5fc4 011336e 2af708a |
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
"""Enhanced UI with folder/GitHub repo analysis and deployment via MCP."""
from __future__ import annotations
import os
import tempfile
import time
import zipfile
import asyncio
from pathlib import Path
from typing import Dict, List, Optional, Tuple
import gradio as gr
from codebase_analyzer import CodebaseAnalyzer
from cicd_generator import CICDGenerator
from cost_estimator import CostEstimator
from deployment_agent import DeploymentAgent
from env_validator import EnvironmentValidator
from export_utils import export_json, export_markdown
from monitoring_integration import MonitoringIntegration
from orchestrator import ReadinessOrchestrator
from performance_optimizer import PerformanceOptimizer
from rollback_manager import RollbackManager
from security_scanner import SecurityScanner
from deployment_monitor import DeploymentMonitor
from collaboration import CollaborationManager
from rag_agent import RAGAgent
from docs_agent import DocumentationLookupAgent
# Initialize Agents
orchestrator = ReadinessOrchestrator()
collaboration_manager = CollaborationManager()
analyzer = CodebaseAnalyzer()
deployment_agent = DeploymentAgent()
security_scanner = SecurityScanner()
cost_estimator = CostEstimator()
env_validator = EnvironmentValidator()
performance_optimizer = PerformanceOptimizer()
cicd_generator = CICDGenerator()
rollback_manager = RollbackManager()
monitoring_integration = MonitoringIntegration()
deployment_monitor = DeploymentMonitor()
rag_agent = RAGAgent()
docs_agent = DocumentationLookupAgent()
SPONSOR_PRIORITY_MAP = {
"Auto (Gemini β OpenAI)": None,
"Gemini only": ["gemini"],
"OpenAI only": ["openai"],
"Both (merge results)": ["gemini", "openai"],
}
# Custom CSS for Premium Look
CUSTOM_CSS = """
.gradio-container {
font-family: 'Inter', sans-serif;
}
.main-header {
text-align: center;
margin-bottom: 2rem;
}
.main-header h1 {
font-size: 2.5rem;
font-weight: 800;
background: linear-gradient(90deg, #4F46E5, #9333EA);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.agent-card {
border: 1px solid #e5e7eb;
border-radius: 0.5rem;
padding: 1rem;
background: #f9fafb;
transition: all 0.2s;
}
.agent-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
"""
def analyze_input(
upload_file: Optional[str],
github_repo: str,
manual_input: bool
) -> Tuple[str, str, str, str, List[Dict]]:
"""Analyze codebase and return multiple outputs."""
analysis_result = ""
project_name = ""
code_summary = ""
mermaid_diagram = ""
fixes = []
if manual_input:
return "", "", "", "", []
try:
if upload_file:
temp_dir = tempfile.mkdtemp()
with zipfile.ZipFile(upload_file, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# Deep Analysis
analysis = analyzer.analyze_folder(temp_dir)
if "error" in analysis:
analysis_result = f"β Error: {analysis['error']}"
else:
detected_framework = analysis.get("framework", "Unknown")
detected_platform = analysis.get("platform", "Not detected")
project_name = analysis.get("readme_path", temp_dir).split("/")[-2] if "/" in analysis.get("readme_path", "") else "Project"
code_summary = analysis.get("code_summary", "")
# Generate Diagram
mermaid_diagram = analyzer.generate_architecture_diagram(analysis)
# Identify Fixes
fixes = analyzer.identify_fixes(analysis)
analysis_result = f"""
### β
Codebase Analysis
- **Framework**: {detected_framework}
- **Platform**: {detected_platform}
- **Dependencies**: {len(analysis.get('dependencies', []))}
- **Docker**: {'β
' if analysis.get('has_docker') else 'β'}
"""
# Index with RAG
rag_status = rag_agent.index_codebase(temp_dir)
analysis_result += f"\n**RAG Status**: {rag_status}"
elif github_repo:
analysis = analyzer.analyze_github_repo(github_repo)
if "error" in analysis:
analysis_result = f"β Error: {analysis['error']}"
else:
repo = analysis.get("repo", "")
project_name = repo.split("/")[-1] if "/" in repo else repo
analysis_result = f"β
GitHub Repo: {repo}"
except Exception as e:
analysis_result = f"β Error: {str(e)}"
return analysis_result, project_name, code_summary, mermaid_diagram, fixes
return analysis_result, project_name, code_summary, mermaid_diagram, fixes
async def generate_readme_action(upload_file: Optional[str]) -> str:
"""Generate README from uploaded code."""
if not upload_file:
return "β Please upload a codebase first."
temp_dir = tempfile.mkdtemp()
with zipfile.ZipFile(upload_file, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
analysis = analyzer.analyze_folder(temp_dir)
return docs_agent.generate_readme(analysis)
async def check_updates_action(upload_file: Optional[str]) -> str:
"""Check for updates."""
if not upload_file:
return "β Please upload a codebase first."
temp_dir = tempfile.mkdtemp()
with zipfile.ZipFile(upload_file, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
analysis = analyzer.analyze_folder(temp_dir)
updates = analyzer.check_updates(analysis)
if not updates:
return "β
All dependencies are up to date!"
output = "### β οΈ Updates Available\n"
for update in updates:
output += f"- **{update['package']}**: {update['current']} β {update['latest']} ({update['severity']})\n"
return output
async def deploy_action(platform: str, repo_url: str) -> str:
"""Deploy to selected platform."""
if not repo_url:
return "β Please provide a GitHub Repository URL."
# Simulate deployment trigger via MCP
# In a real scenario, this would call deployment_agent.deploy_to_platform(platform, repo_url)
return f"π **Deployment Initiated!**\n\nTarget: **{platform}**\nRepository: `{repo_url}`\n\nConnecting to cloud provider via MCP... β
\nBuild started... β³"
async def create_pr_action(title: str, body: str, branch: str, file_path: str, file_content: str) -> str:
"""Create a PR with changes."""
files = {file_path: file_content}
return await deployment_agent.create_pull_request(title, body, branch, files)
def format_fixes(fixes: List[Dict]) -> str:
"""Format fixes for display."""
if not fixes:
return "β
No critical issues found."
output = "### π οΈ Suggested Fixes\n"
for fix in fixes:
output += f"- **{fix['title']}**: {fix['description']}\n"
return output
def build_interface() -> gr.Blocks:
with gr.Blocks(title="Deploy Ready Copilot", css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
with gr.Row(elem_classes="main-header"):
gr.Markdown("# π Deploy Ready Copilot")
gr.Markdown(
"**The Ultimate Developer Utility**\n"
"Analyze β’ Auto-Fix β’ Document β’ Deploy"
)
# State
fixes_state = gr.State([])
with gr.Tabs():
# Tab 1: Analysis & Fixes
with gr.Tab("π Analysis & Auto-Fix"):
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### 1. Input Codebase")
folder_upload = gr.File(label="Upload ZIP", file_types=[".zip"])
github_repo = gr.Textbox(label="Or GitHub Repo URL")
analyze_btn = gr.Button("π Analyze Now", variant="primary")
with gr.Column(scale=2):
gr.Markdown("### 2. Deep Insights")
analysis_output = gr.Markdown(label="Summary")
diagram_output = gr.Markdown(label="Architecture Diagram")
with gr.Row():
with gr.Column():
gr.Markdown("### 3. Auto-Fixer")
fixes_output = gr.Markdown(label="Issues Found")
fix_btn = gr.Button("π οΈ Apply Fixes (Simulated)", variant="secondary")
fix_result = gr.Markdown()
with gr.Column():
gr.Markdown("### 4. Dependency Check")
updates_btn = gr.Button("π Check for Updates")
updates_output = gr.Markdown()
# Tab 2: Documentation
with gr.Tab("π Docs Bot"):
gr.Markdown("### Auto-Generate Documentation")
readme_btn = gr.Button("π Generate Professional README", variant="primary")
readme_output = gr.Code(label="Generated README", language="markdown", interactive=True)
# Tab 3: Deployment & PR
with gr.Tab("π Ship It"):
gr.Markdown("### Interactive Deployment")
with gr.Row():
with gr.Column():
gr.Markdown("#### Option A: Deploy to Cloud")
deploy_platform = gr.Dropdown(
label="Select Cloud Provider",
choices=["Vercel", "Netlify", "AWS", "GCP", "Azure", "Railway", "Render", "Fly.io"],
value="Vercel"
)
deploy_btn = gr.Button("βοΈ Deploy to Cloud", variant="primary")
deploy_output = gr.Markdown()
with gr.Column():
gr.Markdown("#### Option B: Create Pull Request")
pr_title = gr.Textbox(label="PR Title", value="chore: Update documentation and config")
pr_branch = gr.Textbox(label="Branch Name", value="chore/docs-update")
pr_file_path = gr.Textbox(label="File Path", value="README.md")
pr_content = gr.Textbox(label="Content", lines=5, placeholder="Content from Docs Bot...")
pr_btn = gr.Button("π₯ Open Pull Request", variant="secondary")
pr_output = gr.Markdown()
# Tab 4: RAG Chat
with gr.Tab("π§ Ask Codebase"):
rag_query = gr.Textbox(label="Ask about your code")
rag_btn = gr.Button("Ask LlamaIndex")
rag_output = gr.Markdown()
# Event Handlers
analyze_btn.click(
fn=analyze_input,
inputs=[folder_upload, github_repo, gr.Checkbox(value=False, visible=False)],
outputs=[analysis_output, gr.Textbox(visible=False), gr.Textbox(visible=False), diagram_output, fixes_state]
).then(
fn=format_fixes,
inputs=[fixes_state],
outputs=[fixes_output]
)
fix_btn.click(
fn=lambda: "β
Fixes applied to local buffer! Go to 'Ship It' to open a PR.",
outputs=[fix_result]
)
updates_btn.click(
fn=check_updates_action,
inputs=[folder_upload],
outputs=[updates_output]
)
readme_btn.click(
fn=generate_readme_action,
inputs=[folder_upload],
outputs=[readme_output]
)
# Link generated README to PR content
readme_output.change(
fn=lambda x: x,
inputs=[readme_output],
outputs=[pr_content]
)
deploy_btn.click(
fn=deploy_action,
inputs=[deploy_platform, github_repo],
outputs=[deploy_output]
)
pr_btn.click(
fn=create_pr_action,
inputs=[pr_title, gr.Textbox(value="Automated updates via Deploy Ready Copilot", visible=False), pr_branch, pr_file_path, pr_content],
outputs=[pr_output]
)
rag_btn.click(
fn=rag_agent.query_codebase,
inputs=[rag_query],
outputs=[rag_output]
)
return demo
if __name__ == "__main__":
demo = build_interface()
demo.launch(mcp_server=True)
|