Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,246 +1,321 @@
|
|
| 1 |
-
import os
|
| 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 |
-
def
|
| 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 |
-
def
|
| 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 |
-
def generate_code(code_idea):
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are an expert software developer."},
{"role": "user", "content": f"Generate a Python code snippet for the following idea:\n\n{code_idea}"}
]
)
generated_code = response.choices[0].message['content'].strip()
st.session_state.current_state['toolbox']['generated_code'] = generated_code
return generated_code
|
| 90 |
-
def commit_and_push_changes(commit_message):
"""Commits and pushes changes to the Hugging Face repository."""
commands = [
"git add .",
f"git commit -m '{commit_message}'",
"git push"
]
for command in commands:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode != 0:
st.error(f"Error executing command '{command}': {result.stderr}")
break
|
| 91 |
-
Streamlit App
|
| 92 |
st.title("AI Agent Creator")
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
st.
|
| 103 |
-
st.
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
st.
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
chat_response = chat_interface(chat_input)
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
#
|
| 120 |
-
st.subheader("
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
st.
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
st.
|
| 133 |
-
st.
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
st.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
st.
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
st.code(translated_code, language=target_language.lower())
|
| 157 |
-
|
| 158 |
-
# Code Generation
|
| 159 |
-
st.subheader("Code Generation")
|
| 160 |
-
code_idea = st.text_input("Enter your code idea:")
|
| 161 |
-
if st.button("Generate Code"):
|
| 162 |
-
generated_code = generate_code(code_idea)
|
| 163 |
-
st.code(generated_code, language="python")
|
| 164 |
-
|
| 165 |
-
# Display Preset Commands
|
| 166 |
-
st.subheader("Preset Commands")
|
| 167 |
-
preset_commands = {
|
| 168 |
-
"Create a new project": "create_project('project_name')",
|
| 169 |
-
"Add code to workspace": "add_code_to_workspace('project_name', 'code', 'file_name')",
|
| 170 |
-
"Run terminal command": "terminal_interface('command', 'project_name')",
|
| 171 |
-
"Generate code": "generate_code('code_idea')",
|
| 172 |
-
"Summarize text": "summarize_text('text')",
|
| 173 |
-
"Analyze sentiment": "sentiment_analysis('text')",
|
| 174 |
-
"Translate code": "translate_code('code', 'source_language', 'target_language')",
|
| 175 |
-
}
|
| 176 |
-
for command_name, command in preset_commands.items():
|
| 177 |
-
st.write(f"{command_name}: `{command}`")
|
| 178 |
-
elif app_mode == "Workspace Chat App":
# Workspace Chat App
st.header("Workspace Chat App")
|
| 179 |
-
|
| 180 |
-
# Project Workspace Creation
|
| 181 |
-
st.subheader("Create a New Project")
|
| 182 |
-
project_name = st.text_input("Enter project name:")
|
| 183 |
-
if st.button("Create Project"):
|
| 184 |
-
workspace_status = workspace_interface(project_name)
|
| 185 |
-
st.success(workspace_status)
|
| 186 |
-
|
| 187 |
-
# Add Code to Workspace
|
| 188 |
-
st.subheader("Add Code to Workspace")
|
| 189 |
-
code_to_add = st.text_area("Enter code to add to workspace:")
|
| 190 |
-
file_name = st.text_input("Enter file name (e.g. 'app.py'):")
|
| 191 |
-
if st.button("Add Code"):
|
| 192 |
-
add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
|
| 193 |
-
st.success(add_code_status)
|
| 194 |
-
|
| 195 |
-
# Terminal Interface with Project Context
|
| 196 |
-
st.subheader("Terminal (Workspace Context)")
|
| 197 |
-
terminal_input = st.text_input("Enter a command within the workspace:")
|
| 198 |
-
if st.button("Run Command"):
|
| 199 |
-
terminal_output = terminal_interface(terminal_input, project_name)
|
| 200 |
-
st.code(terminal_output, language="bash")
|
| 201 |
-
|
| 202 |
-
# Chat Interface for Guidance
|
| 203 |
-
st.subheader("Chat with CodeCraft for Guidance")
|
| 204 |
-
chat_input = st.text_area("Enter your message for guidance:")
|
| 205 |
-
if st.button("Get Guidance"):
|
| 206 |
-
chat_response = chat_interface(chat_input)
|
| 207 |
-
st.session_state.chat_history.append((chat_input, chat_response))
|
| 208 |
-
st.write(f"CodeCraft: {chat_response}")
|
| 209 |
-
|
| 210 |
-
# Display Chat History
|
| 211 |
-
st.subheader("Chat History")
|
| 212 |
-
for user_input, response in st.session_state.chat_history:
|
| 213 |
-
st.write(f"User: {user_input}")
|
| 214 |
-
st.write(f"CodeCraft: {response}")
|
| 215 |
-
|
| 216 |
-
# Display Terminal History
|
| 217 |
-
st.subheader("Terminal History")
|
| 218 |
-
for command, output in st.session_state.terminal_history:
|
| 219 |
-
st.write(f"Command: {command}")
|
| 220 |
-
st.code(output, language="bash")
|
| 221 |
-
|
| 222 |
-
# Display Projects and Files
|
| 223 |
-
st.subheader("Workspace Projects")
|
| 224 |
-
for project, details in st.session_state.workspace_projects.items():
|
| 225 |
-
st.write(f"Project: {project}")
|
| 226 |
-
for file in details['files']:
|
| 227 |
-
st.write(f" - {file}")
|
| 228 |
-
|
| 229 |
-
# Chat with AI Agents
|
| 230 |
-
st.subheader("Chat with AI Agents")
|
| 231 |
-
selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
|
| 232 |
-
agent_chat_input = st.text_area("Enter your message for the agent:")
|
| 233 |
-
if st.button("Send to Agent"):
|
| 234 |
-
agent_chat_response = chat_interface_with_agent(agent_chat_input, selected_agent)
|
| 235 |
-
st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
|
| 236 |
-
st.write(f"{selected_agent}: {agent_chat_response}")
|
| 237 |
-
|
| 238 |
-
# Automate Build Process
|
| 239 |
-
st.subheader("Automate Build Process")
|
| 240 |
-
if st.button("Automate"):
|
| 241 |
-
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
| 242 |
-
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
|
| 243 |
-
st.write("Autonomous Build Summary:")
|
| 244 |
-
st.write(summary)
|
| 245 |
-
st.write("Next Step:")
|
| 246 |
-
st.write(next_step)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from transformers import pipeline,
|
| 5 |
+
import
|
| 6 |
+
from pylint import lint
|
| 7 |
+
from io import StringIO
|
| 8 |
+
from mixtral import InstructModel # Import Mixtral Instruct
|
| 9 |
+
|
| 10 |
+
HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
|
| 11 |
+
PROJECT_ROOT =
|
| 12 |
+
AGENT_DIRECTORY =
|
| 13 |
+
|
| 14 |
+
# Global state to manage communication between Tool Box and Workspace Chat App
|
| 15 |
+
if 'chat_history' not in st.session_state:
|
| 16 |
+
st.session_state.chat_history = []
|
| 17 |
+
if 'terminal_history' not in st.session_state:
|
| 18 |
+
st.session_state.terminal_history = []
|
| 19 |
+
if 'workspace_projects' not in st.session_state:
|
| 20 |
+
st.session_state.workspace_projects = {}
|
| 21 |
+
if 'available_agents' not in st.session_state:
|
| 22 |
+
st.session_state.available_agents = []
|
| 23 |
+
if 'current_state' not in st.session_state:
|
| 24 |
+
|
| 25 |
+
'toolbox': {},
|
| 26 |
+
'workspace_chat': {}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class AIAgent:
|
| 30 |
+
def __init__(self,
|
| 31 |
+
self.name = name
|
| 32 |
+
self.description = description
|
| 33 |
+
self.skills = skills
|
| 34 |
+
|
| 35 |
+
def create_agent_prompt(self):
|
| 36 |
+
skills_str = '\n'.join([f"* {skill}" for skill in self.skills])
|
| 37 |
+
agent_prompt = f"""
|
| 38 |
+
As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
|
| 39 |
+
{skills_str}
|
| 40 |
+
|
| 41 |
+
I am confident that I can leverage my expertise to assist you in developing and deploying cutting-edge web applications. Please feel free to ask any questions or present any challenges you may encounter.
|
| 42 |
+
"""
|
| 43 |
+
return agent_prompt
|
| 44 |
+
|
| 45 |
+
def autonomous_build(self, chat_history, workspace_projects):
|
| 46 |
+
"""
|
| 47 |
+
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
| 48 |
+
"""
|
| 49 |
+
summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
|
| 50 |
+
summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
| 51 |
+
|
| 52 |
+
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
| 53 |
+
|
| 54 |
+
return summary, next_step
|
| 55 |
+
|
| 56 |
+
def save_agent_to_file(agent):
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
file_path
|
| 61 |
+
config_path
|
| 62 |
+
with open(file_path, "w")
|
| 63 |
+
file.write(agent.create_agent_prompt())
|
| 64 |
+
with open(config_path, "w") as file:
|
| 65 |
+
file.write(f"Agent Name: {agent.name}\nDescription: {agent.description}")
|
| 66 |
+
st.session_state.available_agents.append(agent.name)
|
| 67 |
+
commit_and_push_changes(f"Add agent {agent.name}")
|
| 68 |
+
|
| 69 |
+
def load_agent_prompt(agent_name):
|
| 70 |
+
"""Loads an agent prompt from a file."""
|
| 71 |
+
file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
|
| 72 |
+
if os.path.exists(file_path):
|
| 73 |
+
with open(file_path, "r") as file:
|
| 74 |
+
agent_prompt = file.read()
|
| 75 |
+
return agent_prompt
|
| 76 |
+
else:
|
| 77 |
+
return None
|
| 78 |
+
|
| 79 |
+
def create_agent_from_text(name, text):
|
| 80 |
+
skills = text.split('\n')
|
| 81 |
+
agent = AIAgent(name, "AI agent created from text input.", skills)
|
| 82 |
+
save_agent_to_file(agent)
|
| 83 |
+
return agent.create_agent_prompt()
|
| 84 |
+
|
| 85 |
+
def chat_interface_with_agent(input_text, agent_name):
|
| 86 |
+
agent_prompt = load_agent_prompt(agent_name)
|
| 87 |
+
if agent_prompt is None:
|
| 88 |
+
return f"Agent {agent_name} not found."
|
| 89 |
+
|
| 90 |
+
try:
|
| 91 |
+
model = InstructModel() # Initialize Mixtral Instruct model
|
| 92 |
+
except EnvironmentError as e:
|
| 93 |
+
return f"Error loading model: {e}"
|
| 94 |
+
|
| 95 |
+
combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
|
| 96 |
+
response = model.generate_response(combined_input) # Generate response using Mixtral Instruct
|
| 97 |
+
return response
|
| 98 |
+
|
| 99 |
+
def workspace_interface(project_name):
|
| 100 |
+
project_path = os.path.join(PROJECT_ROOT, project_name)
|
| 101 |
+
if not os.path.exists(PROJECT_ROOT):
|
| 102 |
+
os.makedirs(PROJECT_ROOT)
|
| 103 |
+
if not os.path.exists(project_path):
|
| 104 |
+
os.makedirs(project_path)
|
| 105 |
+
st.session_state.workspace_projects[project_name] = {"files": []}
|
| 106 |
+
st.session_state.current_state['workspace_chat']['project_name'] = project_name
|
| 107 |
+
commit_and_push_changes(f"Create project {project_name}")
|
| 108 |
+
return f"Project {project_name} created successfully."
|
| 109 |
+
else:
|
| 110 |
+
return f"Project {project_name} already exists."
|
| 111 |
+
|
| 112 |
+
def add_code_to_workspace(project_name, code, file_name):
|
| 113 |
+
project_path = os.path.join(PROJECT_ROOT, project_name)
|
| 114 |
+
if os.path.exists(project_path):
|
| 115 |
+
file_path = os.path.join(project_path, file_name)
|
| 116 |
+
with open(file_path, "w") as file:
|
| 117 |
+
file.write(code)
|
| 118 |
+
st.session_state.workspace_projects[project_name]["files"].append(file_name)
|
| 119 |
+
st.session_state.current_state['workspace_chat']['added_code'] = {"file_name": file_name, "code": code}
|
| 120 |
+
commit_and_push_changes(f"Add code to {file_name} in project {project_name}")
|
| 121 |
+
return f"Code added to {file_name} in project {project_name} successfully."
|
| 122 |
+
else:
|
| 123 |
+
return f"Project {project_name} does not exist."
|
| 124 |
+
|
| 125 |
+
def terminal_interface(command, project_name=None):
|
| 126 |
+
if project_name:
|
| 127 |
+
project_path = os.path.join(PROJECT_ROOT, project_name)
|
| 128 |
+
if not os.path.exists(project_path):
|
| 129 |
+
return f"Project {project_name} does not exist."
|
| 130 |
+
result = subprocess.run(command, cwd=project_path, shell=True, capture_output=True, text=True)
|
| 131 |
+
else:
|
| 132 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 133 |
+
if result.returncode == 0:
|
| 134 |
+
st.session_state.current_state['toolbox']['terminal_output'] = result.stdout
|
| 135 |
+
return result.stdout
|
| 136 |
+
else:
|
| 137 |
+
st.session_state.current_state['toolbox']['terminal_output'] = result.stderr
|
| 138 |
+
return result.stderr
|
| 139 |
+
|
| 140 |
+
def code_editor_interface(code):
|
| 141 |
+
try:
|
| 142 |
+
formatted_code = black.format_str(code, mode=black.FileMode())
|
| 143 |
+
except black.NothingChanged:
|
| 144 |
+
formatted_code = code
|
| 145 |
+
result = StringIO()
|
| 146 |
+
sys.stdout = result
|
| 147 |
+
sys.stderr = result
|
| 148 |
+
(pylint_stdout, pylint_stderr) = lint.py_run(code, return_std=True)
|
| 149 |
+
sys.stdout = sys.__stdout__
|
| 150 |
+
sys.stderr = sys.__stderr__
|
| 151 |
+
lint_message = pylint_stdout.getvalue() + pylint_stderr.getvalue()
|
| 152 |
+
st.session_state.current_state['toolbox']['formatted_code'] = formatted_code
|
| 153 |
+
st.session_state.current_state['toolbox']['lint_message'] = lint_message
|
| 154 |
+
return formatted_code, lint_message
|
| 155 |
+
|
| 156 |
+
def translate_code(code, input_language, output_language):
|
| 157 |
+
# Use a Hugging Face translation model to handle end-to-end code translation
|
| 158 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es") # Example: English to Spanish
|
| 159 |
+
translated_code = translator(code, target_lang=output_language)[0]['translation_text']
|
| 160 |
+
st.session_state.current_state['toolbox']['translated_code'] = translated_code
|
| 161 |
+
return translated_code
|
| 162 |
+
|
| 163 |
+
def generate_code(code_idea):
|
| 164 |
+
# Use a Hugging Face code generation model
|
| 165 |
+
generator = pipeline('text-generation', model='bigcode/starcoder')
|
| 166 |
+
generated_code = generator(code_idea, max_length=1000, num_return_sequences=1)[0]['generated_text']
|
| 167 |
+
st.session_state.current_state['toolbox']['generated_code'] = generated_code
|
| 168 |
+
return generated_code
|
| 169 |
+
|
| 170 |
+
def commit_and_push_changes(commit_message):
|
| 171 |
+
"""Commits and pushes changes to the Hugging Face repository."""
|
| 172 |
+
commands = [
|
| 173 |
+
"git add .",
|
| 174 |
+
f"git commit -m '{commit_message}'",
|
| 175 |
+
"git push"
|
| 176 |
]
|
| 177 |
+
for command in commands:
|
| 178 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
| 179 |
+
if result.returncode != 0:
|
| 180 |
+
st.error(f"Error executing command '{command}': {result.stderr}")
|
| 181 |
+
break
|
| 182 |
+
|
| 183 |
+
# Streamlit App
|
|
|
|
|
|
|
|
|
|
| 184 |
st.title("AI Agent Creator")
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
|
| 189 |
+
|
| 190 |
+
if app_mode == "AI Agent Creator":
|
| 191 |
+
# AI Agent Creator
|
| 192 |
+
st.header("Create an AI Agent from Text")
|
| 193 |
+
|
| 194 |
+
st.subheader("From Text")
|
| 195 |
+
agent_name = st.text_input("Enter agent name:")
|
| 196 |
+
text_input =
|
| 197 |
+
if st.button("Create Agent"):
|
| 198 |
+
agent_prompt = create_agent_from_text(agent_name, text_input)
|
| 199 |
+
st.success(f"Agent '{agent_name}' created and saved successfully.")
|
| 200 |
+
st.session_state.available_agents.append(agent_name)
|
| 201 |
+
|
| 202 |
+
elif app_mode == "Tool Box":
|
| 203 |
+
# Tool Box
|
| 204 |
+
st.header("AI-Powered Tools")
|
| 205 |
+
|
| 206 |
+
# Chat Interface
|
| 207 |
+
st.subheader("Chat with CodeCraft")
|
| 208 |
+
chat_input = st.text_area("Enter your message:")
|
| 209 |
+
if st.button("Send"):
|
| 210 |
+
if chat_input.startswith("@"):
|
| 211 |
+
agent_name = chat_input.split(" ")[0][1:] # Extract agent_name from @agent_name
|
| 212 |
+
chat_input = " ".join(chat_input.split(" ")[1:]) # Remove agent_name from input
|
| 213 |
+
chat_response = chat_interface_with_agent(chat_input, agent_name)
|
| 214 |
+
else:
|
| 215 |
+
chat_response = chat_interface(chat_input)
|
| 216 |
+
st.session_state.chat_history.append((chat_input, chat_response))
|
| 217 |
+
st.write(f"CodeCraft: {chat_response}")
|
| 218 |
+
|
| 219 |
+
# Terminal Interface
|
| 220 |
+
st.subheader("Terminal")
|
| 221 |
+
terminal_input = st.text_input("Enter a command:")
|
| 222 |
+
if st.button("Run"):
|
| 223 |
+
terminal_output = terminal_interface(terminal_input)
|
| 224 |
+
st.session_state.terminal_history.append((terminal_input, terminal_output))
|
| 225 |
+
st.code(terminal_output, language="bash")
|
| 226 |
+
|
| 227 |
+
# Code Editor Interface
|
| 228 |
+
st.subheader("Code Editor")
|
| 229 |
+
code_editor = st.text_area("Write your code:", height=300)
|
| 230 |
+
if st.button("Format & Lint"):
|
| 231 |
+
formatted_code, lint_message = code_editor_interface(code_editor)
|
| 232 |
+
st.code(formatted_code, language="python")
|
| 233 |
+
st.info(lint_message)
|
| 234 |
+
|
| 235 |
+
# Text Translation Tool (Code Translation)
|
| 236 |
+
st.subheader("Translate Code")
|
| 237 |
+
code_to_translate = st.text_area("Enter code to translate:")
|
| 238 |
+
source_language = st.text_input("Enter source language (e.g., 'Python'):")
|
| 239 |
+
target_language = st.text_input("Enter target language (e.g., 'JavaScript'):")
|
| 240 |
+
if st.button("Translate Code"):
|
| 241 |
+
translated_code = translate_code(code_to_translate, source_language, target_language)
|
| 242 |
+
st.code(translated_code, language=target_language.lower())
|
| 243 |
+
|
| 244 |
+
# Code Generation
|
| 245 |
+
st.subheader("Code Generation")
|
| 246 |
+
code_idea = st.text_input("Enter your code idea:")
|
| 247 |
+
if st.button("Generate Code"):
|
| 248 |
+
generated_code = generate_code(code_idea)
|
| 249 |
+
st.code(generated_code, language="python")
|
| 250 |
+
|
| 251 |
+
elif app_mode == "Workspace Chat App":
|
| 252 |
+
# Workspace Chat App
|
| 253 |
+
st.header("Workspace Chat App")
|
| 254 |
+
|
| 255 |
+
# Project Workspace Creation
|
| 256 |
+
st.subheader("Create a New Project")
|
| 257 |
+
project_name = st.text_input("Enter project name:")
|
| 258 |
+
if st.button("Create Project"):
|
| 259 |
+
workspace_status = workspace_interface(project_name)
|
| 260 |
+
st.success(workspace_status)
|
| 261 |
+
|
| 262 |
+
# Add Code to Workspace
|
| 263 |
+
st.subheader("Add Code to Workspace")
|
| 264 |
+
code_to_add = st.text_area("Enter code to add to workspace:")
|
| 265 |
+
file_name = st.text_input("Enter file name (e.g., 'app.py'):")
|
| 266 |
+
if st.button("Add Code"):
|
| 267 |
+
add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
|
| 268 |
+
st.success(add_code_status)
|
| 269 |
+
|
| 270 |
+
# Terminal Interface with Project Context
|
| 271 |
+
st.subheader("Terminal (Workspace Context)")
|
| 272 |
+
terminal_input = st.text_input("Enter a command within the workspace:")
|
| 273 |
+
if st.button("Run Command"):
|
| 274 |
+
terminal_output = terminal_interface(terminal_input, project_name)
|
| 275 |
+
st.code(terminal_output, language="bash")
|
| 276 |
+
|
| 277 |
+
# Chat Interface for Guidance
|
| 278 |
+
st.subheader("Chat with CodeCraft for Guidance")
|
| 279 |
+
chat_input = st.text_area("Enter your message for guidance:")
|
| 280 |
+
if st.button("Get Guidance"):
|
| 281 |
chat_response = chat_interface(chat_input)
|
| 282 |
+
st.session_state.chat_history.append((chat_input, chat_response))
|
| 283 |
+
st.write(f"CodeCraft: {chat_response}")
|
| 284 |
+
|
| 285 |
+
# Display Chat History
|
| 286 |
+
st.subheader("Chat History")
|
| 287 |
+
for user_input, response in st.session_state.chat_history:
|
| 288 |
+
st.write(f"User: {user_input}")
|
| 289 |
+
st.write(f"CodeCraft: {response}")
|
| 290 |
+
|
| 291 |
+
# Display Terminal History
|
| 292 |
+
st.subheader("Terminal History")
|
| 293 |
+
for command, output in st.session_state.terminal_history:
|
| 294 |
+
st.write(f"Command: {command}")
|
| 295 |
+
st.code(output, language="bash")
|
| 296 |
+
|
| 297 |
+
# Display Projects and Files
|
| 298 |
+
st.subheader("Workspace Projects")
|
| 299 |
+
for project, details in st.session_state.workspace_projects.items():
|
| 300 |
+
st.write(f"Project: {project}")
|
| 301 |
+
for file in details['files']:
|
| 302 |
+
st.write(f" - {file}")
|
| 303 |
+
|
| 304 |
+
# Chat with AI Agents
|
| 305 |
+
st.subheader("Chat with AI Agents")
|
| 306 |
+
selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
|
| 307 |
+
agent_chat_input = st.text_area("Enter your message for the agent:")
|
| 308 |
+
if st.button("Send to Agent"):
|
| 309 |
+
agent_chat_response = chat_interface_with_agent(agent_chat_input, selected_agent)
|
| 310 |
+
st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
|
| 311 |
+
st.write(f"{selected_agent}: {agent_chat_response}")
|
| 312 |
+
|
| 313 |
+
# Automate Build Process
|
| 314 |
+
st.subheader("Automate Build Process")
|
| 315 |
+
if st.button("Automate"):
|
| 316 |
+
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
| 317 |
+
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
|
| 318 |
+
st.write("Autonomous Build Summary:")
|
| 319 |
+
st.write(summary)
|
| 320 |
+
st.write("Next Step:")
|
| 321 |
+
st.write(next_step)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|