CoolFace
Apppublic

FallnAI/Autonomous-Software-Developer

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py106 linesDownload Raw Back to root
1#FallnAI Autonomous Software Developer2#app.py3 4import os5import json6import subprocess7import tempfile8import time9import re10from flask import Flask, request, jsonify11from crewai import Crew, Process12from crewai.agent import Agent13from crewai.task import Task14from crewai.tools import Tool15from textwrap import dedent16from crewai_tools import SerperDevTool17 18# Import agent and task classes19from agents import planner_agent, coder_agent, tester_agent, ui_designer_agent, docs_agent, devops_agent20from tasks import SoftwareDevelopmentTasks21 22# Import the GitHub Manager23from github_manager import GitHubManager24 25app = Flask(__name__)26 27# --- Configuration ---28# GitHub Token from environment variable29# IMPORTANT: Never hardcode this token.30GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")31if not GITHUB_TOKEN:32    print("Warning: GITHUB_TOKEN environment variable not set. GitHub push will fail.")33 34# Initialize the GitHub tool35github_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'])42def develop_software():43    data = request.json44    user_prompt = data.get('prompt')45 46    if not user_prompt:47        return jsonify({"error": "No prompt provided"}), 40048 49    # Sanitize and create a unique repository name50    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 request56        tasks = SoftwareDevelopmentTasks(user_prompt)57        58        # Add the GitHub tool to the DevOps agent59        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 task69                tasks.push_to_github(devops_agent, repo_name=repo_name) # Pass repo_name70            ],71            process=Process.sequential,72            verbose=273        )74        75        # Kick off the development process76        result = crew.kickoff()77 78        # Extract the final outputs to be pushed79        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.output85            if "ui" in task_result.description.lower():86                final_ui = task_result.output87            if "documentation" in task_result.description.lower():88                final_docs = task_result.output89 90        # Final step is to get the push result and include it in the response91        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_docs99        })100 101    except Exception as e:102        return jsonify({"error": str(e)}), 500103 104if __name__ == '__main__':105    app.run(host='0.0.0.0', port=5000)106