JawadBenali commited on
Commit
e2361a1
Β·
1 Parent(s): 2bbf57d

Initial deployment - ArchitectAI MCP

Browse files
Files changed (1) hide show
  1. app.py +100 -1
app.py CHANGED
@@ -64,7 +64,47 @@ class LLMClientSingleton:
64
 
65
  _llm_singleton = LLMClientSingleton()
66
 
67
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  def process_zip_upload(zip_path, progress=gr.Progress()):
69
  """TAB 2: Extract ZIP and analyze project"""
70
  if not zip_path:
@@ -538,6 +578,65 @@ with gr.Blocks(
538
  inputs=proposal_input,
539
  outputs=[proposal_output, text_output_3, img_output_3, status_banner_3]
540
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
 
542
  # === TAB 4: MODAL CLOUD EXECUTION ===
543
  with gr.Tab("☁️ Safe Refactoring (Modal)", id=3):
 
64
 
65
  _llm_singleton = LLMClientSingleton()
66
 
67
+ def process_proposal_zip(zip_path, progress=gr.Progress()):
68
+ """TAB 3: AI Proposal from ZIP"""
69
+ if not zip_path:
70
+ return "⚠️ Please upload a ZIP file.", None, None, gr.update(visible=True, value="⚠️ No File")
71
+
72
+ try:
73
+ temp_dir = tempfile.mkdtemp()
74
+
75
+ progress(0.2, desc="Extracting ZIP...")
76
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
77
+ zip_ref.extractall(temp_dir)
78
+
79
+ progress(0.5, desc="AI analyzing architecture...")
80
+ analyzer = ProjectAnalyzer(Path(temp_dir))
81
+ structure = analyzer.analyze()
82
+
83
+ if not structure:
84
+ shutil.rmtree(temp_dir)
85
+ return "⚠️ No code found.", None, None, gr.update(visible=True, value="⚠️ No Code")
86
+
87
+ advisor = RefactoringAdvisor()
88
+ proposal = advisor.propose_improvement(structure)
89
+
90
+ if "error" in proposal:
91
+ shutil.rmtree(temp_dir)
92
+ return f"❌ AI Error: {proposal['error']}", None, None, gr.update(visible=True, value="❌ AI Failed")
93
+
94
+ progress(0.8, desc="Generating proposed UML...")
95
+ puml_code = proposal.get("proposed_uml", "")
96
+ _, image = render_plantuml(puml_code)
97
+
98
+ shutil.rmtree(temp_dir)
99
+ progress(1.0, desc="Complete!")
100
+
101
+ return json.dumps(proposal, indent=2), puml_code, image, gr.update(visible=True, value="βœ… Proposal Generated")
102
+
103
+ except Exception as e:
104
+ if 'temp_dir' in locals():
105
+ shutil.rmtree(temp_dir)
106
+ return f"❌ Error: {e}", None, None, gr.update(visible=True, value="❌ Failed")
107
+
108
  def process_zip_upload(zip_path, progress=gr.Progress()):
109
  """TAB 2: Extract ZIP and analyze project"""
110
  if not zip_path:
 
578
  inputs=proposal_input,
579
  outputs=[proposal_output, text_output_3, img_output_3, status_banner_3]
580
  )
581
+ # === TAB 3: AI PROPOSAL ===
582
+ with gr.Tab("✨ AI Refactoring Proposal", id=2):
583
+ gr.Markdown("""
584
+ ### Intelligent Architecture Recommendations
585
+ Let AI analyze your codebase and suggest design pattern improvements.
586
+ """)
587
+
588
+ gr.HTML("""
589
+ <div class="info-card">
590
+ <strong>🧠 AI-Powered:</strong> Detects anti-patterns like God Objects,
591
+ suggests appropriate design patterns (Strategy, Factory, Singleton, etc.),
592
+ and generates before/after UML diagrams.
593
+ </div>
594
+ """)
595
+
596
+ with gr.Row():
597
+ with gr.Column(scale=1):
598
+ proposal_zip = gr.File(
599
+ label="πŸ“¦ Upload Project (ZIP)",
600
+ file_types=[".zip"],
601
+ type="filepath"
602
+ )
603
+
604
+ propose_btn = gr.Button(
605
+ "🧠 Generate Proposal",
606
+ variant="primary",
607
+ size="lg",
608
+ elem_classes=["primary-button"]
609
+ )
610
+
611
+ status_banner_3 = gr.Markdown(visible=False, elem_classes=["banner"])
612
+
613
+ with gr.Group():
614
+ proposal_output = gr.Code(
615
+ language="json",
616
+ label="πŸ“‹ AI Analysis & Recommendations",
617
+ lines=15,
618
+ )
619
+
620
+ with gr.Column(scale=1):
621
+ with gr.Group():
622
+ img_output_3 = gr.Image(
623
+ label="🎨 Proposed Architecture (After Refactoring)",
624
+ type="pil",
625
+ elem_classes=["diagram-container"],
626
+ )
627
+
628
+ with gr.Accordion("πŸ“ Proposed PlantUML", open=False):
629
+ text_output_3 = gr.Code(
630
+ language="markdown",
631
+ label="PlantUML Code",
632
+ lines=10
633
+ )
634
+
635
+ propose_btn.click(
636
+ fn=process_proposal_zip,
637
+ inputs=proposal_zip,
638
+ outputs=[proposal_output, text_output_3, img_output_3, status_banner_3]
639
+ )
640
 
641
  # === TAB 4: MODAL CLOUD EXECUTION ===
642
  with gr.Tab("☁️ Safe Refactoring (Modal)", id=3):