Spaces:
Paused
Paused
Update app.py
Browse files1234567891025 unmodified lines3637383940414243444546474849505152535455565758596 unmodified lines6667686970717211 unmodified lines84858687888990918 unmodified lines10010110210310410510610766 unmodified lines1741751761771781791801818 unmodified lines19019119219319419519610 unmodified lines20720820921021121291 unmodified lines3043053063073083093105 unmodified lines316317318319320321322import osimport subprocessimport sys # Add sys importimport streamlit as stimport blackfrom pylint import lintfrom io import StringIOHUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"PROJECT_ROOT = "projects"25 unmodified linesagent_prompt = f"""As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:{skills_str}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."""return agent_promptdef autonomous_build(self, chat_history, workspace_projects):"""Autonomous build logic that continues based on the state of chat history and workspace projects."""summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])next_step = "Based on the current state, the next logical step is to implement the main application logic."return summary, next_stepdef save_agent_to_file(agent):"""Saves the agent's prompt to a file locally and then commits to the Hugging Face repository."""if not os.path.exists(AGENT_DIRECTORY):os.makedirs(AGENT_DIRECTORY)file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")6 unmodified linescommit_and_push_changes(f"Add agent {agent.name}")def load_agent_prompt(agent_name):"""Loads an agent prompt from a file."""file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")if os.path.exists(file_path):with open(file_path, "r") as file:11 unmodified linesdef chat_interface(input_text):"""Handles chat interactions without a specific agent."""try:model = InstructModel()response = model.generate_response(f"User: {input_text}\nAI:")return responseexcept EnvironmentError as e:return f"Error communicating with AI: {e}"8 unmodified linesexcept EnvironmentError as e:return f"Error loading model: {e}"combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"response = model.generate_response(combined_input) # Generate response using Mixtral Instructreturn responsedef workspace_interface(project_name):66 unmodified linesreturn translated_codeexcept EnvironmentError as e:return f"Error loading model or translating code: {e}"except Exception as e: # Catch other potential errors during translation.return f"An unexpected error occurred during code translation: {e}"def generate_code(code_idea):try:model = InstructModel() # Initialize Mixtral Instruct model8 unmodified linesdef commit_and_push_changes(commit_message):"""Commits and pushes changes to the Hugging Face repository (needs improvement)."""try:# Add error checking for git repository existence.subprocess.run(["git", "add", "."], check=True, capture_output=True, text=True)subprocess.run(["git", "commit", "-m", commit_message], check=True, capture_output=True, text=True)subprocess.run(["git", "push"], check=True, capture_output=True, text=True)10 unmodified linesapp_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])if app_mode == "AI Agent Creator":# AI Agent Creatorst.header("Create an AI Agent from Text")91 unmodified lines# Display Chat Historyst.subheader("Chat History")for user_input, response in st.session_state.chat_history:st.write(f"User: {user_input}")st.write(f"CodeCraft: {response}")# Display Terminal History5 unmodified lines# Display Projects and Filesst.subheader("Workspace Projects")for project, details in st.session_state.workspace_projects.items():st.write(f"Project: {project}")for file in details['files']:st.write(f" - {file}")12345678910111213141516171825 unmodified lines44454647484950515253545556575859606 unmodified lines67686970717211 unmodified lines84858687888990918 unmodified lines10010110210310410510610766 unmodified lines1741751761771781791801811828 unmodified lines19119219319419519610 unmodified lines20720820921021121221391 unmodified lines3053063073083093103115 unmodified lines317318319320321322323import osimport subprocessimport sysimport streamlit as stimport blackfrom pylint import lintfrom io import StringIOimport requestsimport loggingimport atexitimport timefrom datetime import datetime# Import the InstructModel from the appropriate libraryfrom mistralai import InstructModel # Ensure you have the correct import for the modelHUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"PROJECT_ROOT = "projects"25 unmodified linesagent_prompt = f"""As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:{skills_str}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."""return agent_promptdef autonomous_build(self, chat_history, workspace_projects):summary = "Chat History:\n" + "\n".join([f":User {u}\nAgent: {a}" for u, a in chat_history])summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])next_step = "Based on the current state, the next logical step is to implement the main application logic."return summary, next_stepdef save_agent_to_file(agent):if not os.path.exists(AGENT_DIRECTORY):os.makedirs(AGENT_DIRECTORY)file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")6 unmodified linescommit_and_push_changes(f"Add agent {agent.name}")def load_agent_prompt(agent_name):file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")if os.path.exists(file_path):with open(file_path, "r") as file:11 unmodified linesdef chat_interface(input_text):"""Handles chat interactions without a specific agent."""try:model = InstructModel() # Initialize the Mixtral Instruct modelresponse = model.generate_response(f":User {input_text}\nAI:")return responseexcept EnvironmentError as e:return f"Error communicating with AI: {e}"8 unmodified linesexcept EnvironmentError as e:return f"Error loading model: {e}"combined_input = f"{agent_prompt}\n\n:User {input_text}\nAgent:"response = model.generate_response(combined_input) ```pythonreturn responsedef workspace_interface(project_name):66 unmodified linesreturn translated_codeexcept EnvironmentError as e:return f"Error loading model or translating code: {e}"except Exception as e:return f"An unexpected error occurred during code translation: {e}"def generate_code(code_idea):try:model = InstructModel() # Initialize Mixtral Instruct model8 unmodified linesdef commit_and_push_changes(commit_message):"""Commits and pushes changes to the Hugging Face repository (needs improvement)."""try:subprocess.run(["git", "add", "."], check=True, capture_output=True, text=True)subprocess.run(["git", "commit", "-m", commit_message], check=True, capture_output=True, text=True)subprocess.run(["git", "push"], check=True, capture_output=True, text=True)10 unmodified linesapp_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])if app_mode == "AI Agent Creator":```python# AI Agent Creatorst.header("Create an AI Agent from Text")91 unmodified lines# Display Chat Historyst.subheader("Chat History")for user_input, response in st.session_state.chat_history:st.write(f":User {user_input}")st.write(f"CodeCraft: {response}")# Display Terminal History5 unmodified lines# Display Projects and Filesst.subheader("Workspace Projects")for project, details in st.session_state.workspace_projects.items():st.write(f"Project: {project }")for file in details['files']:st.write(f" - {file}")
app.py+19-18