-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
147 lines (112 loc) Β· 5.19 KB
/
ui.py
File metadata and controls
147 lines (112 loc) Β· 5.19 KB
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
import streamlit as st
import os
from blackboard import Blackboard
from agents.analyst import AnalystAgent
from agents.architect import ArchitectAgent
from agents.frontend import FrontendDeveloperAgent
from agents.backend import BackendDeveloperAgent
from agents.reviewer import CodeReviewerAgent
from agents.cleaner import CleanerAgent
from agents.tester import TesterAgent
MAX_CYCLES = 5
def detect_language(filename):
if filename.endswith(".py"):
return "python"
elif filename.endswith(".js"):
return "javascript"
elif filename.endswith(".html"):
return "html"
elif filename.endswith(".css"):
return "css"
else:
return ""
def display_code(folder_path, label):
if not os.path.exists(folder_path):
st.write(f"π **No {label} files found in `{folder_path}`.**")
return
for root, _, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
if any(file.endswith(ext) for ext in [".py", ".html", ".css", ".js"]):
with open(file_path, "r") as f:
content = f.read()
st.write(f"##### π {label} File: `{os.path.basename(file_path)}`")
st.code(content, language=detect_language(file))
def run_agents(goal):
blackboard = Blackboard(goal)
def log_ui(msg):
st.write(msg)
agents = {
"Analyst": AnalystAgent(blackboard, log=log_ui),
"Architect": ArchitectAgent(blackboard, log=log_ui),
"Frontend Developer": FrontendDeveloperAgent(blackboard, log=log_ui),
"Backend Developer": BackendDeveloperAgent(blackboard, log=log_ui),
"Reviewer": CodeReviewerAgent(blackboard, log=log_ui),
"Cleaner": CleanerAgent(blackboard, log=log_ui),
"Tester": TesterAgent(blackboard, log=log_ui),
}
with st.expander("π Analyst Agent"):
agents["Analyst"].act()
with st.expander("π Architect Agent"):
agents["Architect"].act()
for cycle in range(1, MAX_CYCLES + 1):
st.subheader(f"=== Cycle {cycle} ===")
if not blackboard.get("frontend_review_passed"):
with st.expander("π¨ Frontend Developer"):
frontend_file = agents["Frontend Developer"].act()
if frontend_file and os.path.exists(frontend_file):
with open(frontend_file, "r") as f:
code = f.read()
st.code(code, language="html")
if not blackboard.get("backend_review_passed"):
with st.expander("π§ Backend Developer"):
backend_file = agents["Backend Developer"].act()
if backend_file and os.path.exists(backend_file):
with open(backend_file, "r") as f:
code = f.read()
st.code(code, language=detect_language(backend_file))
with st.expander("π Code Reviewer"):
agents["Reviewer"].act()
frontend_passed = blackboard.get("frontend_review_passed")
backend_passed = blackboard.get("backend_review_passed")
frontend_needed = blackboard.get("frontend_needed")
backend_needed = blackboard.get("backend_needed")
# FRONTEND ONLY
if frontend_passed and frontend_needed and not backend_needed:
with st.expander("π§Ή Cleaner - Frontend"):
agents["Cleaner"].act()
display_code("cleaned/frontend", "Frontend")
st.success("π Frontend complete. No backend required. Exiting.")
return
# BACKEND ONLY
if backend_passed and backend_needed and not frontend_needed:
with st.expander("π§Ή Cleaner - Backend"):
agents["Cleaner"].act()
display_code("cleaned/backend", "Backend")
with st.expander("π§ͺ Tester Agent"):
agents["Tester"].act()
display_code("generated/tests", "Generated Tests")
st.success("π Backend complete. No frontend required. Exiting.")
return
# BOTH FRONTEND AND BACKEND
if frontend_passed and backend_passed:
st.success("β
Both Frontend and Backend code passed review!")
with st.expander("π§Ή Final Cleaning"):
agents["Cleaner"].act()
display_code("cleaned/frontend", "Final Cleaned Frontend")
display_code("cleaned/backend", "Final Cleaned Backend")
with st.expander("π§ͺ Final Testing"):
agents["Tester"].act()
display_code("generated/tests", "Final Generated Tests")
st.success("π Process complete with code reviewed, cleaned, and tested.")
return
st.warning("β οΈ Maximum cycles reached. Some components may still need improvements.")
# Streamlit UI
st.set_page_config("AI Software Dev Pipeline", page_icon="π€", layout="wide")
st.title("π€ AI Multi-Agent Software Development")
goal_input = st.text_area("Enter your software goal (include frontend/backend needs):")
if st.button("π Run Agents"):
if goal_input.strip():
run_agents(goal_input)
else:
st.warning("Please enter a valid software goal to start the process.")