Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,11 +44,9 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
| 44 |
"""
|
| 45 |
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
| 46 |
"""
|
| 47 |
-
# Example logic: Generate a summary of chat history and workspace state
|
| 48 |
summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
|
| 49 |
-
summary += "\n\nWorkspace Projects:\n" + "\n
|
| 50 |
|
| 51 |
-
# Example: Generate the next logical step in the project
|
| 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
|
|
@@ -109,79 +107,16 @@ def chat_interface_with_agent(input_text, agent_name):
|
|
| 109 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 110 |
return response
|
| 111 |
|
| 112 |
-
#
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
def code_editor_interface(code):
|
| 123 |
-
formatted_code = black.format_str(code, mode=black.FileMode())
|
| 124 |
-
pylint_output = lint.Run([formatted_code], do_exit=False)
|
| 125 |
-
pylint_output_str = StringIO()
|
| 126 |
-
pylint_output.linter.reporter.write_messages(pylint_output_str)
|
| 127 |
-
return formatted_code, pylint_output_str.getvalue()
|
| 128 |
-
|
| 129 |
-
# Text summarization tool
|
| 130 |
-
def summarize_text(text):
|
| 131 |
-
summarizer = pipeline("summarization")
|
| 132 |
-
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 133 |
-
return summary[0]['summary_text']
|
| 134 |
-
|
| 135 |
-
# Sentiment analysis tool
|
| 136 |
-
def sentiment_analysis(text):
|
| 137 |
-
analyzer = pipeline("sentiment-analysis")
|
| 138 |
-
result = analyzer(text)
|
| 139 |
-
return result[0]['label']
|
| 140 |
-
|
| 141 |
-
# Text translation tool (code translation)
|
| 142 |
-
def translate_code(code, source_language, target_language):
|
| 143 |
-
# Placeholder for translation logic
|
| 144 |
-
return f"Translated {source_language} code to {target_language}."
|
| 145 |
-
|
| 146 |
-
# Code generation tool
|
| 147 |
-
def generate_code(idea):
|
| 148 |
-
response = openai.Completion.create(
|
| 149 |
-
engine="davinci-codex",
|
| 150 |
-
prompt=idea,
|
| 151 |
-
max_tokens=150
|
| 152 |
-
)
|
| 153 |
-
return response.choices[0].text.strip()
|
| 154 |
-
|
| 155 |
-
# Workspace interface
|
| 156 |
-
def workspace_interface(project_name):
|
| 157 |
-
project_path = os.path.join(PROJECT_ROOT, project_name)
|
| 158 |
-
if not os.path.exists(project_path):
|
| 159 |
-
os.makedirs(project_path)
|
| 160 |
-
st.session_state.workspace_projects[project_name] = {'files': []}
|
| 161 |
-
return f"Project '{project_name}' created successfully."
|
| 162 |
-
else:
|
| 163 |
-
return f"Project '{project_name}' already exists."
|
| 164 |
-
|
| 165 |
-
# Add code to workspace
|
| 166 |
-
def add_code_to_workspace(project_name, code, file_name):
|
| 167 |
-
project_path = os.path.join(PROJECT_ROOT, project_name)
|
| 168 |
-
if not os.path.exists(project_path):
|
| 169 |
-
return f"Project '{project_name}' does not exist."
|
| 170 |
-
|
| 171 |
-
file_path = os.path.join(project_path, file_name)
|
| 172 |
-
with open(file_path, "w") as file:
|
| 173 |
-
file.write(code)
|
| 174 |
-
st.session_state.workspace_projects[project_name]['files'].append(file_name)
|
| 175 |
-
return f"Code added to '{file_name}' in project '{project_name}'."
|
| 176 |
-
|
| 177 |
-
# Chat interface
|
| 178 |
-
def chat_interface(input_text):
|
| 179 |
-
response = openai.Completion.create(
|
| 180 |
-
engine="davinci-codex",
|
| 181 |
-
prompt=input_text,
|
| 182 |
-
max_tokens=150
|
| 183 |
-
)
|
| 184 |
-
return response.choices[0].text.strip()
|
| 185 |
|
| 186 |
# Streamlit App
|
| 187 |
st.title("AI Agent Creator")
|
|
@@ -210,7 +145,12 @@ elif app_mode == "Tool Box":
|
|
| 210 |
st.subheader("Chat with CodeCraft")
|
| 211 |
chat_input = st.text_area("Enter your message:")
|
| 212 |
if st.button("Send"):
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
st.session_state.chat_history.append((chat_input, chat_response))
|
| 215 |
st.write(f"CodeCraft: {chat_response}")
|
| 216 |
|
|
@@ -247,8 +187,8 @@ elif app_mode == "Tool Box":
|
|
| 247 |
# Text Translation Tool (Code Translation)
|
| 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
|
| 251 |
-
target_language = st.text_input("Enter target language (e.g
|
| 252 |
if st.button("Translate Code"):
|
| 253 |
translated_code = translate_code(code_to_translate, source_language, target_language)
|
| 254 |
st.code(translated_code, language=target_language.lower())
|
|
@@ -260,6 +200,11 @@ elif app_mode == "Tool Box":
|
|
| 260 |
generated_code = generate_code(code_idea)
|
| 261 |
st.code(generated_code, language="python")
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
elif app_mode == "Workspace Chat App":
|
| 264 |
# Workspace Chat App
|
| 265 |
st.header("Workspace Chat App")
|
|
@@ -274,7 +219,7 @@ elif app_mode == "Workspace Chat App":
|
|
| 274 |
# Add Code to Workspace
|
| 275 |
st.subheader("Add Code to Workspace")
|
| 276 |
code_to_add = st.text_area("Enter code to add to workspace:")
|
| 277 |
-
file_name = st.text_input("Enter file name (e.g
|
| 278 |
if st.button("Add Code"):
|
| 279 |
add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
|
| 280 |
st.success(add_code_status)
|
|
|
|
| 44 |
"""
|
| 45 |
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
| 46 |
"""
|
|
|
|
| 47 |
summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
|
| 48 |
+
summary += "\n\nWorkspace Projects:\n" + "\n.join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
| 49 |
|
|
|
|
| 50 |
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
| 51 |
|
| 52 |
return summary, next_step
|
|
|
|
| 107 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 108 |
return response
|
| 109 |
|
| 110 |
+
# Preset commands for no-code-knowledge developers
|
| 111 |
+
preset_commands = {
|
| 112 |
+
"Create a new project": "create_project('project_name')",
|
| 113 |
+
"Add code to workspace": "add_code_to_workspace('project_name', 'code', 'file_name')",
|
| 114 |
+
"Run terminal command": "terminal_interface('command', 'project_name')",
|
| 115 |
+
"Generate code": "generate_code('code_idea')",
|
| 116 |
+
"Summarize text": "summarize_text('text')",
|
| 117 |
+
"Analyze sentiment": "sentiment_analysis('text')",
|
| 118 |
+
"Translate code": "translate_code('code', 'source_language', 'target_language')",
|
| 119 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Streamlit App
|
| 122 |
st.title("AI Agent Creator")
|
|
|
|
| 145 |
st.subheader("Chat with CodeCraft")
|
| 146 |
chat_input = st.text_area("Enter your message:")
|
| 147 |
if st.button("Send"):
|
| 148 |
+
if chat_input.startswith("@"):
|
| 149 |
+
agent_name = chat_input.split(" ")[0][1:] # Extract agent_name from @agent_name
|
| 150 |
+
chat_input = " ".join(chat_input.split(" ")[1:]) # Remove agent_name from input
|
| 151 |
+
chat_response = chat_interface_with_agent(chat_input, agent_name)
|
| 152 |
+
else:
|
| 153 |
+
chat_response = chat_interface(chat_input)
|
| 154 |
st.session_state.chat_history.append((chat_input, chat_response))
|
| 155 |
st.write(f"CodeCraft: {chat_response}")
|
| 156 |
|
|
|
|
| 187 |
# Text Translation Tool (Code Translation)
|
| 188 |
st.subheader("Translate Code")
|
| 189 |
code_to_translate = st.text_area("Enter code to translate:")
|
| 190 |
+
source_language = st.text_input("Enter source language (e.g. 'Python'):")
|
| 191 |
+
target_language = st.text_input("Enter target language (e.g. 'JavaScript'):")
|
| 192 |
if st.button("Translate Code"):
|
| 193 |
translated_code = translate_code(code_to_translate, source_language, target_language)
|
| 194 |
st.code(translated_code, language=target_language.lower())
|
|
|
|
| 200 |
generated_code = generate_code(code_idea)
|
| 201 |
st.code(generated_code, language="python")
|
| 202 |
|
| 203 |
+
# Display Preset Commands
|
| 204 |
+
st.subheader("Preset Commands")
|
| 205 |
+
for command_name, command in preset_commands.items():
|
| 206 |
+
st.write(f"{command_name}: `{command}`")
|
| 207 |
+
|
| 208 |
elif app_mode == "Workspace Chat App":
|
| 209 |
# Workspace Chat App
|
| 210 |
st.header("Workspace Chat App")
|
|
|
|
| 219 |
# Add Code to Workspace
|
| 220 |
st.subheader("Add Code to Workspace")
|
| 221 |
code_to_add = st.text_area("Enter code to add to workspace:")
|
| 222 |
+
file_name = st.text_input("Enter file name (e.g. 'app.py'):")
|
| 223 |
if st.button("Add Code"):
|
| 224 |
add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
|
| 225 |
st.success(add_code_status)
|