Spaces:
Build error
Build error
| #FallnAI Autonomous Software Developer | |
| #app.py | |
| import os | |
| import json | |
| import subprocess | |
| import tempfile | |
| import time | |
| import re | |
| from flask import Flask, request, jsonify | |
| from crewai import Crew, Process | |
| from crewai.agent import Agent | |
| from crewai.task import Task | |
| from crewai.tools import Tool | |
| from textwrap import dedent | |
| from crewai_tools import SerperDevTool | |
| # Import agent and task classes | |
| from agents import planner_agent, coder_agent, tester_agent, ui_designer_agent, docs_agent, devops_agent | |
| from tasks import SoftwareDevelopmentTasks | |
| # Import the GitHub Manager | |
| from github_manager import GitHubManager | |
| app = Flask(__name__) | |
| # --- Configuration --- | |
| # GitHub Token from environment variable | |
| # IMPORTANT: Never hardcode this token. | |
| GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") | |
| if not GITHUB_TOKEN: | |
| print("Warning: GITHUB_TOKEN environment variable not set. GitHub push will fail.") | |
| # Initialize the GitHub tool | |
| github_tool = Tool( | |
| name="GitHub_Manager", | |
| func=GitHubManager(GITHUB_TOKEN).create_and_push_repo, | |
| description="A tool to create and push files to a new GitHub repository." | |
| ) | |
| def develop_software(): | |
| data = request.json | |
| user_prompt = data.get('prompt') | |
| if not user_prompt: | |
| return jsonify({"error": "No prompt provided"}), 400 | |
| # Sanitize and create a unique repository name | |
| sanitized_prompt = re.sub(r'[^a-zA-Z0-9-]', '', user_prompt[:30]).lower() | |
| timestamp = int(time.time()) | |
| repo_name = f"auto-dev-{sanitized_prompt}-{timestamp}" | |
| try: | |
| # Create a new crew for this request | |
| tasks = SoftwareDevelopmentTasks(user_prompt) | |
| # Add the GitHub tool to the DevOps agent | |
| devops_agent.tools.append(github_tool) | |
| crew = Crew( | |
| agents=[planner_agent, coder_agent, tester_agent, ui_designer_agent, docs_agent, devops_agent], | |
| tasks=[ | |
| tasks.plan_software(planner_agent), | |
| tasks.write_code(coder_agent), | |
| tasks.write_ui(ui_designer_agent), | |
| tasks.review_and_test(tester_agent), | |
| tasks.write_documentation(docs_agent), # New documentation task | |
| tasks.push_to_github(devops_agent, repo_name=repo_name) # Pass repo_name | |
| ], | |
| process=Process.sequential, | |
| verbose=2 | |
| ) | |
| # Kick off the development process | |
| result = crew.kickoff() | |
| # Extract the final outputs to be pushed | |
| final_code = "" | |
| final_ui = "" | |
| final_docs = "" | |
| for task_result in crew.tasks_outputs: | |
| if "code" in task_result.description.lower(): | |
| final_code = task_result.output | |
| if "ui" in task_result.description.lower(): | |
| final_ui = task_result.output | |
| if "documentation" in task_result.description.lower(): | |
| final_docs = task_result.output | |
| # Final step is to get the push result and include it in the response | |
| final_result = crew.kickoff() | |
| return jsonify({ | |
| "status": "success", | |
| "log": final_result, | |
| "final_code": final_code, | |
| "final_ui": final_ui, | |
| "final_docs": final_docs | |
| }) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=5000) | |