acecalisto3 commited on
Commit
c7f6047
1 Parent(s): 0c763b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -38
app.py CHANGED
@@ -1,16 +1,17 @@
1
- import streamlit as st
2
  import os
 
3
  import subprocess
 
4
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
5
  import black
6
  from pylint import lint
7
  from io import StringIO
8
  import openai
9
- import sys
10
 
11
  # Set your OpenAI API key here
12
  openai.api_key = "YOUR_OPENAI_API_KEY"
13
 
 
14
  PROJECT_ROOT = "projects"
15
  AGENT_DIRECTORY = "agents"
16
 
@@ -23,6 +24,11 @@ if 'workspace_projects' not in st.session_state:
23
  st.session_state.workspace_projects = {}
24
  if 'available_agents' not in st.session_state:
25
  st.session_state.available_agents = []
 
 
 
 
 
26
 
27
  class AIAgent:
28
  def __init__(self, name, description, skills):
@@ -52,14 +58,19 @@ I am confident that I can leverage my expertise to assist you in developing and
52
  return summary, next_step
53
 
54
  def save_agent_to_file(agent):
55
- """Saves the agent's prompt to a file."""
56
  if not os.path.exists(AGENT_DIRECTORY):
57
  os.makedirs(AGENT_DIRECTORY)
58
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")
 
59
  with open(file_path, "w") as file:
60
  file.write(agent.create_agent_prompt())
 
 
61
  st.session_state.available_agents.append(agent.name)
62
 
 
 
63
  def load_agent_prompt(agent_name):
64
  """Loads an agent prompt from a file."""
65
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
@@ -76,11 +87,13 @@ def create_agent_from_text(name, text):
76
  save_agent_to_file(agent)
77
  return agent.create_agent_prompt()
78
 
 
79
  def chat_interface_with_agent(input_text, agent_name):
80
  agent_prompt = load_agent_prompt(agent_name)
81
  if agent_prompt is None:
82
  return f"Agent {agent_name} not found."
83
 
 
84
  model_name = "gpt2"
85
  try:
86
  model = AutoModelForCausalLM.from_pretrained(model_name)
@@ -89,27 +102,31 @@ def chat_interface_with_agent(input_text, agent_name):
89
  except EnvironmentError as e:
90
  return f"Error loading model: {e}"
91
 
 
92
  combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
93
 
94
- input_ids = tokenizer.encode(combined_input, return_tensors="pt")
95
  max_input_length = 900
 
96
  if input_ids.shape[1] > max_input_length:
97
  input_ids = input_ids[:, :max_input_length]
98
 
 
99
  outputs = model.generate(
100
- input_ids, max_new_tokens=50, num_return_sequences=1, do_sample=True,
101
- pad_token_id=tokenizer.eos_token_id # Set pad_token_id to eos_token_id
102
  )
103
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
104
  return response
105
 
106
  def workspace_interface(project_name):
 
107
  if not os.path.exists(PROJECT_ROOT):
108
  os.makedirs(PROJECT_ROOT)
109
- project_path = os.path.join(PROJECT_ROOT, project_name)
110
  if not os.path.exists(project_path):
111
  os.makedirs(project_path)
112
  st.session_state.workspace_projects[project_name] = {"files": []}
 
 
113
  return f"Project {project_name} created successfully."
114
  else:
115
  return f"Project {project_name} already exists."
@@ -121,6 +138,8 @@ def add_code_to_workspace(project_name, code, file_name):
121
  with open(file_path, "w") as file:
122
  file.write(code)
123
  st.session_state.workspace_projects[project_name]["files"].append(file_name)
 
 
124
  return f"Code added to {file_name} in project {project_name} successfully."
125
  else:
126
  return f"Project {project_name} does not exist."
@@ -133,10 +152,11 @@ def terminal_interface(command, project_name=None):
133
  result = subprocess.run(command, cwd=project_path, shell=True, capture_output=True, text=True)
134
  else:
135
  result = subprocess.run(command, shell=True, capture_output=True, text=True)
136
-
137
  if result.returncode == 0:
 
138
  return result.stdout
139
  else:
 
140
  return result.stderr
141
 
142
  def code_editor_interface(code):
@@ -144,27 +164,27 @@ def code_editor_interface(code):
144
  formatted_code = black.format_str(code, mode=black.FileMode())
