Spaces:
Build error
Build error
Update app2.py
Browse files
app2.py
CHANGED
@@ -7,6 +7,10 @@ import subprocess
|
|
7 |
import git
|
8 |
import logging
|
9 |
|
|
|
|
|
|
|
|
|
10 |
# API Key Input
|
11 |
if "GOOGLE_API_KEY" not in st.session_state:
|
12 |
st.session_state.GOOGLE_API_KEY = ""
|
@@ -17,6 +21,7 @@ st.session_state.GOOGLE_API_KEY = st.text_input("API Key:", value=st.session_sta
|
|
17 |
# Initialize Google Search API Wrapper (only if API key is provided)
|
18 |
if st.session_state.GOOGLE_API_KEY:
|
19 |
search = GoogleSearchAPIWrapper(google_api_key=st.session_state.GOOGLE_API_KEY)
|
|
|
20 |
# Agents
|
21 |
agents = {
|
22 |
"WEB_DEV": {
|
@@ -108,7 +113,6 @@ if st.session_state.GOOGLE_API_KEY:
|
|
108 |
st.info("Starting autonomous build process...")
|
109 |
for agent in selected_agents:
|
110 |
st.write(f"Agent {agent} is working on the project...")
|
111 |
-
# More specific prompt for code generation
|
112 |
prompt = f"Generate Python code for a simple web application using Flask framework in project {project_name}. Include instructions for running the application."
|
113 |
code = get_agent_response(prompt, agents[agent]['system_prompt'])
|
114 |
add_code_to_workspace(project_name, code, f"{agent.lower()}_app.py")
|
@@ -141,44 +145,43 @@ if st.session_state.GOOGLE_API_KEY:
|
|
141 |
if project_name and project_name not in st.session_state.workspace_projects:
|
142 |
st.session_state.workspace_projects[project_name] = {'files': []}
|
143 |
st.success(f"Created project: {project_name}")
|
144 |
-
|
145 |
-
os.makedirs(project_name, exist_ok=True)
|
146 |
elif project_name in st.session_state.workspace_projects:
|
147 |
st.warning(f"Project {project_name} already exists")
|
148 |
else:
|
149 |
st.warning("Please enter a project name")
|
150 |
|
151 |
# Code Editor
|
152 |
-
st.subheader("Code Editor")
|
153 |
-
if st.session_state.workspace_projects:
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
file['
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
else:
|
174 |
-
st.info("No projects created yet. Create a project to start coding.")
|
175 |
else:
|
176 |
st.info("No projects created yet. Create a project to start coding.")
|
177 |
|
178 |
# Terminal Interface
|
179 |
st.subheader("Terminal (Workspace Context)")
|
180 |
if st.session_state.workspace_projects:
|
181 |
-
selected_project = st.selectbox("Select project for terminal",
|
|
|
|
|
182 |
terminal_input = st.text_input("Enter a command within the workspace:")
|
183 |
if st.button("Run Command"):
|
184 |
terminal_output = terminal_interface(terminal_input, selected_project)
|
@@ -239,7 +242,9 @@ else:
|
|
239 |
|
240 |
# Collaborative Agent Example
|
241 |
st.subheader("Collaborative Agent Example")
|
242 |
-
collab_agents = st.multiselect("Select AI agents for collaboration",
|
|
|
|
|
243 |
collab_project = st.text_input("Enter project name for collaboration:")
|
244 |
collab_task = st.text_input("Enter collaborative task:")
|
245 |
if st.button("Start Collaborative Task"):
|
@@ -249,4 +254,4 @@ else:
|
|
249 |
st.warning("Please select agents, enter a project name, and a task.")
|
250 |
|
251 |
else:
|
252 |
-
st.warning("Please enter your Google Search API Key to continue.")
|
|
|
7 |
import git
|
8 |
import logging
|
9 |
|
10 |
+
# Configure logging
|
11 |
+
logging.basicConfig(level=logging.INFO)
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
|
14 |
# API Key Input
|
15 |
if "GOOGLE_API_KEY" not in st.session_state:
|
16 |
st.session_state.GOOGLE_API_KEY = ""
|
|
|
21 |
# Initialize Google Search API Wrapper (only if API key is provided)
|
22 |
if st.session_state.GOOGLE_API_KEY:
|
23 |
search = GoogleSearchAPIWrapper(google_api_key=st.session_state.GOOGLE_API_KEY)
|
24 |
+
|
25 |
# Agents
|
26 |
agents = {
|
27 |
"WEB_DEV": {
|
|
|
113 |
st.info("Starting autonomous build process...")
|
114 |
for agent in selected_agents:
|
115 |
st.write(f"Agent {agent} is working on the project...")
|
|
|
116 |
prompt = f"Generate Python code for a simple web application using Flask framework in project {project_name}. Include instructions for running the application."
|
117 |
code = get_agent_response(prompt, agents[agent]['system_prompt'])
|
118 |
add_code_to_workspace(project_name, code, f"{agent.lower()}_app.py")
|
|
|
145 |
if project_name and project_name not in st.session_state.workspace_projects:
|
146 |
st.session_state.workspace_projects[project_name] = {'files': []}
|
147 |
st.success(f"Created project: {project_name}")
|
148 |
+
os.makedirs(project_name, exist_ok=True)
|
|
|
149 |
elif project_name in st.session_state.workspace_projects:
|
150 |
st.warning(f"Project {project_name} already exists")
|
151 |
else:
|
152 |
st.warning("Please enter a project name")
|
153 |
|
154 |
# Code Editor
|
155 |
+
st.subheader("Code Editor")
|
156 |
+
if st.session_state.workspace_projects:
|
157 |
+
selected_project = st.selectbox("Select project", list(st.session_state.workspace_projects.keys()))
|
158 |
+
if selected_project:
|
159 |
+
files = [file['file_name'] for file in st.session_state.workspace_projects[selected_project]['files']]
|
160 |
+
selected_file = st.selectbox("Select file to edit", files) if files else None
|
161 |
+
if selected_file:
|
162 |
+
file_content = next((file['code'] for file in st.session_state.workspace_projects[selected_project]['files']
|
163 |
+
if file['file_name'] == selected_file), "")
|
164 |
+
edited_code = st.text_area("Edit code", value=file_content, height=300)
|
165 |
+
if st.button("Save Changes"):
|
166 |
+
for file in st.session_state.workspace_projects[selected_project]['files']:
|
167 |
+
if file['file_name'] == selected_file:
|
168 |
+
file['code'] = edited_code
|
169 |
+
file_path = os.path.join(selected_project, selected_file)
|
170 |
+
with open(file_path, "w") as f:
|
171 |
+
f.write(edited_code)
|
172 |
+
st.success("Changes saved successfully!")
|
173 |
+
break
|
174 |
+
else:
|
175 |
+
st.info("No files in the project. Use the chat interface to generate code.")
|
|
|
|
|
176 |
else:
|
177 |
st.info("No projects created yet. Create a project to start coding.")
|
178 |
|
179 |
# Terminal Interface
|
180 |
st.subheader("Terminal (Workspace Context)")
|
181 |
if st.session_state.workspace_projects:
|
182 |
+
selected_project = st.selectbox("Select project for terminal",
|
183 |
+
list(st.session_state.workspace_projects.keys()),
|
184 |
+
key="terminal_project_select")
|
185 |
terminal_input = st.text_input("Enter a command within the workspace:")
|
186 |
if st.button("Run Command"):
|
187 |
terminal_output = terminal_interface(terminal_input, selected_project)
|
|
|
242 |
|
243 |
# Collaborative Agent Example
|
244 |
st.subheader("Collaborative Agent Example")
|
245 |
+
collab_agents = st.multiselect("Select AI agents for collaboration",
|
246 |
+
list(agents.keys()),
|
247 |
+
key="collab_agent_select")
|
248 |
collab_project = st.text_input("Enter project name for collaboration:")
|
249 |
collab_task = st.text_input("Enter collaborative task:")
|
250 |
if st.button("Start Collaborative Task"):
|
|
|
254 |
st.warning("Please select agents, enter a project name, and a task.")
|
255 |
|
256 |
else:
|
257 |
+
st.warning("Please enter your Google Search API Key to continue.")
|