Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,12 @@ from rich.progress import track
|
|
13 |
from rich.table import Table
|
14 |
import subprocess
|
15 |
import threading
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# --- Constants ---
|
18 |
MODEL_NAME = "bigscience/bloom-1b7"
|
@@ -27,41 +33,41 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
27 |
|
28 |
# --- Agents ---
|
29 |
agents = {
|
30 |
-
"WEB_DEV": {
|
31 |
-
"description": "Expert in web development technologies and frameworks.",
|
32 |
-
"skills": ["HTML", "CSS", "JavaScript", "React", "Vue.js", "Flask", "Django", "Node.js", "Express.js"],
|
33 |
-
"system_prompt": "You are a web development expert. Your goal is to assist the user in building and deploying web applications. Provide code snippets, explanations, and guidance on best practices.",
|
34 |
-
},
|
35 |
-
"AI_SYSTEM_PROMPT": {
|
36 |
-
"description": "Expert in designing and implementing AI systems.",
|
37 |
-
"skills": ["Machine Learning", "Deep Learning", "Natural Language Processing", "Computer Vision", "Reinforcement Learning"],
|
38 |
-
"system_prompt": "You are an AI system expert. Your goal is to assist the user in designing and implementing AI systems. Provide code snippets, explanations, and guidance on best practices.",
|
39 |
-
},
|
40 |
-
"PYTHON_CODE_DEV": {
|
41 |
-
"description": "Expert in Python programming and development.",
|
42 |
-
"skills": ["Python", "Data Structures", "Algorithms", "Object-Oriented Programming", "Functional Programming"],
|
43 |
-
"system_prompt": "You are a Python code development expert. Your goal is to assist the user in writing and debugging Python code. Provide code snippets, explanations, and guidance on best practices.",
|
44 |
-
},
|
45 |
-
"CODE_REVIEW_ASSISTANT": {
|
46 |
-
"description": "Expert in code review and quality assurance.",
|
47 |
-
"skills": ["Code Style", "Best Practices", "Security", "Performance", "Maintainability"],
|
48 |
-
"system_prompt": "You are a code review assistant. Your goal is to assist the user in reviewing code for quality and efficiency. Provide feedback on code style, best practices, security, performance, and maintainability.",
|
49 |
-
},
|
50 |
-
"CONTENT_WRITER_EDITOR": {
|
51 |
-
"description": "Expert in content writing and editing.",
|
52 |
-
"skills": ["Grammar", "Style", "Clarity", "Conciseness", "SEO"],
|
53 |
-
"system_prompt": "You are a content writer and editor. Your goal is to assist the user in creating high-quality content. Provide suggestions on grammar, style, clarity, conciseness, and SEO.",
|
54 |
-
},
|
55 |
-
"QUESTION_GENERATOR": {
|
56 |
-
"description": "Expert in generating questions for learning and assessment.",
|
57 |
-
"skills": ["Question Types", "Cognitive Levels", "Assessment Design"],
|
58 |
-
"system_prompt": "You are a question generator. Your goal is to assist the user in generating questions for learning and assessment. Provide questions that are relevant to the topic and aligned with the cognitive levels.",
|
59 |
-
},
|
60 |
-
"HUGGINGFACE_FILE_DEV": {
|
61 |
-
"description": "Expert in developing Hugging Face files for machine learning models.",
|
62 |
-
"skills": ["Transformers", "Datasets", "Model Training", "Model Deployment"],
|
63 |
-
"system_prompt": "You are a Hugging Face file development expert. Your goal is to assist the user in creating and deploying Hugging Face files for machine learning models. Provide code snippets, explanations, and guidance on best practices.",
|
64 |
-
},
|
65 |
}
|
66 |
|
67 |
# --- Session State ---
|
@@ -103,13 +109,15 @@ def terminal_interface(command: str, project_name: str):
|
|
103 |
def chat_interface(message: str, selected_agents: List[str]):
|
104 |
responses = {}
|
105 |
for agent in selected_agents:
|
106 |
-
# Assuming a function `get_agent_response` that fetches the response from the agent
|
107 |
responses[agent] = get_agent_response(message, agents[agent]['system_prompt'])
|
108 |
return responses
|
109 |
|
110 |
def get_agent_response(message: str, system_prompt: str):
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
113 |
|
114 |
# --- Streamlit UI ---
|
115 |
st.title("DevToolKit: AI-Powered Development Environment")
|
@@ -200,4 +208,76 @@ gr.ChatInterface(
|
|
200 |
title="DevToolKit AI Assistant",
|
201 |
examples=examples,
|
202 |
concurrency_limit=20,
|
203 |
-
).launch(show_api=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from rich.table import Table
|
14 |
import subprocess
|
15 |
import threading
|
16 |
+
from langchain.llms import HuggingFaceHub
|
17 |
+
from langchain.chains import ConversationChain
|
18 |
+
from langchain.memory import ConversationBufferMemory
|
19 |
+
from langchain.chains.question_answering import load_qa_chain
|
20 |
+
from langchain.document_loaders import TextLoader
|
21 |
+
from langchain.text_splitter import CharacterTextSplitter
|
22 |
|
23 |
# --- Constants ---
|
24 |
MODEL_NAME = "bigscience/bloom-1b7"
|
|
|
33 |
|
34 |
# --- Agents ---
|
35 |
agents = {
|
36 |
+
"WEB_DEV": {
|
37 |
+
"description": "Expert in web development technologies and frameworks.",
|
38 |
+
"skills": ["HTML", "CSS", "JavaScript", "React", "Vue.js", "Flask", "Django", "Node.js", "Express.js"],
|
39 |
+
"system_prompt": "You are a web development expert. Your goal is to assist the user in building and deploying web applications. Provide code snippets, explanations, and guidance on best practices.",
|
40 |
+
},
|
41 |
+
"AI_SYSTEM_PROMPT": {
|
42 |
+
"description": "Expert in designing and implementing AI systems.",
|
43 |
+
"skills": ["Machine Learning", "Deep Learning", "Natural Language Processing", "Computer Vision", "Reinforcement Learning"],
|
44 |
+
"system_prompt": "You are an AI system expert. Your goal is to assist the user in designing and implementing AI systems. Provide code snippets, explanations, and guidance on best practices.",
|
45 |
+
},
|
46 |
+
"PYTHON_CODE_DEV": {
|
47 |
+
"description": "Expert in Python programming and development.",
|
48 |
+
"skills": ["Python", "Data Structures", "Algorithms", "Object-Oriented Programming", "Functional Programming"],
|
49 |
+
"system_prompt": "You are a Python code development expert. Your goal is to assist the user in writing and debugging Python code. Provide code snippets, explanations, and guidance on best practices.",
|
50 |
+
},
|
51 |
+
"CODE_REVIEW_ASSISTANT": {
|
52 |
+
"description": "Expert in code review and quality assurance.",
|
53 |
+
"skills": ["Code Style", "Best Practices", "Security", "Performance", "Maintainability"],
|
54 |
+
"system_prompt": "You are a code review assistant. Your goal is to assist the user in reviewing code for quality and efficiency. Provide feedback on code style, best practices, security, performance, and maintainability.",
|
55 |
+
},
|
56 |
+
"CONTENT_WRITER_EDITOR": {
|
57 |
+
"description": "Expert in content writing and editing.",
|
58 |
+
"skills": ["Grammar", "Style", "Clarity", "Conciseness", "SEO"],
|
59 |
+
"system_prompt": "You are a content writer and editor. Your goal is to assist the user in creating high-quality content. Provide suggestions on grammar, style, clarity, conciseness, and SEO.",
|
60 |
+
},
|
61 |
+
"QUESTION_GENERATOR": {
|
62 |
+
"description": "Expert in generating questions for learning and assessment.",
|
63 |
+
"skills": ["Question Types", "Cognitive Levels", "Assessment Design"],
|
64 |
+
"system_prompt": "You are a question generator. Your goal is to assist the user in generating questions for learning and assessment. Provide questions that are relevant to the topic and aligned with the cognitive levels.",
|
65 |
+
},
|
66 |
+
"HUGGINGFACE_FILE_DEV": {
|
67 |
+
"description": "Expert in developing Hugging Face files for machine learning models.",
|
68 |
+
"skills": ["Transformers", "Datasets", "Model Training", "Model Deployment"],
|
69 |
+
"system_prompt": "You are a Hugging Face file development expert. Your goal is to assist the user in creating and deploying Hugging Face files for machine learning models. Provide code snippets, explanations, and guidance on best practices.",
|
70 |
+
},
|
71 |
}
|
72 |
|
73 |
# --- Session State ---
|
|
|
109 |
def chat_interface(message: str, selected_agents: List[str]):
|
110 |
responses = {}
|
111 |
for agent in selected_agents:
|
|
|
112 |
responses[agent] = get_agent_response(message, agents[agent]['system_prompt'])
|
113 |
return responses
|
114 |
|
115 |
def get_agent_response(message: str, system_prompt: str):
|
116 |
+
llm = HuggingFaceHub(repo_id=MODEL_NAME, model_kwargs={"temperature": TEMPERATURE, "top_p": TOP_P, "repetition_penalty": REPETITION_PENALTY})
|
117 |
+
memory = ConversationBufferMemory()
|
118 |
+
conversation = ConversationChain(llm=llm, memory=memory)
|
119 |
+
response = conversation.run(system_prompt + "\n" + message)
|
120 |
+
return response
|
121 |
|
122 |
# --- Streamlit UI ---
|
123 |
st.title("DevToolKit: AI-Powered Development Environment")
|
|
|
208 |
title="DevToolKit AI Assistant",
|
209 |
examples=examples,
|
210 |
concurrency_limit=20,
|
211 |
+
).launch(show_api=True)
|
212 |
+
|
213 |
+
# --- Helper Functions ---
|
214 |
+
|
215 |
+
def display_agent_info(agent_name: str):
|
216 |
+
agent = agents[agent_name]
|
217 |
+
st.sidebar.subheader(f"Active Agent: {agent_name}")
|
218 |
+
st.sidebar.write(f"Description: {agent['description']}")
|
219 |
+
st.sidebar.write(f"Skills: {', '.join(agent['skills'])}")
|
220 |
+
|
221 |
+
def display_workspace_projects():
|
222 |
+
st.sidebar.subheader("Workspace Projects")
|
223 |
+
if st.session_state.workspace_projects:
|
224 |
+
for project_name in st.session_state.workspace_projects:
|
225 |
+
st.sidebar.write(f"- {project_name}")
|
226 |
+
else:
|
227 |
+
st.sidebar.write("No projects created yet.")
|
228 |
+
|
229 |
+
def display_chat_history():
|
230 |
+
st.sidebar.subheader("Chat History")
|
231 |
+
if st.session_state.chat_history:
|
232 |
+
for message in st.session_state.chat_history:
|
233 |
+
st.sidebar.write(message)
|
234 |
+
else:
|
235 |
+
st.sidebar.write("No chat history yet.")
|
236 |
+
|
237 |
+
def run_autonomous_build(selected_agents: List[str], project_name: str):
|
238 |
+
# This function should implement the autonomous build process
|
239 |
+
# It should use the selected agents and the project name to generate code and run commands
|
240 |
+
# You can use the `get_agent_response` function to get responses from agents
|
241 |
+
# You can use the `add_code_to_workspace` and `terminal_interface` functions to manage the workspace
|
242 |
+
st.write("Running autonomous build...")
|
243 |
+
for agent in selected_agents:
|
244 |
+
# Example: Get code from the agent
|
245 |
+
code = get_agent_response(f"Generate code for a simple web application in project {project_name}", agents[agent]['system_prompt'])
|
246 |
+
# Example: Add code to the workspace
|
247 |
+
add_code_to_workspace(project_name, code, "app.py")
|
248 |
+
# Example: Run a command in the workspace
|
249 |
+
terminal_interface("python app.py", project_name)
|
250 |
+
st.write("Autonomous build completed.")
|
251 |
+
|
252 |
+
# --- Collaborative Agent Example ---
|
253 |
+
|
254 |
+
def collaborative_agent_example(selected_agents: List[str], project_name: str, task: str):
|
255 |
+
# Example: Collaborative code generation
|
256 |
+
st.write(f"Running collaborative task: {task}")
|
257 |
+
responses = []
|
258 |
+
for agent in selected_agents:
|
259 |
+
response = get_agent_response(f"As a {agent}, please contribute to the following task: {task}", agents[agent]['system_prompt'])
|
260 |
+
responses.append(response)
|
261 |
+
|
262 |
+
# Combine responses and process them
|
263 |
+
combined_response = "\n".join(responses)
|
264 |
+
st.write(f"Combined response:\n{combined_response}")
|
265 |
+
|
266 |
+
# Example: Use code review agent for feedback
|
267 |
+
if "CODE_REVIEW_ASSISTANT" in selected_agents:
|
268 |
+
review_response = get_agent_response(f"Review the following code and provide feedback: {combined_response}", agents["CODE_REVIEW_ASSISTANT"]['system_prompt'])
|
269 |
+
st.write(f"Code Review Feedback:\n{review_response}")
|
270 |
+
|
271 |
+
# Example: Use content writer for documentation
|
272 |
+
if "CONTENT_WRITER_EDITOR" in selected_agents:
|
273 |
+
documentation_response = get_agent_response(f"Generate documentation for the following code: {combined_response}", agents["CONTENT_WRITER_EDITOR"]['system_prompt'])
|
274 |
+
st.write(f"Documentation:\n{documentation_response}")
|
275 |
+
|
276 |
+
# --- Streamlit UI for Collaborative Agent Example ---
|
277 |
+
|
278 |
+
st.subheader("Collaborative Agent Example")
|
279 |
+
selected_agents_example = st.multiselect("Select AI agents for collaboration", list(agents.keys()), key="agent_select_example")
|
280 |
+
project_name_example = st.text_input("Enter project name (for example purposes):")
|
281 |
+
task_example = st.text_input("Enter a task for the agents to collaborate on:")
|
282 |
+
if st.button("Run Collaborative Task"):
|
283 |
+
collaborative_agent_example(selected_agents_example, project_name_example, task_example)
|