Falln87 commited on
Commit
f2bc6e2
·
verified ·
1 Parent(s): 6e2124b

Upload 9 files

Browse files
Files changed (9) hide show
  1. Dockerfile +31 -0
  2. agents.py +80 -0
  3. app.py +105 -0
  4. github_manager.py +50 -0
  5. index.html +102 -0
  6. readme.md +24 -0
  7. requirements.txt +9 -0
  8. run.sh +16 -0
  9. task.py +77 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a base image with Python 3.10 and CUDA for GPU support
2
+ FROM python:3.10-slim
3
+
4
+ # Install system dependencies for Docker and Git
5
+ RUN apt-get update && apt-get install -y \
6
+ curl \
7
+ git \
8
+ build-essential \
9
+ libffi-dev \
10
+ libssl-dev \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Install Docker inside the container
14
+ RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
15
+ RUN usermod -aG docker www-data
16
+
17
+ # Set the working directory
18
+ WORKDIR /app
19
+
20
+ # Copy the application files
21
+ COPY . /app
22
+
23
+ # Install Python dependencies
24
+ # We use --no-cache-dir to save space
25
+ RUN pip install --no-cache-dir -r requirements.txt
26
+
27
+ # Expose the port for the Flask application
28
+ EXPOSE 7860
29
+
30
+ # Command to run the application
31
+ CMD ["bash", "run.sh"]
agents.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FallnAI Autonomous Software Developer
2
+ # agent.py
3
+
4
+ from crewai import Agent
5
+ from crewai_tools import SerperDevTool
6
+
7
+ # Define search tool
8
+ search_tool = SerperDevTool()
9
+
10
+ # Define the Planner Agent
11
+ planner_agent = Agent(
12
+ role="Software Architect",
13
+ goal="""Create a detailed, step-by-step plan to develop a new software application
14
+ based on the user's request. Break down the project into manageable tasks
15
+ for other agents.""",
16
+ backstory="""You are a seasoned software architect with a passion for designing elegant
17
+ and efficient systems. You excel at translating vague ideas into clear,
18
+ actionable project plans.""",
19
+ verbose=True,
20
+ allow_delegation=False
21
+ )
22
+
23
+ # Define the Coder Agent
24
+ coder_agent = Agent(
25
+ role="Senior Python Developer",
26
+ goal="""Write high-quality, bug-free, and well-commented Python code according to the
27
+ project plan. Ensure the code is clean and adheres to best practices.""",
28
+ backstory="""You are a highly skilled Python developer with a knack for solving complex
29
+ problems. You write robust code that is easy to read and maintain.""",
30
+ verbose=True,
31
+ allow_delegation=False
32
+ )
33
+
34
+ # Define the Tester Agent
35
+ tester_agent = Agent(
36
+ role="Quality Assurance Engineer",
37
+ goal="""Test the developed code for bugs, errors, and edge cases. Provide detailed
38
+ feedback to the Coder Agent to ensure the final product is flawless.""",
39
+ backstory="""You are a meticulous and thorough QA engineer. You find pleasure in breaking
40
+ code and providing constructive criticism to improve its quality.""",
41
+ verbose=True,
42
+ allow_delegation=False
43
+ )
44
+
45
+ # Define the UI Designer Agent
46
+ ui_designer_agent = Agent(
47
+ role="Frontend Developer",
48
+ goal="""Create a simple but functional user interface for the software. Use HTML and
49
+ CSS to design a clean and intuitive layout.""",
50
+ backstory="""You are a creative frontend developer who can turn any concept into a
51
+ visually appealing and easy-to-use interface. You specialize in rapid
52
+ prototyping with basic web technologies.""",
53
+ verbose=True,
54
+ allow_delegation=False
55
+ )
56
+
57
+ # Define the Documentation Agent
58
+ docs_agent = Agent(
59
+ role="Technical Writer",
60
+ goal="""Write high-quality documentation, including a README.md file, for the software.
61
+ The documentation should explain the project's purpose, how to use it, and how to install dependencies.""",
62
+ backstory="""You are a skilled technical writer who specializes in making complex topics easy to understand.
63
+ You create excellent READMEs and other project documentation.""",
64
+ verbose=True,
65
+ allow_delegation=False
66
+ )
67
+
68
+ # Define the DevOps Agent
69
+ devops_agent = Agent(
70
+ role="DevOps Engineer",
71
+ goal="""Manage repository creation and push the final, working code to GitHub.
72
+ Automate the deployment process.""",
73
+ backstory="""You are an expert in continuous integration and deployment.
74
+ You handle all aspects of getting the software from development
75
+ to a live, accessible repository.""",
76
+ verbose=True,
77
+ allow_delegation=False
78
+ )
79
+
80
+
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #FallnAI Autonomous Software Developer
2
+ #app.py
3
+
4
+ import os
5
+ import json
6
+ import subprocess
7
+ import tempfile
8
+ import time
9
+ import re
10
+ from flask import Flask, request, jsonify
11
+ from crewai import Crew, Process
12
+ from crewai.agent import Agent
13
+ from crewai.task import Task
14
+ from crewai.tools import Tool
15
+ from textwrap import dedent
16
+ from crewai_tools import SerperDevTool
17
+
18
+ # Import agent and task classes
19
+ from agents import planner_agent, coder_agent, tester_agent, ui_designer_agent, docs_agent, devops_agent
20
+ from tasks import SoftwareDevelopmentTasks
21
+
22
+ # Import the GitHub Manager
23
+ from github_manager import GitHubManager
24
+
25
+ app = Flask(__name__)
26
+
27
+ # --- Configuration ---
28
+ # GitHub Token from environment variable
29
+ # IMPORTANT: Never hardcode this token.
30
+ GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
31
+ if not GITHUB_TOKEN:
32
+ print("Warning: GITHUB_TOKEN environment variable not set. GitHub push will fail.")
33
+
34
+ # Initialize the GitHub tool
35
+ github_tool = Tool(
36
+ name="GitHub_Manager",
37
+ func=GitHubManager(GITHUB_TOKEN).create_and_push_repo,
38
+ description="A tool to create and push files to a new GitHub repository."
39
+ )
40
+
41
+ @app.route('/develop', methods=['POST'])
42
+ def develop_software():
43
+ data = request.json
44
+ user_prompt = data.get('prompt')
45
+
46
+ if not user_prompt:
47
+ return jsonify({"error": "No prompt provided"}), 400
48
+
49
+ # Sanitize and create a unique repository name
50
+ sanitized_prompt = re.sub(r'[^a-zA-Z0-9-]', '', user_prompt[:30]).lower()
51
+ timestamp = int(time.time())
52
+ repo_name = f"auto-dev-{sanitized_prompt}-{timestamp}"
53
+
54
+ try:
55
+ # Create a new crew for this request
56
+ tasks = SoftwareDevelopmentTasks(user_prompt)
57
+
58
+ # Add the GitHub tool to the DevOps agent
59
+ devops_agent.tools.append(github_tool)
60
+
61
+ crew = Crew(
62
+ agents=[planner_agent, coder_agent, tester_agent, ui_designer_agent, docs_agent, devops_agent],
63
+ tasks=[
64
+ tasks.plan_software(planner_agent),
65
+ tasks.write_code(coder_agent),
66
+ tasks.write_ui(ui_designer_agent),
67
+ tasks.review_and_test(tester_agent),
68
+ tasks.write_documentation(docs_agent), # New documentation task
69
+ tasks.push_to_github(devops_agent, repo_name=repo_name) # Pass repo_name
70
+ ],
71
+ process=Process.sequential,
72
+ verbose=2
73
+ )
74
+
75
+ # Kick off the development process
76
+ result = crew.kickoff()
77
+
78
+ # Extract the final outputs to be pushed
79
+ final_code = ""
80
+ final_ui = ""
81
+ final_docs = ""
82
+ for task_result in crew.tasks_outputs:
83
+ if "code" in task_result.description.lower():
84
+ final_code = task_result.output
85
+ if "ui" in task_result.description.lower():
86
+ final_ui = task_result.output
87
+ if "documentation" in task_result.description.lower():
88
+ final_docs = task_result.output
89
+
90
+ # Final step is to get the push result and include it in the response
91
+ final_result = crew.kickoff()
92
+
93
+ return jsonify({
94
+ "status": "success",
95
+ "log": final_result,
96
+ "final_code": final_code,
97
+ "final_ui": final_ui,
98
+ "final_docs": final_docs
99
+ })
100
+
101
+ except Exception as e:
102
+ return jsonify({"error": str(e)}), 500
103
+
104
+ if __name__ == '__main__':
105
+ app.run(host='0.0.0.0', port=5000)
github_manager.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FallnAI Autonomous Software Developer
2
+ # github_manager.py
3
+
4
+ import os
5
+ from github import Github, InputGitTreeElement
6
+
7
+ class GitHubManager:
8
+ """A tool to manage GitHub repositories and push code."""
9
+
10
+ def __init__(self, token):
11
+ self.github = Github(token)
12
+
13
+ def create_and_push_repo(self, repo_name, commit_message, files):
14
+ """
15
+ Creates a new public repository and pushes a set of files to it.
16
+
17
+ :param repo_name: The name for the new repository.
18
+ :param commit_message: The message for the initial commit.
19
+ :param files: A dictionary of {file_path: file_content}.
20
+ :return: The URL of the new repository on success, or an error message.
21
+ """
22
+ try:
23
+ user = self.github.get_user()
24
+
25
+ # Check if repo already exists
26
+ try:
27
+ user.get_repo(repo_name)
28
+ return f"Error: Repository '{repo_name}' already exists."
29
+ except Exception:
30
+ pass # Repo doesn't exist, which is what we want
31
+
32
+ # Create the repository
33
+ repo = user.create_repo(repo_name, private=False)
34
+ main_branch = repo.get_branch("main")
35
+
36
+ # Prepare files for the commit
37
+ elements = []
38
+ for file_path, content in files.items():
39
+ elements.append(InputGitTreeElement(file_path, '100644', 'blob', content))
40
+
41
+ # Create the initial commit
42
+ base_tree = repo.get_git_tree(main_branch.commit.sha)
43
+ new_tree = repo.create_git_tree(elements, base_tree)
44
+ new_commit = repo.create_git_commit(commit_message, new_tree, [main_branch.commit])
45
+ main_branch.set_reference(f"refs/heads/main", new_commit.sha)
46
+
47
+ return f"Success: Repository created and code pushed. URL: {repo.html_url}"
48
+
49
+ except Exception as e:
50
+ return f"Error pushing to GitHub: {e}"
index.html ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>FallnAI Autonomous Software Developer</title>
7
+ <style>
8
+ body { font-family: sans-serif; margin: 20px; background-color: #f0f4f8; }
9
+ .container { max-width: 900px; margin: auto; padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
10
+ h1 { text-align: center; color: #333; }
11
+ .input-group { margin-bottom: 20px; }
12
+ textarea { width: 100%; height: 100px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; }
13
+ button { padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }
14
+ button:disabled { background-color: #aaa; cursor: not-allowed; }
15
+ .log-section, .code-section, .docs-section { margin-top: 20px; }
16
+ pre { background: #eee; padding: 15px; border-radius: 4px; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word; }
17
+ #progressLog, #finalCode, #finalUI, #finalDocs { border: 1px solid #ddd; min-height: 150px; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="container">
22
+ <h1>🤖 FallnAI Autonomous Software Developer v.01</h1>
23
+ <p>Enter your software specifications below. The agents will plan, code, and test the solution automatically using open-source models.</p>
24
+
25
+ <div class="input-group">
26
+ <textarea id="prompt" placeholder="e.g., A simple Python script that takes a list of numbers and returns the sum."></textarea>
27
+ <button id="devButton" onclick="startDevelopment()">Start Development</button>
28
+ </div>
29
+
30
+ <div class="log-section">
31
+ <h2>Development Log</h2>
32
+ <pre id="progressLog">Waiting for input...</pre>
33
+ </div>
34
+
35
+ <div class="code-section">
36
+ <h2>Final Code (`app.py`)</h2>
37
+ <pre id="finalCode">The final code will appear here.</pre>
38
+ </div>
39
+
40
+ <div class="code-section">
41
+ <h2>User Interface (`index.html`)</h2>
42
+ <pre id="finalUI">The user interface code will appear here.</pre>
43
+ </div>
44
+
45
+ <div class="docs-section">
46
+ <h2>Documentation (`README.md`)</h2>
47
+ <pre id="finalDocs">The README file will be generated here.</pre>
48
+ </div>
49
+ </div>
50
+
51
+ <script>
52
+ async function startDevelopment() {
53
+ const prompt = document.getElementById('prompt').value;
54
+ const progressLog = document.getElementById('progressLog');
55
+ const finalCode = document.getElementById('finalCode');
56
+ const finalUI = document.getElementById('finalUI');
57
+ const finalDocs = document.getElementById('finalDocs');
58
+ const devButton = document.getElementById('devButton');
59
+
60
+ if (!prompt) {
61
+ alert('Please enter a prompt.');
62
+ return;
63
+ }
64
+
65
+ devButton.disabled = true;
66
+ progressLog.textContent = 'Development started... This may take a few minutes as the model is generating and the sandbox is building.';
67
+ finalCode.textContent = 'Awaiting result...';
68
+ finalUI.textContent = 'Awaiting result...';
69
+ finalDocs.textContent = 'Awaiting result...';
70
+
71
+ try {
72
+ const response = await fetch('http://localhost:5000/develop', {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json' },
75
+ body: JSON.stringify({ prompt: prompt })
76
+ });
77
+
78
+ const data = await response.json();
79
+
80
+ if (response.ok) {
81
+ progressLog.textContent = data.log;
82
+ if (data.status === "success") {
83
+ finalCode.textContent = data.final_code;
84
+ finalUI.textContent = data.final_ui;
85
+ finalDocs.textContent = data.final_docs;
86
+ } else {
87
+ finalCode.textContent = "Could not generate working code. See log for details.";
88
+ finalUI.textContent = "";
89
+ finalDocs.textContent = "";
90
+ }
91
+ } else {
92
+ progressLog.textContent = `Error from server: ${data.error}`;
93
+ }
94
+ } catch (error) {
95
+ progressLog.textContent = `Failed to connect to the backend: ${error.message}`;
96
+ } finally {
97
+ devButton.disabled = false;
98
+ }
99
+ }
100
+ </script>
101
+ </body>
102
+ </html>
readme.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FallnAI Autonomous Software Developer
3
+ emoji: 🚀
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
8
+ ---
9
+
10
+ # FallnAI Autonomous Software Development Platform
11
+
12
+ This is a proof-of-concept autonomous software development platform. It leverages a crew of AI agents using open-source Large Language Models (LLMs) from Hugging Face to write, test, and correct its own code within a secure Docker sandbox. It automatically pushes the final, working code and documentation to a new GitHub repository.
13
+
14
+ ## How it works
15
+
16
+ 1. **Frontend**: A simple web UI in `index.html` allows users to submit a software request.
17
+ 2. **Backend**: The Flask application in `app.py` receives the request.
18
+ 3. **Agent Crew**: The backend uses the CrewAI framework to orchestrate a team of specialized agents (e.g., Planner, Coder, Tester) to execute a sequential development process: plan, code, test, and document.
19
+ 4. **LLMs & Transformers**: Each agent uses an LLM (accessed via the `transformers` library) as its core reasoning engine to perform its task.
20
+ 5. **Sandboxing**: The generated code is executed inside a temporary, isolated Docker container to prevent any malicious code from affecting the host system.
21
+ 6. **Correction Loop**: The LLM analyzes the output and errors from the sandbox and corrects the code until it passes.
22
+ 7. **Documentation & Deployment**: A dedicated agent writes a `README.md` file, and a DevOps agent pushes all final files to a new, unique GitHub repository.
23
+
24
+ Give it a try! You can describe any simple Python script, such as "a program that calculates the factorial of a number."
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ flask
2
+ transformers
3
+ torch
4
+ docker
5
+ crewai
6
+ crewai[mistral]
7
+ openai
8
+ PyGithub
9
+ crewai-tools
run.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Start the Docker daemon in the background
4
+ dockerd-entrypoint.sh &
5
+
6
+ # Wait for the Docker daemon to be ready
7
+ until docker info >/dev/null 2>&1; do
8
+ echo "Waiting for Docker daemon to start..."
9
+ sleep 1
10
+ done
11
+
12
+ echo "Docker daemon is running."
13
+
14
+ # Run the Flask application
15
+ # Hugging Face Spaces uses port 7860 by default
16
+ python app.py --port 7860 --host 0.0.0.0
task.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FallnAI Autonomous Software Developer
2
+ # tasks.py
3
+
4
+ from crewai import Task
5
+ from textwrap import dedent
6
+
7
+ class SoftwareDevelopmentTasks:
8
+ def __init__(self, user_prompt):
9
+ self.user_prompt = user_prompt
10
+
11
+ def plan_software(self, agent):
12
+ return Task(
13
+ description=dedent(f"""
14
+ Plan the development of a software application based on the following request:
15
+ "{self.user_prompt}"
16
+ Break down the project into clear, executable steps for the other agents.
17
+ The final output should be a detailed development plan.
18
+ """),
19
+ agent=agent
20
+ )
21
+
22
+ def write_code(self, agent):
23
+ return Task(
24
+ description=dedent("""
25
+ Write the core Python code for the application based on the provided plan.
26
+ Ensure the code is functional, well-commented, and includes necessary imports.
27
+ The final output must be a single, complete Python script.
28
+ """),
29
+ agent=agent
30
+ )
31
+
32
+ def write_ui(self, agent):
33
+ return Task(
34
+ description=dedent("""
35
+ Create a simple but functional HTML/CSS user interface to interact with the Python script.
36
+ The UI should be a single HTML file with embedded CSS.
37
+ The final output must be the complete HTML file content.
38
+ """),
39
+ agent=agent
40
+ )
41
+
42
+ def review_and_test(self, agent, code_content, ui_content):
43
+ return Task(
44
+ description=dedent(f"""
45
+ Review and test the generated Python code and UI.
46
+ Identify any bugs, errors, or security vulnerabilities.
47
+ If any issues are found, provide specific feedback for the Coder and UI agents to fix.
48
+ The final output should be a confirmation that the code is working or a list of required fixes.
49
+ Code to test: {code_content}
50
+ UI to test: {ui_content}
51
+ """),
52
+ agent=agent
53
+ )
54
+
55
+ def write_documentation(self, agent):
56
+ return Task(
57
+ description=dedent("""
58
+ Analyze the provided software code and the original user request.
59
+ Write a detailed README.md file that includes:
60
+ - A project title and a brief description.
61
+ - A "How to Use" section with clear instructions.
62
+ - An "Installation" section listing any required dependencies.
63
+
64
+ The final output should be the complete documentation content for a single file named README.md.
65
+ """),
66
+ agent=agent
67
+ )
68
+
69
+ def push_to_github(self, agent, repo_name):
70
+ return Task(
71
+ description=dedent(f"""
72
+ Take the final, verified code and documentation and push it to a new GitHub repository.
73
+ The repository name should be '{repo_name}'.
74
+ The final output must be the URL of the repository.
75
+ """),
76
+ agent=agent
77
+ )