Spaces:
Running
Running
acecalisto3
commited on
Commit
•
20250e3
1
Parent(s):
79ecef6
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
import streamlit as st
|
4 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
5 |
import black
|
6 |
from pylint import lint
|
7 |
from io import StringIO
|
@@ -30,6 +30,15 @@ if 'current_state' not in st.session_state:
|
|
30 |
'workspace_chat': {}
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
class AIAgent:
|
34 |
def __init__(self, name, description, skills):
|
35 |
self.name = name
|
@@ -41,12 +50,11 @@ class AIAgent:
|
|
41 |
agent_prompt = f"""
|
42 |
As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
|
43 |
{skills_str}
|
44 |
-
|
45 |
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.
|
46 |
"""
|
47 |
return agent_prompt
|
48 |
|
49 |
-
def autonomous_build(self, chat_history, workspace_projects):
|
50 |
"""
|
51 |
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
52 |
"""
|
@@ -66,6 +74,39 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
66 |
# Generate a response based on the analysis
|
67 |
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
return summary, next_step
|
70 |
|
71 |
def save_agent_to_file(agent):
|
@@ -170,11 +211,14 @@ def translate_code(code, source_language, target_language):
|
|
170 |
translated_code = translator(code, target_lang=target_language)[0]['translation_text']
|
171 |
return translated_code
|
172 |
|
173 |
-
def generate_code(code_idea):
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
178 |
|
179 |
def chat_interface(input_text):
|
180 |
"""Handles general chat interactions with the user."""
|
@@ -293,6 +337,18 @@ elif app_mode == "Workspace Chat App":
|
|
293 |
workspace_status = workspace_interface(project_name)
|
294 |
st.success(workspace_status)
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
# Add Code to Workspace
|
297 |
st.subheader("Add Code to Workspace")
|
298 |
code_to_add = st.text_area("Enter code to add to workspace:")
|
@@ -344,11 +400,22 @@ elif app_mode == "Workspace Chat App":
|
|
344 |
st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
|
345 |
st.write(f"{selected_agent}: {agent_chat_response}")
|
346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
# Automate Build Process
|
348 |
st.subheader("Automate Build Process")
|
349 |
if st.button("Automate"):
|
350 |
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
351 |
-
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects)
|
352 |
st.write("Autonomous Build Summary:")
|
353 |
st.write(summary)
|
354 |
st.write("Next Step:")
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
import streamlit as st
|
4 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer, AutoModel
|
5 |
import black
|
6 |
from pylint import lint
|
7 |
from io import StringIO
|
|
|
30 |
'workspace_chat': {}
|
31 |
}
|
32 |
|
33 |
+
# List of top downloaded free code-generative models from Hugging Face Hub
|
34 |
+
AVAILABLE_CODE_GENERATIVE_MODELS = [
|
35 |
+
"bigcode/starcoder", # Popular and powerful
|
36 |
+
"Salesforce/codegen-350M-mono", # Smaller, good for quick tasks
|
37 |
+
"microsoft/CodeGPT-small", # Smaller, good for quick tasks
|
38 |
+
"google/flan-t5-xl", # Powerful, good for complex tasks
|
39 |
+
"facebook/bart-large-cnn", # Good for text-to-code tasks
|
40 |
+
]
|
41 |
+
|
42 |
class AIAgent:
|
43 |
def __init__(self, name, description, skills):
|
44 |
self.name = name
|
|
|
50 |
agent_prompt = f"""
|
51 |
As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
|
52 |
{skills_str}
|
|
|
53 |
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.
|
54 |
"""
|
55 |
return agent_prompt
|
56 |
|
57 |
+
def autonomous_build(self, chat_history, workspace_projects, project_name, selected_model):
|
58 |
"""
|
59 |
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
60 |
"""
|
|
|
74 |
# Generate a response based on the analysis
|
75 |
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
76 |
|
77 |
+
# Ensure project folder exists
|
78 |
+
project_path = os.path.join(PROJECT_ROOT, project_name)
|
79 |
+
if not os.path.exists(project_path):
|
80 |
+
os.makedirs(project_path)
|
81 |
+
|
82 |
+
# Create requirements.txt if it doesn't exist
|
83 |
+
requirements_file = os.path.join(project_path, "requirements.txt")
|
84 |
+
if not os.path.exists(requirements_file):
|
85 |
+
with open(requirements_file, "w") as f:
|
86 |
+
f.write("# Add your project's dependencies here\n")
|
87 |
+
|
88 |
+
# Create app.py if it doesn't exist
|
89 |
+
app_file = os.path.join(project_path, "app.py")
|
90 |
+
if not os.path.exists(app_file):
|
91 |
+
with open(app_file, "w") as f:
|
92 |
+
f.write("# Your project's main application logic goes here\n")
|
93 |
+
|
94 |
+
# Generate GUI code for app.py if requested
|
95 |
+
if "create a gui" in summary.lower():
|
96 |
+
gui_code = generate_code("Create a simple GUI for this application", selected_model)
|
97 |
+
with open(app_file, "a") as f:
|
98 |
+
f.write(gui_code)
|
99 |
+
|
100 |
+
# Run the default build process
|
101 |
+
build_command = "pip install -r requirements.txt && python app.py"
|
102 |
+
try:
|
103 |
+
result = subprocess.run(build_command, shell=True, capture_output=True, text=True, cwd=project_path)
|
104 |
+
st.write(f"Build Output:\n{result.stdout}")
|
105 |
+
if result.stderr:
|
106 |
+
st.error(f"Build Errors:\n{result.stderr}")
|
107 |
+
except Exception as e:
|
108 |
+
st.error(f"Build Error: {e}")
|
109 |
+
|
110 |
return summary, next_step
|
111 |
|
112 |
def save_agent_to_file(agent):
|
|
|
211 |
translated_code = translator(code, target_lang=target_language)[0]['translation_text']
|
212 |
return translated_code
|
213 |
|
214 |
+
def generate_code(code_idea, model_name):
|
215 |
+
"""Generates code using the selected model."""
|
216 |
+
try:
|
217 |
+
generator = pipeline('text-generation', model=model_name)
|
218 |
+
generated_code = generator(code_idea, max_length=1000, num_return_sequences=1)[0]['generated_text']
|
219 |
+
return generated_code
|
220 |
+
except Exception as e:
|
221 |
+
return f"Error generating code: {e}"
|
222 |
|
223 |
def chat_interface(input_text):
|
224 |
"""Handles general chat interactions with the user."""
|
|
|
337 |
workspace_status = workspace_interface(project_name)
|
338 |
st.success(workspace_status)
|
339 |
|
340 |
+
# Automatically create requirements.txt and app.py
|
341 |
+
project_path = os.path.join(PROJECT_ROOT, project_name)
|
342 |
+
requirements_file = os.path.join(project_path, "requirements.txt")
|
343 |
+
if not os.path.exists(requirements_file):
|
344 |
+
with open(requirements_file, "w") as f:
|
345 |
+
f.write("# Add your project's dependencies here\n")
|
346 |
+
|
347 |
+
app_file = os.path.join(project_path, "app.py")
|
348 |
+
if not os.path.exists(app_file):
|
349 |
+
with open(app_file, "w") as f:
|
350 |
+
f.write("# Your project's main application logic goes here\n")
|
351 |
+
|
352 |
# Add Code to Workspace
|
353 |
st.subheader("Add Code to Workspace")
|
354 |
code_to_add = st.text_area("Enter code to add to workspace:")
|
|
|
400 |
st.session_state.chat_history.append((agent_chat_input, agent_chat_response))
|
401 |
st.write(f"{selected_agent}: {agent_chat_response}")
|
402 |
|
403 |
+
# Code Generation
|
404 |
+
st.subheader("Code Generation")
|
405 |
+
code_idea = st.text_input("Enter your code idea:")
|
406 |
+
|
407 |
+
# Model Selection Menu
|
408 |
+
selected_model = st.selectbox("Select a code-generative model", AVAILABLE_CODE_GENERATIVE_MODELS)
|
409 |
+
|
410 |
+
if st.button("Generate Code"):
|
411 |
+
generated_code = generate_code(code_idea, selected_model)
|
412 |
+
st.code(generated_code, language="python")
|
413 |
+
|
414 |
# Automate Build Process
|
415 |
st.subheader("Automate Build Process")
|
416 |
if st.button("Automate"):
|
417 |
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
418 |
+
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects, project_name, selected_model)
|
419 |
st.write("Autonomous Build Summary:")
|
420 |
st.write(summary)
|
421 |
st.write("Next Step:")
|