Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -29,6 +29,7 @@ class AIAgent: | |
| 29 | 
             
                    self.name = name
         | 
| 30 | 
             
                    self.description = description
         | 
| 31 | 
             
                    self.skills = skills
         | 
|  | |
| 32 |  | 
| 33 | 
             
                def create_agent_prompt(self):
         | 
| 34 | 
             
                    skills_str = '\n'.join([f"* {skill}" for skill in self.skills])
         | 
| @@ -47,8 +48,19 @@ I am confident that I can leverage my expertise to assist you in developing and | |
| 47 | 
             
                    return summary, next_step
         | 
| 48 |  | 
| 49 | 
             
                def deploy_built_space_to_hf(self):
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 50 | 
             
                    pass
         | 
| 51 |  | 
|  | |
|  | |
|  | |
| 52 | 
             
            def process_input(input_text):
         | 
| 53 | 
             
                chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", tokenizer="microsoft/DialoGPT-medium")
         | 
| 54 | 
             
                response = chatbot(input_text, max_length=50, num_return_sequences=1)[0]['generated_text']
         | 
| @@ -88,74 +100,86 @@ def display_workspace_projects(workspace_projects): | |
| 88 | 
             
                return "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
         | 
| 89 |  | 
| 90 | 
             
            if __name__ == "__main__":
         | 
| 91 | 
            -
                st. | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
                 | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
                 | 
| 100 | 
            -
                    st. | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
                         | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
                     | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
                        st. | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
                     | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
                 | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
                 | 
| 144 | 
            -
             | 
| 145 | 
            -
                     | 
| 146 | 
            -
                     | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 159 |  | 
| 160 | 
             
                # CSS for styling
         | 