145
  except black.NothingChanged:
146
  formatted_code = code
147
-
148
  result = StringIO()
149
  sys.stdout = result
150
  sys.stderr = result
151
-
152
  (pylint_stdout, pylint_stderr) = lint.py_run(code, return_std=True)
153
  sys.stdout = sys.__stdout__
154
  sys.stderr = sys.__stderr__
155
-
156
  lint_message = pylint_stdout.getvalue() + pylint_stderr.getvalue()
157
-
 
158
  return formatted_code, lint_message
159
 
160
  def summarize_text(text):
161
  summarizer = pipeline("summarization")
162
  summary = summarizer(text, max_length=50, min_length=25, do_sample=False)
 
163
  return summary[0]['summary_text']
164
 
165
  def sentiment_analysis(text):
166
  analyzer = pipeline("sentiment-analysis")
167
  sentiment = analyzer(text)
 
168
  return sentiment[0]
169
 
170
  def translate_code(code, source_language, target_language):
@@ -176,7 +196,9 @@ def translate_code(code, source_language, target_language):
176
  {"role": "user", "content": prompt}
177
  ]
178
  )
179
- return response.choices[0].message['content'].strip()
 
 
180
 
181
  def generate_code(code_idea):
182
  response = openai.ChatCompletion.create(
@@ -186,14 +208,32 @@ def generate_code(code_idea):
186
  {"role": "user", "content": f"Generate a Python code snippet for the following idea:\n\n{code_idea}"}
187
  ]
188
  )
189
- return response.choices[0].message['content'].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
 
191
  st.title("AI Agent Creator")
192
 
 
193
  st.sidebar.title("Navigation")
194
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
195
 
196
  if app_mode == "AI Agent Creator":
 
197
  st.header("Create an AI Agent from Text")
198
 
199
  st.subheader("From Text")
@@ -205,20 +245,23 @@ if app_mode == "AI Agent Creator":
205
  st.session_state.available_agents.append(agent_name)
206
 
207
  elif app_mode == "Tool Box":
 
208
  st.header("AI-Powered Tools")
209
 
 
210
  st.subheader("Chat with CodeCraft")
211
  chat_input = st.text_area("Enter your message:")
212
  if st.button("Send"):
213
  if chat_input.startswith("@"):
214
- agent_name = chat_input.split(" ")[0][1:]
215
- chat_input = " ".join(chat_input.split(" ")[1:])
216
  chat_response = chat_interface_with_agent(chat_input, agent_name)
217
  else:
218
- chat_response = "Chat interface function not provided."
219
  st.session_state.chat_history.append((chat_input, chat_response))
220
  st.write(f"CodeCraft: {chat_response}")
221
 
 
222
  st.subheader("Terminal")
223
  terminal_input = st.text_input("Enter a command:")
224
  if st.button("Run"):
@@ -226,6 +269,7 @@ elif app_mode == "Tool Box":
226
  st.session_state.terminal_history.append((terminal_input, terminal_output))
227
  st.code(terminal_output, language="bash")
228
 
 
229
  st.subheader("Code Editor")
230
  code_editor = st.text_area("Write your code:", height=300)
231
  if st.button("Format & Lint"):
@@ -233,18 +277,21 @@ elif app_mode == "Tool Box":
233
  st.code(formatted_code, language="python")
234
  st.info(lint_message)
235
 
 
236
  st.subheader("Summarize Text")
237
  text_to_summarize = st.text_area("Enter text to summarize:")
238
  if st.button("Summarize"):
239
  summary = summarize_text(text_to_summarize)
240
  st.write(f"Summary: {summary}")
241
 
 
242
  st.subheader("Sentiment Analysis")
243
  sentiment_text = st.text_area("Enter text for sentiment analysis:")
244
  if st.button("Analyze Sentiment"):
245
  sentiment = sentiment_analysis(sentiment_text)
246
  st.write(f"Sentiment: {sentiment}")
247
 
 
248
  st.subheader("Translate Code")
249
  code_to_translate = st.text_area("Enter code to translate:")
250
  source_language = st.text_input("Enter source language (e.g. 'Python'):")
@@ -253,12 +300,14 @@ elif app_mode == "Tool Box":
253
  translated_code = translate_code(code_to_translate, source_language, target_language)
