Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -51,18 +51,32 @@ class AIAgent:
|
|
51 |
self.description = description
|
52 |
self.skills = skills
|
53 |
|
54 |
-
def generate_agent_response(self, prompt: str) -> str:
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
""
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def create_project(self, project_name: str) -> str:
|
68 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
@@ -73,7 +87,7 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
73 |
else:
|
74 |
return f"Project '{project_name}' already exists."
|
75 |
|
76 |
-
def
|
77 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
78 |
if not os.path.exists(project_path):
|
79 |
return f"Project '{project_name}' does not exist."
|
@@ -82,24 +96,17 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
82 |
with open(file_path, "w") as file:
|
83 |
file.write(content)
|
84 |
st.session_state.workspace_projects[project_name]['files'].append(file_name)
|
85 |
-
return f"File '{file_name}'
|
86 |
|
87 |
-
def
|
88 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
89 |
file_path = os.path.join(project_path, file_name)
|
90 |
if not os.path.exists(file_path):
|
91 |
return f"File '{file_name}' does not exist in project '{project_name}'."
|
92 |
|
93 |
-
with open(file_path, "
|
94 |
-
file.write(
|
95 |
-
return f"
|
96 |
-
|
97 |
-
# Initialize some example agents
|
98 |
-
example_agents = [
|
99 |
-
AIAgent("WebDev Wizard", "Full-stack web development expert", ["HTML", "CSS", "JavaScript", "React", "Node.js"]),
|
100 |
-
AIAgent("Data Scientist", "Machine learning and data analysis specialist", ["Python", "Pandas", "Scikit-learn", "TensorFlow"]),
|
101 |
-
AIAgent("DevOps Guru", "Infrastructure and deployment expert", ["Docker", "Kubernetes", "AWS", "CI/CD"])
|
102 |
-
]
|
103 |
|
104 |
def main():
|
105 |
st.title("AI-Guided Workspace")
|
@@ -124,7 +131,7 @@ def main():
|
|
124 |
st.subheader("Chat with AI Agent")
|
125 |
user_input = st.text_input("Enter your message:")
|
126 |
if st.button("Send"):
|
127 |
-
agent_response = example_agents[0].generate_agent_response(user_input)
|
128 |
st.session_state.chat_history.append((user_input, agent_response))
|
129 |
|
130 |
# Display chat history
|
@@ -137,7 +144,7 @@ def main():
|
|
137 |
file_name = st.text_input("File name:")
|
138 |
code = st_ace(language="python", theme="monokai", key="code_editor")
|
139 |
if st.button("Save File"):
|
140 |
-
result = example_agents[0].
|
141 |
st.write(result)
|
142 |
|
143 |
# Display project files
|
@@ -145,6 +152,10 @@ def main():
|
|
145 |
if st.session_state.current_project in st.session_state.workspace_projects:
|
146 |
for file in st.session_state.workspace_projects[st.session_state.current_project]['files']:
|
147 |
st.text(file)
|
|
|
|
|
|
|
|
|
148 |
|
149 |
else:
|
150 |
st.write("Please create or select a project to get started.")
|
|
|
51 |
self.description = description
|
52 |
self.skills = skills
|
53 |
|
54 |
+
def generate_agent_response(self, prompt: str, project_name: str) -> str:
|
55 |
+
# Simple logic to demonstrate agent capabilities
|
56 |
+
if "create file" in prompt.lower():
|
57 |
+
file_name = re.search(r"create file (\w+\.?\w*)", prompt.lower())
|
58 |
+
if file_name:
|
59 |
+
return self.create_file(project_name, file_name.group(1), "# New file created")
|
60 |
+
else:
|
61 |
+
return "I'm sorry, I couldn't understand the file name. Please specify the file name clearly."
|
62 |
+
|
63 |
+
elif "add code" in prompt.lower():
|
64 |
+
file_name = re.search(r"add code to (\w+\.?\w*)", prompt.lower())
|
65 |
+
if file_name:
|
66 |
+
code_to_add = prompt.split("add code to")[1].split(":", 1)[-1].strip()
|
67 |
+
return self.add_code_to_file(project_name, file_name.group(1), code_to_add)
|
68 |
+
else:
|
69 |
+
return "I'm sorry, I couldn't understand the file name. Please specify the file name clearly."
|
70 |
+
|
71 |
+
elif "create project" in prompt.lower():
|
72 |
+
new_project_name = re.search(r"create project (\w+)", prompt.lower())
|
73 |
+
if new_project_name:
|
74 |
+
return self.create_project(new_project_name.group(1))
|
75 |
+
else:
|
76 |
+
return "I'm sorry, I couldn't understand the project name. Please specify the project name clearly."
|
77 |
+
|
78 |
+
else:
|
79 |
+
return f"I understand you're asking about '{prompt}'. How can I assist you with this in the context of your project?"
|
80 |
|
81 |
def create_project(self, project_name: str) -> str:
|
82 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
|
|
87 |
else:
|
88 |
return f"Project '{project_name}' already exists."
|
89 |
|
90 |
+
def create_file(self, project_name: str, file_name: str, content: str) -> str:
|
91 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
92 |
if not os.path.exists(project_path):
|
93 |
return f"Project '{project_name}' does not exist."
|
|
|
96 |
with open(file_path, "w") as file:
|
97 |
file.write(content)
|
98 |
st.session_state.workspace_projects[project_name]['files'].append(file_name)
|
99 |
+
return f"File '{file_name}' created in project '{project_name}'."
|
100 |
|
101 |
+
def add_code_to_file(self, project_name: str, file_name: str, code: str) -> str:
|
102 |
project_path = os.path.join(PROJECT_ROOT, project_name)
|
103 |
file_path = os.path.join(project_path, file_name)
|
104 |
if not os.path.exists(file_path):
|
105 |
return f"File '{file_name}' does not exist in project '{project_name}'."
|
106 |
|
107 |
+
with open(file_path, "a") as file:
|
108 |
+
file.write("\n" + code)
|
109 |
+
return f"Code added to '{file_name}' in project '{project_name}'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
def main():
|
112 |
st.title("AI-Guided Workspace")
|
|
|
131 |
st.subheader("Chat with AI Agent")
|
132 |
user_input = st.text_input("Enter your message:")
|
133 |
if st.button("Send"):
|
134 |
+
agent_response = example_agents[0].generate_agent_response(user_input, st.session_state.current_project)
|
135 |
st.session_state.chat_history.append((user_input, agent_response))
|
136 |
|
137 |
# Display chat history
|
|
|
144 |
file_name = st.text_input("File name:")
|
145 |
code = st_ace(language="python", theme="monokai", key="code_editor")
|
146 |
if st.button("Save File"):
|
147 |
+
result = example_agents[0].create_file(st.session_state.current_project, file_name, code)
|
148 |
st.write(result)
|
149 |
|
150 |
# Display project files
|
|
|
152 |
if st.session_state.current_project in st.session_state.workspace_projects:
|
153 |
for file in st.session_state.workspace_projects[st.session_state.current_project]['files']:
|
154 |
st.text(file)
|
155 |
+
if st.button(f"View {file}"):
|
156 |
+
file_path = os.path.join(PROJECT_ROOT, st.session_state.current_project, file)
|
157 |
+
with open(file_path, "r") as f:
|
158 |
+
st.code(f.read())
|
159 |
|
160 |
else:
|
161 |
st.write("Please create or select a project to get started.")
|