| 161 | 
             
                st.markdown("""
         | 
|  | |
| 29 | 
             
                    self.name = name
         | 
| 30 | 
             
                    self.description = description
         | 
| 31 | 
             
                    self.skills = skills
         | 
| 32 | 
            +
                    self._hf_api = HfApi(token=huggingface_token)
         | 
| 33 |  | 
| 34 | 
             
                def create_agent_prompt(self):
         | 
| 35 | 
             
                    skills_str = '\n'.join([f"* {skill}" for skill in self.skills])
         | 
|  | |
| 48 | 
             
                    return summary, next_step
         | 
| 49 |  | 
| 50 | 
             
                def deploy_built_space_to_hf(self):
         | 
| 51 | 
            +
                    # Implement logic to deploy the built space to Hugging Face Spaces
         | 
| 52 | 
            +
                    # This could involve creating a new Space, uploading files, and configuring the Space
         | 
| 53 | 
            +
                    # Use the HfApi to interact with the Hugging Face API
         | 
| 54 | 
            +
                    # Example:
         | 
| 55 | 
            +
                    # repository = self._hf_api.create_repo(repo_id="my-new-space", private=False)
         | 
| 56 | 
            +
                    # ... upload files to the repository
         | 
| 57 | 
            +
                    # ... configure the Space
         | 
| 58 | 
            +
                    # return repository
         | 
| 59 | 
             
                    pass
         | 
| 60 |  | 
| 61 | 
            +
                def has_valid_hf_token(self):
         | 
| 62 | 
            +
                    return self._hf_api.whoami() is not None
         | 
| 63 | 
            +
             | 
| 64 | 
             
            def process_input(input_text):
         | 
| 65 | 
             
                chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", tokenizer="microsoft/DialoGPT-medium")
         | 
| 66 | 
             
                response = chatbot(input_text, max_length=50, num_return_sequences=1)[0]['generated_text']
         | 
|  | |
| 100 | 
             
                return "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
         | 
| 101 |  | 
| 102 | 
             
            if __name__ == "__main__":
         | 
| 103 | 
            +
                st.set_page_config(layout="wide", page_title="AI-Powered Development Platform")
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                # Sidebar
         | 
| 106 | 
            +
                st.sidebar.title("AI Development Platform")
         | 
| 107 | 
            +
                st.sidebar.header("Tool Box")
         | 
| 108 | 
            +
                st.sidebar.subheader("Workspace Management")
         | 
| 109 | 
            +
                project_name_input = st.sidebar.text_input("Project Name:")
         | 
| 110 | 
            +
                create_project_button = st.sidebar.button("Create Project")
         | 
| 111 | 
            +
                if create_project_button:
         | 
| 112 | 
            +
                    st.sidebar.write(workspace_interface(project_name_input))
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                st.sidebar.subheader("Code Generation")
         | 
| 115 | 
            +
                selected_model = st.sidebar.selectbox("Select Code Model", AVAILABLE_CODE_GENERATIVE_MODELS)
         | 
| 116 | 
            +
                code_input = st.sidebar.text_area("Enter Code Prompt:")
         | 
| 117 | 
            +
                generate_code_button = st.sidebar.button("Generate Code")
         | 
| 118 | 
            +
                if generate_code_button:
         | 
| 119 | 
            +
                    if selected_model:
         | 
| 120 | 
            +
                        tokenizer = AutoTokenizer.from_pretrained(selected_model)
         | 
| 121 | 
            +
                        model = AutoModelForCausalLM.from_pretrained(selected_model)
         | 
| 122 | 
            +
                        code_generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
         | 
| 123 | 
            +
                        generated_code = code_generator(code_input, max_length=500, num_return_sequences=1)[0]['generated_text']
         | 
| 124 | 
            +
                        st.sidebar.code(generated_code)
         | 
| 125 | 
            +
                    else:
         | 
| 126 | 
            +
                        st.sidebar.error("Please select a code model.")
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                st.sidebar.subheader("Terminal")
         | 
| 129 | 
            +
                command = st.sidebar.text_input("Enter a command:")
         | 
| 130 | 
            +
                if command:
         | 
| 131 | 
            +
                    output, error = run_command(command)
         | 
| 132 | 
            +
                    if error:
         | 
| 133 | 
            +
                        st.sidebar.error(f"Error executing command: {error}")
         | 
| 134 | 
            +
                    else:
         | 
| 135 | 
            +
                        st.sidebar.code(output)
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                # Main Content
         | 
| 138 | 
            +
                st.title("AI-Powered Development Platform")
         | 
| 139 | 
            +
                st.header("Workspace")
         | 
| 140 | 
            +
                st.subheader("Chat with an AI Agent")
         | 
| 141 | 
            +
                chat_input = st.text_input("Enter your message:")
         | 
| 142 | 
            +
                if chat_input:
         | 
| 143 | 
            +
                    st.session_state.chat_history.append((chat_input, process_input(chat_input)))
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                st.markdown("## Chat History ##")
         | 
| 146 | 
            +
                st.markdown(display_chat_history(st.session_state.chat_history))
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                st.subheader("Available Agents")
         | 
| 149 | 
            +
                for agent_name in st.session_state.available_agents:
         | 
| 150 | 
            +
                    st.write(f"**{agent_name}**")
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                st.subheader("Project Management")
         | 
| 153 | 
            +
                st.markdown(display_workspace_projects(st.session_state.workspace_projects))
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                # AI Guide
         | 
| 156 | 
            +
                if ai_guide_level == "Full Assistance":
         | 
| 157 | 
            +
                    st.markdown("## AI Guide: Full Assistance ##")
         | 
| 158 | 
            +
                    st.write("**Recommended Action:**")
         | 
| 159 | 
            +
                    st.write("Create a new project and then generate some code.")
         | 
| 160 | 
            +
                elif ai_guide_level == "Partial Assistance":
         | 
| 161 | 
            +
                    st.markdown("## AI Guide: Partial Assistance ##")
         | 
| 162 | 
            +
                    st.write("**Tips:**")
         | 
| 163 | 
            +
                    st.write("Use the chat interface to ask questions about your project.")
         | 
| 164 | 
            +
                    st.write("Use the code generation tool to generate code snippets.")
         | 
| 165 | 
            +
                else:
         | 
| 166 | 
            +
                    st.markdown("## AI Guide: No Assistance ##")
         | 
| 167 | 
            +
                    st.write("You are on your own!")
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                # Autonomous Build
         | 
| 170 | 
            +
                if st.button("Autonomous Build"):
         | 
| 171 | 
            +
                    project_name = project_name_input
         | 
| 172 | 
            +
                    selected_model = selected_model
         | 
| 173 | 
            +
                    agent = AIAgent("Code Architect", "I am an expert in code generation and deployment.", ["Code Generation", "Deployment"])
         | 
| 174 | 
            +
                    summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects, project_name, selected_model, huggingface_token)
         | 
| 175 | 
            +
                    st.write("Autonomous Build Summary:")
         | 
| 176 | 
            +
                    st.write(summary)
         | 
| 177 | 
            +
                    st.write("Next Step:")
         | 
| 178 | 
            +
                    st.write(next_step)
         | 
| 179 | 
            +
                    if agent._hf_api and agent.has_valid_hf_token():
         | 
| 180 | 
            +
                        repository = agent.deploy_built_space_to_hf()
         | 
| 181 | 
            +
                        st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
         | 
| 182 | 
            +
                        st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
         | 
| 183 |  | 
| 184 | 
             
                # CSS for styling
         | 
| 185 | 
             
                st.markdown("""
         | 
 
			