254
  st.code(translated_code, language=target_language.lower())
255
 
 
256
  st.subheader("Code Generation")
257
  code_idea = st.text_input("Enter your code idea:")
258
  if st.button("Generate Code"):
259
  generated_code = generate_code(code_idea)
260
  st.code(generated_code, language="python")
261
 
 
262
  st.subheader("Preset Commands")
263
  preset_commands = {
264
  "Create a new project": "create_project('project_name')",
@@ -273,14 +322,17 @@ elif app_mode == "Tool Box":
273
  st.write(f"{command_name}: `{command}`")
274
 
275
  elif app_mode == "Workspace Chat App":
 
276
  st.header("Workspace Chat App")
277
 
 
278
  st.subheader("Create a New Project")
279
  project_name = st.text_input("Enter project name:")
280
  if st.button("Create Project"):
281
  workspace_status = workspace_interface(project_name)
282
  st.success(workspace_status)
283
 
 
284
  st.subheader("Add Code to Workspace")
285
  code_to_add = st.text_area("Enter code to add to workspace:")
286
  file_name = st.text_input("Enter file name (e.g. 'app.py'):")
@@ -288,55 +340,59 @@ elif app_mode == "Workspace Chat App":
288
  add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
289
  st.success(add_code_status)
290
 
 
291
  st.subheader("Terminal (Workspace Context)")
292
  terminal_input = st.text_input("Enter a command within the workspace:")
293
  if st.button("Run Command"):
294
  terminal_output = terminal_interface(terminal_input, project_name)
295
  st.code(terminal_output, language="bash")
296
 
 
297
  st.subheader("Chat with CodeCraft for Guidance")
298
  chat_input = st.text_area("Enter your message for guidance:")
299
  if st.button("Get Guidance"):
300
- chat_response = "Chat interface function not provided."
301
  st.session_state.chat_history.append((chat_input, chat_response))
302
  st.write(f"CodeCraft: {chat_response}")
303
 
 
304
  st.subheader("Chat History")
305
  for user_input, response in st.session_state.chat_history:
306
  st.write(f"User: {user_input}")
307
  st.write(f"CodeCraft: {response}")
308
 
 
309
  st.subheader("Terminal History")
310
  for command, output in st.session_state.terminal_history:
311
  st.write(f"Command: {command}")
312
  st.code(output, language="bash")
313
 
 
314
  st.subheader("Workspace Projects")
315
  for project, details in st.session_state.workspace_projects.items():
316
  st.write(f"Project: {project}")
317
  for file in details['files']:
318
  st.write(f" - {file}")
319
 
 
320
  st.subheader("Chat with AI Agents")
321
- if st.session_state.available_agents:
322
- selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
323
- agent_chat_input = st.text_area("Enter your message for the agent:")
324
- if st.button("Send to Agent"):
325
- agent_chat_response = chat_interface_with_agent(agent_chat_input, selected_agent)
326
- st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
327
- st.write(f"{selected_agent}: {agent_chat_response}")
328
- else:
329
- st.write("No agents available. Please create an agent first.")
330
-
331
  st.subheader("Automate Build Process")
332
  if st.button("Automate"):
333
- if st.session_state.available_agents:
334
- selected_agent = st.session_state.available_agents[0]
335
- agent = AIAgent(selected_agent, "", [])
336
- summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
337
- st.write("Autonomous Build Summary:")
338
- st.write(summary)
339
- st.write("Next Step:")
340
- st.write(next_step)
341
- else:
342
- st.write("No agents available. Please create an agent first.")
 
 
1
  import os
2
+ import sys
3
  import subprocess
4
+ import streamlit as st
5
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
6
  import black
7
  from pylint import lint
8
  from io import StringIO
9
  import openai
 
10
 
11
  # Set your OpenAI API key here
12
  openai.api_key = "YOUR_OPENAI_API_KEY"
13
 
14
+ HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
15
  PROJECT_ROOT = "projects"
16
  AGENT_DIRECTORY = "agents"
17
 
 
24
  st.session_state.workspace_projects = {}
25
  if 'available_agents' not in st.session_state:
26
  st.session_state.available_agents = []
27
+ if 'current_state' not in st.session_state:
28
+ st.session_state.current_state = {
29
+ 'toolbox': {},
30
+ 'workspace_chat': {}
31
+ }
32
 
33
  class AIAgent:
34
  def __init__(self, name, description, skills):
 
58
  return summary, next_step
59
 
60
  def save_agent_to_file(agent):
61
+ """Saves the agent's prompt to a file locally and then commits to the Hugging Face repository."""
62
  if not os.path.exists(AGENT_DIRECTORY):
63
  os.makedirs(AGENT_DIRECTORY)
64
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")
65
+ config_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}Config.txt")
66
  with open(file_path, "w") as file:
