Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -99,7 +99,7 @@ def chat_interface_with_agent(input_text, agent_name):
|
|
99 |
|
100 |
# Combine the agent prompt with user input
|
101 |
combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
|
102 |
-
|
103 |
# Truncate input text to avoid exceeding the model's maximum length
|
104 |
max_input_length = 900
|
105 |
input_ids = tokenizer.encode(combined_input, return_tensors="pt")
|
@@ -178,13 +178,22 @@ def generate_code(code_idea):
|
|
178 |
{"role": "user", "content": f"Generate a Python code snippet for the following idea:\n\n{code_idea}"}
|
179 |
]
|
180 |
st.session_state.current_state['toolbox']['generated_code'] = generated_code
|
181 |
-
|
182 |
return generated_code
|
183 |
-
|
184 |
def translate_code(code, input_language, output_language):
|
185 |
# Define a dictionary to map programming languages to their corresponding file extensions
|
186 |
language_extensions = {
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
}
|
189 |
|
190 |
# Add code to handle edge cases such as invalid input and unsupported programming languages
|
@@ -307,11 +316,11 @@ elif app_mode == "Tool Box":
|
|
307 |
# Text Translation Tool (Code Translation)
|
308 |
st.subheader("Translate Code")
|
309 |
code_to_translate = st.text_area("Enter code to translate:")
|
310 |
-
|
311 |
-
|
312 |
if st.button("Translate Code"):
|
313 |
-
translated_code = translate_code(code_to_translate,
|
314 |
-
st.code(translated_code, language=
|
315 |
|
316 |
# Code Generation
|
317 |
st.subheader("Code Generation")
|
@@ -384,28 +393,6 @@ elif app_mode == "Workspace Chat App":
|
|
384 |
st.subheader("Workspace Projects")
|
385 |
for project, details in st.session_state.workspace_projects.items():
|
386 |
st.write(f"Project: {project}")
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
# Chat with AI Agents
|
391 |
-
st.subheader("Chat with AI Agents")
|
392 |
-
selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
|
393 |
-
agent_chat_input = st.text_area("Enter your message for the agent:")
|
394 |
-
if st.button("Send to Agent"):
|
395 |
-
agent_chat_response = chat_interface_with_agent(agent_chat_input, selected_agent)
|
396 |
-
st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
|
397 |
-
st.write(f"{selected_agent}: {agent_chat_response}")
|
398 |
-
|
399 |
-
# Automate Build Process
|
400 |
-
st.subheader("Automate Build Process")
|
401 |
-
if st.button("Automate"):
|
402 |
-
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
403 |
-
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
|
404 |
-
st.write("Autonomous Build Summary:")
|
405 |
-
st.write(summary)
|
406 |
-
st.write("Next Step:")
|
407 |
-
st.write(next_step)
|
408 |
-
|
409 |
-
# Display current state for debugging
|
410 |
-
st.sidebar.subheader("Current State")
|
411 |
-
st.sidebar.json(st.session_state.current_state)
|
|
|
99 |
|
100 |
# Combine the agent prompt with user input
|
101 |
combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
|
102 |
+
|
103 |
# Truncate input text to avoid exceeding the model's maximum length
|
104 |
max_input_length = 900
|
105 |
input_ids = tokenizer.encode(combined_input, return_tensors="pt")
|
|
|
178 |
{"role": "user", "content": f"Generate a Python code snippet for the following idea:\n\n{code_idea}"}
|
179 |
]
|
180 |
st.session_state.current_state['toolbox']['generated_code'] = generated_code
|
181 |
+
|
182 |
return generated_code
|
183 |
+
|
184 |
def translate_code(code, input_language, output_language):
|
185 |
# Define a dictionary to map programming languages to their corresponding file extensions
|
186 |
language_extensions = {
|
187 |
+
"Python": "py",
|
188 |
+
"JavaScript": "js",
|
189 |
+
"Java": "java",
|
190 |
+
"C++": "cpp",
|
191 |
+
"C#": "cs",
|
192 |
+
"Ruby": "rb",
|
193 |
+
"Go": "go",
|
194 |
+
"PHP": "php",
|
195 |
+
"Swift": "swift",
|
196 |
+
"TypeScript": "ts",
|
197 |
}
|
198 |
|
199 |
# Add code to handle edge cases such as invalid input and unsupported programming languages
|
|
|
316 |
# Text Translation Tool (Code Translation)
|
317 |
st.subheader("Translate Code")
|
318 |
code_to_translate = st.text_area("Enter code to translate:")
|
319 |
+
input_language = st.text_input("Enter input language (e.g. 'Python'):")
|
320 |
+
output_language = st.text_input("Enter output language (e.g. 'JavaScript'):")
|
321 |
if st.button("Translate Code"):
|
322 |
+
translated_code = translate_code(code_to_translate, input_language, output_language)
|
323 |
+
st.code(translated_code, language=output_language.lower())
|
324 |
|
325 |
# Code Generation
|
326 |
st.subheader("Code Generation")
|
|
|
393 |
st.subheader("Workspace Projects")
|
394 |
for project, details in st.session_state.workspace_projects.items():
|
395 |
st.write(f"Project: {project}")
|
396 |
+
st.write("Files:")
|
397 |
+
for file in details["files"]:
|
398 |
+
st.write(f"- {file}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|