Spaces:
Sleeping
Sleeping
Download app.py from RozzaCreat/UDP_advisor: direct link, hf CLI and curl.
- Browser
- Download file 22.8 kB
-
https://huggingface.co/spaces/RozzaCreat/UDP_advisor/resolve/main/app.py
- Command line
-
hf download hf://spaces/RozzaCreat/UDP_advisor/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RozzaCreat/UDP_advisor/resolve/main/app.py
22.8 kB
| from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool | |
| import datetime | |
| import requests | |
| import pytz | |
| import yaml | |
| import math | |
| from tools.final_answer import FinalAnswerTool | |
| from Gradio_UI import GradioUI | |
| def udp_advisor(development_phase: str, team_size: int, project_complexity: str) -> str: | |
| """Provides UDP (Unified Development Platform) recommendations based on development phase, team size, and project complexity. | |
| Args: | |
| development_phase: Current phase of development (planning, development, testing, deployment, monitoring) | |
| team_size: Number of team members | |
| project_complexity: Project complexity level (low, medium, high) | |
| Returns: | |
| UDP recommendations as formatted text | |
| """ | |
| if team_size <= 0 or team_size > 1000: | |
| return "Error: Please provide a valid team size (1-1000)." | |
| # Normalize development phase | |
| development_phase = development_phase.lower().strip() | |
| valid_phases = ["planning", "development", "testing", "deployment", "monitoring"] | |
| if development_phase not in valid_phases: | |
| return "Error: Development phase must be one of: planning, development, testing, deployment, monitoring." | |
| # Normalize complexity | |
| project_complexity = project_complexity.lower().strip() | |
| valid_complexity = ["low", "medium", "high"] | |
| if project_complexity not in valid_complexity: | |
| return "Error: Project complexity must be 'low', 'medium', or 'high'." | |
| # Database of UDP tools by development phase and complexity | |
| udp_tools = { | |
| "planning": { | |
| "low": [ | |
| {"name": "Trello", "category": "Project Management", "complexity": "Low", "min_team_size": 1, "description": "Simple kanban board for task tracking"}, | |
| {"name": "GitHub Projects", "category": "Project Management", "complexity": "Low", "min_team_size": 1, "description": "Basic project management integrated with GitHub"} | |
| ], | |
| "medium": [ | |
| {"name": "Jira", "category": "Project Management", "complexity": "Medium", "min_team_size": 5, "description": "Comprehensive agile project management tool"}, | |
| {"name": "Azure DevOps Boards", "category": "Project Management", "complexity": "Medium", "min_team_size": 5, "description": "Project tracking with Azure integration"} | |
| ], | |
| "high": [ | |
| {"name": "Monday.com", "category": "Project Management", "complexity": "High", "min_team_size": 10, "description": "Customizable workflow platform for complex projects"}, | |
| {"name": "Rally", "category": "Project Management", "complexity": "High", "min_team_size": 20, "description": "Enterprise-scale agile management and portfolio planning"} | |
| ] | |
| }, | |
| "development": { | |
| "low": [ | |
| {"name": "GitHub", "category": "Version Control", "complexity": "Low", "min_team_size": 1, "description": "Popular code hosting platform with basic CI/CD"}, | |
| {"name": "VS Code", "category": "IDE", "complexity": "Low", "min_team_size": 1, "description": "Lightweight, extensible code editor"} | |
| ], | |
| "medium": [ | |
| {"name": "GitLab", "category": "DevOps Platform", "complexity": "Medium", "min_team_size": 5, "description": "Integrated DevOps platform with built-in CI/CD"}, | |
| {"name": "JetBrains IDEs", "category": "IDE", "complexity": "Medium", "min_team_size": 1, "description": "Language-specific professional IDEs"} | |
| ], | |
| "high": [ | |
| {"name": "Bitbucket + Bamboo", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 10, "description": "Atlassian's integrated code and CI/CD solution"}, | |
| {"name": "GitHub Enterprise", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 20, "description": "Self-hosted, compliant GitHub with advanced security"} | |
| ] | |
| }, | |
| "testing": { | |
| "low": [ | |
| {"name": "Jest", "category": "Testing Framework", "complexity": "Low", "min_team_size": 1, "description": "JavaScript testing framework with minimal configuration"}, | |
| {"name": "GitHub Actions", "category": "CI/CD", "complexity": "Low", "min_team_size": 1, "description": "Simple workflow automation integrated with GitHub"} | |
| ], | |
| "medium": [ | |
| {"name": "Jenkins", "category": "CI/CD", "complexity": "Medium", "min_team_size": 3, "description": "Flexible automation server for building, testing, and deployment"}, | |
| {"name": "Selenium", "category": "Testing", "complexity": "Medium", "min_team_size": 2, "description": "Browser automation for web application testing"} | |
| ], | |
| "high": [ | |
| {"name": "Azure DevOps Pipelines", "category": "CI/CD", "complexity": "High", "min_team_size": 5, "description": "Enterprise-grade pipelines with extensive integration"}, | |
| {"name": "SonarQube", "category": "Code Quality", "complexity": "High", "min_team_size": 5, "description": "Advanced code quality and security platform"} | |
| ] | |
| }, | |
| "deployment": { | |
| "low": [ | |
| {"name": "Netlify", "category": "Hosting", "complexity": "Low", "min_team_size": 1, "description": "Simple deployment platform for frontend applications"}, | |
| {"name": "Heroku", "category": "PaaS", "complexity": "Low", "min_team_size": 1, "description": "Platform-as-a-Service with simplified deployment"} | |
| ], | |
| "medium": [ | |
| {"name": "Docker", "category": "Containerization", "complexity": "Medium", "min_team_size": 2, "description": "Container platform for application packaging"}, | |
| {"name": "AWS Elastic Beanstalk", "category": "PaaS", "complexity": "Medium", "min_team_size": 3, "description": "Easy-to-use service for deploying applications"} | |
| ], | |
| "high": [ | |
| {"name": "Kubernetes", "category": "Container Orchestration", "complexity": "High", "min_team_size": 5, "description": "Production-grade container orchestration"}, | |
| {"name": "Terraform", "category": "IaC", "complexity": "High", "min_team_size": 3, "description": "Infrastructure as Code for multi-cloud deployment"} | |
| ] | |
| }, | |
| "monitoring": { | |
| "low": [ | |
| {"name": "Uptime Robot", "category": "Monitoring", "complexity": "Low", "min_team_size": 1, "description": "Simple uptime monitoring for websites"}, | |
| {"name": "Sentry", "category": "Error Tracking", "complexity": "Low", "min_team_size": 1, "description": "Application error monitoring"} | |
| ], | |
| "medium": [ | |
| {"name": "Grafana", "category": "Observability", "complexity": "Medium", "min_team_size": 2, "description": "Metrics visualization and dashboards"}, | |
| {"name": "New Relic", "category": "APM", "complexity": "Medium", "min_team_size": 3, "description": "Application performance monitoring"} | |
| ], | |
| "high": [ | |
| {"name": "Prometheus", "category": "Monitoring", "complexity": "High", "min_team_size": 3, "description": "Advanced metrics collection and alerting system"}, | |
| {"name": "Datadog", "category": "Observability", "complexity": "High", "min_team_size": 5, "description": "Full-stack observability platform"} | |
| ] | |
| } | |
| } | |
| # Team size categorization | |
| team_category = "small" if team_size < 10 else "medium" if team_size < 50 else "large" | |
| # Find suitable tools based on team size and complexity | |
| suitable_tools = [] | |
| tools_for_phase = udp_tools[development_phase][project_complexity] | |
| # Filter tools by team size | |
| for tool in tools_for_phase: | |
| if tool["min_team_size"] <= team_size: | |
| suitable_tools.append(tool) | |
| # Format response | |
| response = f"## UDP Tool Recommendations\n\n" | |
| response += f"**Development Phase:** {development_phase.capitalize()}\n" | |
| response += f"**Team Size:** {team_size} ({team_category} team)\n" | |
| response += f"**Project Complexity:** {project_complexity.capitalize()}\n\n" | |
| if suitable_tools: | |
| response += "### Recommended Tools\n\n" | |
| for tool in suitable_tools: | |
| response += f"**{tool['name']}**\n" | |
| response += f"- Category: {tool['category']}\n" | |
| response += f"- Complexity: {tool['complexity']}\n" | |
| response += f"- Min Team Size: {tool['min_team_size']}\n" | |
| response += f"- Description: {tool['description']}\n\n" | |
| else: | |
| response += "Unfortunately, we cannot provide specific tool recommendations for your team size and complexity requirements. Consider reviewing tools for a different complexity level or adjusting your team size.\n\n" | |
| # Additional phase-specific advice | |
| if development_phase == "planning": | |
| response += "### Planning Phase Tips\n" | |
| response += "- Document your requirements clearly\n" | |
| response += "- Set up communication channels\n" | |
| response += "- Define team roles and responsibilities\n" | |
| elif development_phase == "development": | |
| response += "### Development Phase Tips\n" | |
| response += "- Implement branch protection rules\n" | |
| response += "- Use consistent code formatting\n" | |
| response += "- Schedule regular code reviews\n" | |
| elif development_phase == "testing": | |
| response += "### Testing Phase Tips\n" | |
| response += "- Automate unit and integration tests\n" | |
| response += "- Establish QA processes\n" | |
| response += "- Document test cases and expected outcomes\n" | |
| elif development_phase == "deployment": | |
| response += "### Deployment Phase Tips\n" | |
| response += "- Use environment-specific configurations\n" | |
| response += "- Implement rollback strategies\n" | |
| response += "- Document deployment procedures\n" | |
| elif development_phase == "monitoring": | |
| response += "### Monitoring Phase Tips\n" | |
| response += "- Set up alerts for critical metrics\n" | |
| response += "- Establish incident response processes\n" | |
| response += "- Regularly review logs and performance data\n" | |
| response += "\n### Important Information\n" | |
| response += "- These are general recommendations based on the information provided.\n" | |
| response += "- Before adopting tools, assess your team's specific needs and skills.\n" | |
| response += "- Consider integration capabilities with your existing toolchain.\n" | |
| response += "- Training requirements should be factored into tool adoption decisions.\n" | |
| return response | |
| def get_current_time_in_timezone(timezone: str) -> str: | |
| """A tool that fetches the current local time in a specified timezone. | |
| Args: | |
| timezone: A string representing a valid timezone (e.g., 'America/New_York'). | |
| """ | |
| try: | |
| # Create timezone object | |
| tz = pytz.timezone(timezone) | |
| # Get current time in that timezone | |
| local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S") | |
| return f"The current local time in {timezone} is: {local_time}" | |
| except Exception as e: | |
| return f"Error fetching time for timezone '{timezone}': {str(e)}" | |
| def search_udp_tool_reviews(tool_name: str) -> str: | |
| """Searches for information and reviews about a specific UDP tool. | |
| Args: | |
| tool_name: The name of the tool to search for (e.g., 'Kubernetes', 'Jira') | |
| """ | |
| try: | |
| # This is a placeholder - in a real application, you would implement | |
| # actual search functionality here using DuckDuckGoSearchTool | |
| common_tools = { | |
| "github": "GitHub is widely regarded as one of the most popular version control and collaboration platforms. " + | |
| "Recent reviews praise its improved Actions feature for CI/CD pipelines, but note that complex " + | |
| "permissions management can be challenging for larger teams.", | |
| "gitlab": "GitLab receives positive reviews for its all-in-one DevOps platform approach. Users appreciate " + | |
| "the integrated CI/CD capabilities and built-in security scanning. Some reviews mention that the " + | |
| "interface can be overwhelming for beginners.", | |
| "kubernetes": "Kubernetes continues to be the leading container orchestration platform. Reviews highlight " + | |
| "its robust ecosystem and flexibility, though many note a steep learning curve. Enterprise " + | |
| "users praise its scalability while smaller teams sometimes find it overly complex.", | |
| "jenkins": "Jenkins remains a popular CI/CD tool with a large plugin ecosystem. Recent reviews mention " + | |
| "that while it's highly customizable, maintaining Jenkins installations can become complex over time. " + | |
| "Many organizations are considering cloud-native alternatives.", | |
| "terraform": "Terraform is widely praised for its infrastructure-as-code capabilities across multiple cloud providers. " + | |
| "Recent reviews highlight improved state management features, though some users note challenges with " + | |
| "complex dependency management in large infrastructures.", | |
| "jira": "Jira continues to be a leading project management tool for agile teams. Reviews appreciate its " + | |
| "customization options but sometimes criticize its complexity and learning curve. Recent updates " + | |
| "to the interface have received mixed feedback.", | |
| "docker": "Docker remains essential for containerization. Recent reviews praise its compatibility improvements " + | |
| "and simplified developer experience. Some enterprise users mention challenges with orchestration " + | |
| "at scale, often leading them to Kubernetes.", | |
| "azure devops": "Azure DevOps receives positive reviews for its integrated toolchain and strong integration " + | |
| "with Microsoft products. Users appreciate its CI/CD capabilities and built-in test management. " + | |
| "Some reviews mention that non-Microsoft workloads might require additional configuration." | |
| } | |
| # Normalize the tool name for lookup | |
| normalized_tool = tool_name.lower() | |
| if normalized_tool in common_tools: | |
| return f"### Recent Reviews for {tool_name}\n\n{common_tools[normalized_tool]}\n\n" + \ | |
| "This information is based on aggregated recent reviews and industry analysis." | |
| else: | |
| return f"No specific review information available for '{tool_name}'. " + \ | |
| "This tool may be less commonly used or recently introduced to the market. " + \ | |
| "Consider searching for specific features you need rather than tool names." | |
| except Exception as e: | |
| return f"Error searching for information about '{tool_name}': {str(e)}" | |
| # Setup required tools | |
| final_answer = FinalAnswerTool() | |
| search_tool = DuckDuckGoSearchTool() | |
| # Setup language model | |
| model = HfApiModel( | |
| max_tokens=2096, | |
| temperature=0.5, | |
| model_id='Qwen/Qwen2.5-Coder-32B-Instruct' | |
| ) | |
| # Try to load prompt templates from file | |
| try: | |
| with open("prompts.yaml", 'r') as stream: | |
| prompt_templates = yaml.safe_load(stream) | |
| except: | |
| # If loading fails, create default templates | |
| prompt_templates = {} | |
| # Add our templates directly to ensure proper structure | |
| prompt_templates["react-system"] = """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects. | |
| You have access to the following tools: | |
| {tools_string} | |
| You should help the user determine which UDP tools are best for their project based on: | |
| 1. The current development phase they are in (planning, development, testing, deployment, monitoring) | |
| 2. The size of their development team | |
| 3. The complexity of their project (low, medium, high) | |
| You can also provide information about specific tools, search for reviews, and check the current time in different timezones to help with global team coordination. | |
| To use a tool, output an action in this format: | |
| ```py | |
| action = tool_name(arg1=value1, arg2=value2, ...) | |
| ``` | |
| Always use Python syntax for calling tools. After using a tool, analyze the result to determine what to do next. Use final_answer to return your final answer. | |
| """ | |
| prompt_templates["react-human"] = "{input_string}" | |
| prompt_templates["react-assistant"] = "{agent_response}" | |
| prompt_templates["final_answer"] = { | |
| "pre_messages": "I'll provide you with UDP tool recommendations based on your project details.", | |
| "template": "Final Answer: {answer}", | |
| "post_messages": "Is there anything else you'd like to know about these UDP tools or development practices?" | |
| } | |
| # Create the agent with all tools | |
| agent = CodeAgent( | |
| model=model, | |
| tools=[final_answer, udp_advisor, get_current_time_in_timezone, search_udp_tool_reviews, search_tool], | |
| max_steps=6, | |
| verbosity_level=1, | |
| prompt_templates=prompt_templates | |
| ) | |
| # Create a custom Gradio UI | |
| class UDPAdvisorUI(GradioUI): | |
| def launch(self, **kwargs): | |
| import gradio as gr | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# UDP Advisor for Software Development") | |
| gr.Markdown("Get personalized UDP tool recommendations and development information") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_type = gr.Radio( | |
| ["Tool Recommendations", "Tool Reviews", "Timezone Check", "Free-form Question"], | |
| label="What would you like help with?", | |
| value="Tool Recommendations" | |
| ) | |
| # Tool recommendation inputs | |
| with gr.Group(visible=True) as recommendation_group: | |
| phase_input = gr.Radio( | |
| ["Planning", "Development", "Testing", "Deployment", "Monitoring"], | |
| label="Development Phase" | |
| ) | |
| team_input = gr.Number(label="Team Size", minimum=1, value=5) | |
| complexity_input = gr.Radio( | |
| ["Low", "Medium", "High"], | |
| label="Project Complexity" | |
| ) | |
| # Tool review input | |
| with gr.Group(visible=False) as review_group: | |
| tool_name_input = gr.Textbox(label="Tool Name", placeholder="Enter a tool name (e.g., Kubernetes, GitLab)") | |
| # Timezone input | |
| with gr.Group(visible=False) as timezone_group: | |
| timezone_input = gr.Textbox(label="Timezone", placeholder="Enter a timezone (e.g., America/New_York, Europe/London)") | |
| # Free-form question input | |
| with gr.Group(visible=False) as freeform_group: | |
| question_input = gr.Textbox(label="Your Question", placeholder="Ask anything about development tools or practices") | |
| submit_btn = gr.Button("Submit", variant="primary") | |
| with gr.Row(): | |
| with gr.Column(): | |
| output = gr.Markdown(label="Response") | |
| # Logic to show/hide input groups based on selection | |
| def update_visibility(choice): | |
| return { | |
| recommendation_group: choice == "Tool Recommendations", | |
| review_group: choice == "Tool Reviews", | |
| timezone_group: choice == "Timezone Check", | |
| freeform_group: choice == "Free-form Question" | |
| } | |
| input_type.change( | |
| update_visibility, | |
| inputs=[input_type], | |
| outputs=[recommendation_group, review_group, timezone_group, freeform_group] | |
| ) | |
| # Process input based on type | |
| def process_input(input_type, phase, team_size, complexity, tool_name, timezone, question): | |
| if input_type == "Tool Recommendations": | |
| if not phase: | |
| return "Please select a development phase." | |
| if not team_size or team_size < 1: | |
| return "Please provide a valid team size (at least 1)." | |
| if not complexity: | |
| return "Please select a project complexity level." | |
| query = f"I need UDP tool recommendations for a project in the {phase.lower()} phase with a team of {int(team_size)} people and {complexity.lower()} complexity." | |
| elif input_type == "Tool Reviews": | |
| if not tool_name or tool_name.strip() == "": | |
| return "Please enter a tool name to search for reviews." | |
| query = f"What are the reviews and opinions about {tool_name.strip()}?" | |
| elif input_type == "Timezone Check": | |
| if not timezone or timezone.strip() == "": | |
| return "Please enter a timezone to check." | |
| query = f"What is the current time in {timezone.strip()}?" | |
| else: # Free-form question | |
| if not question or question.strip() == "": | |
| return "Please enter your question." | |
| query = question | |
| # Process the query using the agent | |
| try: | |
| response = agent.run(query) | |
| return response | |
| except Exception as e: | |
| return f"Error processing request: {str(e)}" | |
| submit_btn.click( | |
| process_input, | |
| inputs=[input_type, phase_input, team_input, complexity_input, tool_name_input, timezone_input, question_input], | |
| outputs=output | |
| ) | |
| demo.launch(**kwargs) | |
| # Launch the interface | |
| UDPAdvisorUI(agent).launch() |