67
  file.write(agent.create_agent_prompt())
68
+ with open(config_path, "w") as file:
69
+ file.write(f"Agent Name: {agent.name}\nDescription: {agent.description}")
70
  st.session_state.available_agents.append(agent.name)
71
 
72
+ commit_and_push_changes(f"Add agent {agent.name}")
73
+
74
  def load_agent_prompt(agent_name):
75
  """Loads an agent prompt from a file."""
76
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
 
87
  save_agent_to_file(agent)
88
  return agent.create_agent_prompt()
89
 
90
+ # Chat interface using a selected agent
91
  def chat_interface_with_agent(input_text, agent_name):
92
  agent_prompt = load_agent_prompt(agent_name)
93
  if agent_prompt is None:
94
  return f"Agent {agent_name} not found."
95
 
96
+ # Load the GPT-2 model which is compatible with AutoModelForCausalLM
97
  model_name = "gpt2"
98
  try:
99
  model = AutoModelForCausalLM.from_pretrained(model_name)
 
102
  except EnvironmentError as e:
103
  return f"Error loading model: {e}"
104
 
105
+ # Combine the agent prompt with user input
106
  combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
107
 
108
+ # Truncate input text to avoid exceeding the model's maximum length
109
  max_input_length = 900
110
+ input_ids = tokenizer.encode(combined_input, return_tensors="pt")
111
  if input_ids.shape[1] > max_input_length:
112
  input_ids = input_ids[:, :max_input_length]
113
 
114
+ # Generate chatbot response
115
  outputs = model.generate(
116
+ input_ids, max_new_tokens=50, num_return_sequences=1, do_sample=True, pad_token_id=tokenizer.eos_token_id # Set pad_token_id to eos_token_id
 
117
  )
118
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
119
  return response
120
 
121
  def workspace_interface(project_name):
122
+ project_path = os.path.join(PROJECT_ROOT, project_name)
123
  if not os.path.exists(PROJECT_ROOT):
124
  os.makedirs(PROJECT_ROOT)
 
125
  if not os.path.exists(project_path):
126
  os.makedirs(project_path)
127
  st.session_state.workspace_projects[project_name] = {"files": []}
128
+ st.session_state.current_state['workspace_chat']['project_name'] = project_name
129
+ commit_and_push_changes(f"Create project {project_name}")
130
  return f"Project {project_name} created successfully."
131
  else:
132
  return f"Project {project_name} already exists."
 
138
  with open(file_path, "w") as file:
139
  file.write(code)
140
  st.session_state.workspace_projects[project_name]["files"].append(file_name)
141
+ st.session_state.current_state['workspace_chat']['added_code'] = {"file_name": file_name, "code": code}
142
+ commit_and_push_changes(f"Add code to {file_name} in project {project_name}")
143
  return f"Code added to {file_name} in project {project_name} successfully."
144
  else:
145
  return f"Project {project_name} does not exist."
 
152
  result = subprocess.run(command, cwd=project_path, shell=True, capture_output=True, text=True)
153
  else:
154
  result = subprocess.run(command, shell=True, capture_output=True, text=True)
 
155
  if result.returncode == 0:
156
+ st.session_state.current_state['toolbox']['terminal_output'] = result.stdout
157
  return result.stdout
158
  else:
159
+ st.session_state.current_state['toolbox']['terminal_output'] = result.stderr
160
  return result.stderr
161
 
162
  def code_editor_interface(code):
 
164
  formatted_code = black.format_str(code, mode=black.FileMode())
165
  except black.NothingChanged:
166
  formatted_code = code
 
167
  result = StringIO()
168
  sys.stdout = result
169
  sys.stderr = result
 
170
  (pylint_stdout, pylint_stderr) = lint.py_run(code, return_std=True)
171
  sys.stdout = sys.__stdout__
172
  sys.stderr = sys.__stderr__
 
173
  lint_message = pylint_stdout.getvalue() + pylint_stderr.getvalue()
174
+ st.session_state.current_state['toolbox']['formatted_code'] = formatted_code
175
+ st.session_state.current_state['toolbox']['lint_message'] = lint_message
176
  return formatted_code, lint_message
177
 
178
  def summarize_text(text):
179
  summarizer = pipeline("summarization")
180
  summary = summarizer(text, max_length=50, min_length=25, do_sample=False)
181
+ st.session_state.current_state['toolbox']['summary'] = summary[0]['summary_text']
182
  return summary[0]['summary_text']
183
 
184
  def sentiment_analysis(text):
185
  analyzer = pipeline("sentiment-analysis")
186
  sentiment = analyzer(text)
187
+ st.session_state.current_state['toolbox']['sentiment'] = sentiment[0]
188
  return sentiment[0]
189
 
190
  def translate_code(code, source_language, target_language):
 
196
  {"role": "user", "content": prompt}
197
  ]
198
  )
199
+ translated_code = response.choices[0].message['content'].strip()
200
+ st.session_state.current_state['toolbox']['translated_code'] = translated_code
201
+ return translated_code
202
 
203
  def generate_code(code_idea):
204
  response = openai.ChatCompletion.create(
 
208
  {"role": "user", "content": f"Generate a Python code snippet for the following idea:\n\n{code_idea}"}
209
  ]
210
  )
211
+ generated_code = response.choices[0].message['content'].strip()
212
+ st.session_state.current_state['toolbox']['generated_code'] = generated_code
213
+ return generated_code
214
+
215
+ def commit_and_push_changes(commit_message):
216
+ """Commits and pushes changes to the Hugging Face repository."""
217
+ commands = [
218
+ "git add .",
219
+ f"git commit -m '{commit_message}'",
220
+ "git push"
221
+ ]
222
+ for command in commands:
223
+ result = subprocess.run(command, shell=True, capture_output=True, text=True)
224
+ if result.returncode != 0:
225
+ st.error(f"Error executing command '{command}': {result.stderr}")
226
+ break
227
 
228
+ # Streamlit App
229
  st.title("AI Agent Creator")
230
 
231
+ # Sidebar navigation
232
  st.sidebar.title("Navigation")
233
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
234
 
235
  if app_mode == "AI Agent Creator":
236
+ # AI Agent Creator
237
  st.header("Create an AI Agent from Text")
238
 
239
  st.subheader("From Text")
 
245
  st.session_state.available_agents.append(agent_name)
246
 
247
  elif app_mode == "Tool Box":
248
+ # Tool Box
249
  st.header("AI-Powered Tools")
250
 
251
+ # Chat Interface
252
  st.subheader("Chat with CodeCraft")
253
  chat_input = st.text_area("Enter your message:")
254
  if st.button("Send"):
255
  if chat_input.startswith("@"):
256
+ agent_name = chat_input.split(" ")[0][1:] # Extract agent_name from @agent_name
257
+ chat_input = " ".join(chat_input.split(" ")[1:]) # Remove agent_name from input
258
  chat_response = chat_interface_with_agent(chat_input, agent_name)
259
  else:
260
+ chat_response = chat_interface(chat_input)
261
  st.session_state.chat_history.append((chat_input, chat_response))
262
  st.write(f"CodeCraft: {chat_response}")
263
 
264
+ # Terminal Interface
265
  st.subheader("Terminal")
266
  terminal_input = st.text_input("Enter a command:")
267
  if st.button("Run"):
 
269
  st.session_state.terminal_history.append((terminal_input, terminal_output))
270
  st.code(terminal_output, language="bash")
271
 
272
+ # Code Editor Interface
273
  st.subheader("Code Editor")
274
  code_editor = st.text_area("Write your code:", height=300)
275
  if st.button("Format & Lint"):
 
277
  st.code(formatted_code, language="python")
278
  st.info(lint_message)
279
 
280
+ # Text Summarization Tool
281
  st.subheader("Summarize Text")
282
  text_to_summarize = st.text_area("Enter text to summarize:")
283
  if st.button("Summarize"):
284
  summary = summarize_text(text_to_summarize)
285
  st.write(f"Summary: {summary}")
286
 
287
+ # Sentiment Analysis Tool
288
  st.subheader("Sentiment Analysis")
289
  sentiment_text = st.text_area("Enter text for sentiment analysis:")
290
  if st.button("Analyze Sentiment"):
291
  sentiment = sentiment_analysis(sentiment_text)
292
  st.write(f"Sentiment: {sentiment}")
293
 
294
+ # Text Translation Tool (Code Translation)
295
  st.subheader("Translate Code")
296
  code_to_translate = st.text_area("Enter code to translate:")
297
  source_language = st.text_input("Enter source language (e.g. 'Python'):")
 
300
  translated_code = translate_code(code_to_translate, source_language, target_language)
301
  st.code(translated_code, language=target_language.lower())
302
 
303
+ # Code Generation
304
  st.subheader("Code Generation")
305
  code_idea = st.text_input("Enter your code idea:")
306
  if st.button("Generate Code"):
307
  generated_code = generate_code(code_idea)
308
  st.code(generated_code, language="python")
309
 
310
+ # Display Preset Commands
311
  st.subheader("Preset Commands")
312
  preset_commands = {
313
  "Create a new project": "create_project('project_name')",
 
322
  st.write(f"{command_name}: `{command}`")
323
 
324
  elif app_mode == "Workspace Chat App":
325
+ # Workspace Chat App
326
  st.header("Workspace Chat App")
327
 
328
+ # Project Workspace Creation
329
  st.subheader("Create a New Project")
330
  project_name = st.text_input("Enter project name:")
331
  if st.button("Create Project"):
332
  workspace_status = workspace_interface(project_name)
333
  st.success(workspace_status)
334
 
335
+ # Add Code to Workspace
336
  st.subheader("Add Code to Workspace")
337
  code_to_add = st.text_area("Enter code to add to workspace:")
338
  file_name = st.text_input("Enter file name (e.g. 'app.py'):")
 
340
  add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
341
  st.success(add_code_status)
342
 
343
+ # Terminal Interface with Project Context
344
  st.subheader("Terminal (Workspace Context)")
345
  terminal_input = st.text_input("Enter a command within the workspace:")
346
  if st.button("Run Command"):
347
  terminal_output = terminal_interface(terminal_input, project_name)
348
  st.code(terminal_output, language="bash")
349
 
350
+ # Chat Interface for Guidance
351
  st.subheader("Chat with CodeCraft for Guidance")
352
  chat_input = st.text_area("Enter your message for guidance:")
353
  if st.button("Get Guidance"):
354
+ chat_response = chat_interface(chat_input)
355
  st.session_state.chat_history.append((chat_input, chat_response))
356
  st.write(f"CodeCraft: {chat_response}")
357
 
358
+ # Display Chat History
359
  st.subheader("Chat History")
360
  for user_input, response in st.session_state.chat_history:
361
  st.write(f"User: {user_input}")
362
  st.write(f"CodeCraft: {response}")
363
 
364
+ # Display Terminal History
365
  st.subheader("Terminal History")
366
  for command, output in st.session_state.terminal_history:
367
  st.write(f"Command: {command}")
368
  st.code(output, language="bash")
369
 
370
+ # Display Projects and Files
371
  st.subheader("Workspace Projects")
372
  for project, details in st.session_state.workspace_projects.items():
373
  st.write(f"Project: {project}")
374
  for file in details['files']:
375
  st.write(f" - {file}")
376
 
377
+ # Chat with AI Agents
378
  st.subheader("Chat with AI Agents")
379
+ selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
380
+ agent_chat_input = st.text_area("Enter your message for the agent:")
381
+ if st.button("Send to Agent"):
382
+ agent_chat_response = chat_interface_with_agent(agent_chat_input, selected_agent)
383
+ st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
384
+ st.write(f"{selected_agent}: {agent_chat_response}")
385
+
386
+ # Automate Build Process
 
 
387
  st.subheader("Automate Build Process")
388
  if st.button("Automate"):
389
+ agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
390
+ summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
391
+ st.write("Autonomous Build Summary:")
392
+ st.write(summary)
393
+ st.write("Next Step:")
394
+ st.write(next_step)
395
+
396
+ # Display current state for debugging
397
+ st.sidebar.subheader("Current State")
398
+ st.sidebar.json(st.session_state.current_state)