RozzaCreat commited on
Commit
f1cb32a
·
verified ·
1 Parent(s): dca5e74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +262 -54
app.py CHANGED
@@ -1,62 +1,270 @@
1
- from smolagents.agent import CodeAgent
2
- from smolagents.tools.core import tool
3
- import gradio as gr
4
 
5
- # 🔧 Объявляем функцию как инструмент
6
  @tool
7
- def udp_learning_advisor(experience_level: int, learning_style: str, age: int) -> str:
 
 
 
 
 
 
 
 
 
8
  """
9
- Personalized learning recommendations for Unified Development Platform based on experience, learning style, and age.
10
- """
11
- # 🧠 Определение подхода к обучению по стилю
12
- if learning_style.lower() == 'intensive':
13
- plan = "Focus on hands-on projects and advanced features of the platform."
14
- elif learning_style.lower() == 'balanced':
15
- plan = "Combine structured tutorials with practical exercises."
16
- else: # slow or cautious
17
- plan = "Start with guided walkthroughs and foundational concepts."
18
-
19
- # 🧠 Советы по уровню опыта
20
- if experience_level < 30:
21
- experience_note = "Begin with basic modules like UI components and workflow automation."
22
- elif experience_level < 70:
23
- experience_note = "Explore integration, APIs, and process orchestration."
24
- else:
25
- experience_note = "Dive into customization, DevOps integration, and performance tuning."
26
-
27
- # 🧠 Подстройка по возрасту
28
- if age < 25:
29
- age_note = "Incorporate gamified challenges to keep engagement high."
30
- elif age < 50:
31
- age_note = "Use real-world business cases to reinforce concepts."
32
- else:
33
- age_note = "Include step-by-step explanations and documentation-heavy resources."
34
-
35
- return f"{plan} {experience_note} {age_note}"
36
-
37
-
38
- # 🧠 Агент
39
- agent = CodeAgent(
40
- name="UDP Learning Advisor",
41
- description="Advises users on learning strategies for the Unified Development Platform based on experience level, learning style, and age.",
42
- tools=[udp_learning_advisor]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
 
45
- # 🎛️ Интерфейс
46
- def advisor_ui(experience_level, learning_style, age):
47
- return udp_learning_advisor(experience_level, learning_style, age)
48
-
49
- demo = gr.Interface(
50
- fn=advisor_ui,
51
- inputs=[
52
- gr.Slider(0, 100, label="Experience Level"),
53
- gr.Dropdown(["intensive", "balanced", "slow"], label="Learning Style"),
54
- gr.Number(label="Your Age")
55
- ],
56
- outputs="text",
57
- title="UDP Learning Advisor",
58
- description="Get a personalized learning strategy for mastering the Unified Development Platform."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  )
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  if __name__ == "__main__":
62
- demo.launch()
 
 
1
+ from smolagents import CodeAgent, HfApiModel, tool
2
+ import yaml
 
3
 
 
4
  @tool
5
+ def udp_advisor(development_phase: str, team_size: int, project_complexity: str) -> str:
6
+ """Provides UDP (Unified Development Platform) recommendations based on development phase, team size, and project complexity.
7
+
8
+ Args:
9
+ development_phase: Current phase of development (planning, development, testing, deployment, monitoring)
10
+ team_size: Number of team members
11
+ project_complexity: Project complexity level (low, medium, high)
12
+
13
+ Returns:
14
+ UDP recommendations as formatted text
15
  """
16
+ if team_size <= 0 or team_size > 1000:
17
+ return "Error: Please provide a valid team size (1-1000)."
18
+
19
+ # Normalize development phase
20
+ development_phase = development_phase.lower().strip()
21
+ valid_phases = ["planning", "development", "testing", "deployment", "monitoring"]
22
+
23
+ if development_phase not in valid_phases:
24
+ return "Error: Development phase must be one of: planning, development, testing, deployment, monitoring."
25
+
26
+ # Normalize complexity
27
+ project_complexity = project_complexity.lower().strip()
28
+ valid_complexity = ["low", "medium", "high"]
29
+
30
+ if project_complexity not in valid_complexity:
31
+ return "Error: Project complexity must be 'low', 'medium', or 'high'."
32
+
33
+ # Database of UDP tools by development phase and complexity
34
+ udp_tools = {
35
+ "planning": {
36
+ "low": [
37
+ {"name": "Trello", "category": "Project Management", "complexity": "Low", "description": "Simple kanban board for task tracking"},
38
+ {"name": "GitHub Projects", "category": "Project Management", "complexity": "Low", "description": "Basic project management integrated with GitHub"}
39
+ ],
40
+ "medium": [
41
+ {"name": "Jira", "category": "Project Management", "complexity": "Medium", "description": "Comprehensive agile project management tool"},
42
+ {"name": "Azure DevOps Boards", "category": "Project Management", "complexity": "Medium", "description": "Project tracking with Azure integration"}
43
+ ],
44
+ "high": [
45
+ {"name": "Monday.com", "category": "Project Management", "complexity": "High", "description": "Customizable workflow platform for complex projects"},
46
+ {"name": "Rally", "category": "Project Management", "complexity": "High", "description": "Enterprise-scale agile management and portfolio planning"}
47
+ ]
48
+ },
49
+ "development": {
50
+ "low": [
51
+ {"name": "GitHub", "category": "Version Control", "complexity": "Low", "description": "Popular code hosting platform with basic CI/CD"},
52
+ {"name": "VS Code", "category": "IDE", "complexity": "Low", "description": "Lightweight, extensible code editor"}
53
+ ],
54
+ "medium": [
55
+ {"name": "GitLab", "category": "DevOps Platform", "complexity": "Medium", "description": "Integrated DevOps platform with built-in CI/CD"},
56
+ {"name": "JetBrains IDEs", "category": "IDE", "complexity": "Medium", "description": "Language-specific professional IDEs"}
57
+ ],
58
+ "high": [
59
+ {"name": "Bitbucket + Bamboo", "category": "Enterprise DevOps", "complexity": "High", "description": "Atlassian's integrated code and CI/CD solution"},
60
+ {"name": "GitHub Enterprise", "category": "Enterprise DevOps", "complexity": "High", "description": "Self-hosted, compliant GitHub with advanced security"}
61
+ ]
62
+ },
63
+ "testing": {
64
+ "low": [
65
+ {"name": "Jest", "category": "Testing Framework", "complexity": "Low", "description": "JavaScript testing framework with minimal configuration"},
66
+ {"name": "GitHub Actions", "category": "CI/CD", "complexity": "Low", "description": "Simple workflow automation integrated with GitHub"}
67
+ ],
68
+ "medium": [
69
+ {"name": "Jenkins", "category": "CI/CD", "complexity": "Medium", "description": "Flexible automation server for building, testing, and deployment"},
70
+ {"name": "Selenium", "category": "Testing", "complexity": "Medium", "description": "Browser automation for web application testing"}
71
+ ],
72
+ "high": [
73
+ {"name": "Azure DevOps Pipelines", "category": "CI/CD", "complexity": "High", "description": "Enterprise-grade pipelines with extensive integration"},
74
+ {"name": "SonarQube", "category": "Code Quality", "complexity": "High", "description": "Advanced code quality and security platform"}
75
+ ]
76
+ },
77
+ "deployment": {
78
+ "low": [
79
+ {"name": "Netlify", "category": "Hosting", "complexity": "Low", "description": "Simple deployment platform for frontend applications"},
80
+ {"name": "Heroku", "category": "PaaS", "complexity": "Low", "description": "Platform-as-a-Service with simplified deployment"}
81
+ ],
82
+ "medium": [
83
+ {"name": "Docker", "category": "Containerization", "complexity": "Medium", "description": "Container platform for application packaging"},
84
+ {"name": "AWS Elastic Beanstalk", "category": "PaaS", "complexity": "Medium", "description": "Easy-to-use service for deploying applications"}
85
+ ],
86
+ "high": [
87
+ {"name": "Kubernetes", "category": "Container Orchestration", "complexity": "High", "description": "Production-grade container orchestration"},
88
+ {"name": "Terraform", "category": "IaC", "complexity": "High", "description": "Infrastructure as Code for multi-cloud deployment"}
89
+ ]
90
+ },
91
+ "monitoring": {
92
+ "low": [
93
+ {"name": "Uptime Robot", "category": "Monitoring", "complexity": "Low", "description": "Simple uptime monitoring for websites"},
94
+ {"name": "Sentry", "category": "Error Tracking", "complexity": "Low", "description": "Application error monitoring"}
95
+ ],
96
+ "medium": [
97
+ {"name": "Grafana", "category": "Observability", "complexity": "Medium", "description": "Metrics visualization and dashboards"},
98
+ {"name": "New Relic", "category": "APM", "complexity": "Medium", "description": "Application performance monitoring"}
99
+ ],
100
+ "high": [
101
+ {"name": "Prometheus", "category": "Monitoring", "complexity": "High", "description": "Advanced metrics collection and alerting system"},
102
+ {"name": "Datadog", "category": "Observability", "complexity": "High", "description": "Full-stack observability platform"}
103
+ ]
104
+ }
105
+ }
106
+
107
+ # Team size categorization
108
+ team_category = "small" if team_size < 10 else "medium" if team_size < 50 else "large"
109
+
110
+ # Get tool recommendations
111
+ tools_for_phase = udp_tools[development_phase][project_complexity]
112
+
113
+ # Format response
114
+ response = f"## UDP Tool Recommendations\n\n"
115
+ response += f"**Development Phase:** {development_phase.capitalize()}\n"
116
+ response += f"**Team Size:** {team_size} ({team_category} team)\n"
117
+ response += f"**Project Complexity:** {project_complexity.capitalize()}\n\n"
118
+
119
+ response += "### Recommended Tools\n\n"
120
+
121
+ for tool in tools_for_phase:
122
+ response += f"**{tool['name']}**\n"
123
+ response += f"- Category: {tool['category']}\n"
124
+ response += f"- Complexity: {tool['complexity']}\n"
125
+ response += f"- Description: {tool['description']}\n\n"
126
+
127
+ # Additional phase-specific advice
128
+ if development_phase == "planning":
129
+ response += "### Planning Phase Tips\n"
130
+ response += "- Document your requirements clearly\n"
131
+ response += "- Set up communication channels\n"
132
+ response += "- Define team roles and responsibilities\n"
133
+ elif development_phase == "development":
134
+ response += "### Development Phase Tips\n"
135
+ response += "- Implement branch protection rules\n"
136
+ response += "- Use consistent code formatting\n"
137
+ response += "- Schedule regular code reviews\n"
138
+ elif development_phase == "testing":
139
+ response += "### Testing Phase Tips\n"
140
+ response += "- Automate unit and integration tests\n"
141
+ response += "- Establish QA processes\n"
142
+ response += "- Document test cases and expected outcomes\n"
143
+ elif development_phase == "deployment":
144
+ response += "### Deployment Phase Tips\n"
145
+ response += "- Use environment-specific configurations\n"
146
+ response += "- Implement rollback strategies\n"
147
+ response += "- Document deployment procedures\n"
148
+ elif development_phase == "monitoring":
149
+ response += "### Monitoring Phase Tips\n"
150
+ response += "- Set up alerts for critical metrics\n"
151
+ response += "- Establish incident response processes\n"
152
+ response += "- Regularly review logs and performance data\n"
153
+
154
+ response += "\n### UDP Learning Resources\n"
155
+ response += "- [Unified Development Platforms Study Guide](https://ds-an.github.io/udp-study-guide/)\n"
156
+ response += "- [DevOps Roadmap](https://roadmap.sh/devops)\n"
157
+ response += "- [GitHub Learning Lab](https://lab.github.com/)\n"
158
+
159
+ return response
160
+
161
+ # Import final answer tool
162
+ from tools.final_answer import FinalAnswerTool
163
+ final_answer = FinalAnswerTool()
164
+
165
+ # Configure the language model
166
+ model = HfApiModel(
167
+ max_tokens=1024,
168
+ temperature=0.7,
169
+ model_id='Qwen/Qwen2.5-7B-Instruct' # Using a smaller model for educational purposes
170
  )
171
 
172
+ # Define prompt templates
173
+ udp_prompt_templates = {
174
+ "react-system": """You are a UDP (Unified Development Platform) advisor who helps users choose appropriate tools for their software development projects.
175
+ You have access to the following tools:
176
+
177
+ {tools_string}
178
+
179
+ You should help the user determine which UDP tools are best for their project based on:
180
+ 1. The current development phase they are in
181
+ 2. The size of their development team
182
+ 3. The complexity of their project
183
+
184
+ Use the udp_advisor tool to analyze these factors and provide tool recommendations.
185
+
186
+ To use a tool, output an action in this format:
187
+ ```py
188
+ action = tool_name(arg1=value1, arg2=value2, ...)
189
+ ```
190
+
191
+ 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.
192
+ """,
193
+ "react-human": "{input_string}",
194
+ "react-assistant": "{agent_response}",
195
+ }
196
+
197
+ # Load prompt templates from file or use our templates
198
+ try:
199
+ with open("prompts.yaml", 'r') as stream:
200
+ prompt_templates = yaml.safe_load(stream)
201
+ prompt_templates.update(udp_prompt_templates)
202
+ except:
203
+ prompt_templates = udp_prompt_templates
204
+
205
+ # Create the agent
206
+ agent = CodeAgent(
207
+ model=model,
208
+ tools=[final_answer, udp_advisor],
209
+ max_steps=3,
210
+ verbosity_level=1,
211
+ prompt_templates=prompt_templates
212
  )
213
 
214
+ # Create a custom Gradio UI
215
+ def create_udp_advisor_ui():
216
+ import gradio as gr
217
+
218
+ with gr.Blocks(theme=gr.themes.Base()) as demo:
219
+ gr.Markdown("# UDP Advisor for Software Development Projects")
220
+ gr.Markdown("Get tool recommendations for your Unified Development Platform")
221
+
222
+ with gr.Row():
223
+ with gr.Column():
224
+ phase_input = gr.Radio(
225
+ ["Planning", "Development", "Testing", "Deployment", "Monitoring"],
226
+ label="Development Phase"
227
+ )
228
+ team_input = gr.Slider(
229
+ minimum=1,
230
+ maximum=100,
231
+ step=1,
232
+ value=5,
233
+ label="Team Size"
234
+ )
235
+ complexity_input = gr.Radio(
236
+ ["Low", "Medium", "High"],
237
+ label="Project Complexity"
238
+ )
239
+ submit_btn = gr.Button("Get Recommendations", variant="primary")
240
+
241
+ with gr.Row():
242
+ with gr.Column():
243
+ recommendation_output = gr.Markdown(label="UDP Recommendations")
244
+
245
+ def get_recommendations(phase, team_size, complexity):
246
+ if not phase:
247
+ return "Please select a development phase."
248
+ if not team_size or team_size < 1:
249
+ return "Please provide a valid team size (at least 1)."
250
+ if not complexity:
251
+ return "Please select a project complexity level."
252
+
253
+ try:
254
+ recommendations = udp_advisor(phase.lower(), int(team_size), complexity.lower())
255
+ return recommendations
256
+ except Exception as e:
257
+ return f"Error generating recommendations: {str(e)}"
258
+
259
+ submit_btn.click(
260
+ get_recommendations,
261
+ inputs=[phase_input, team_input, complexity_input],
262
+ outputs=recommendation_output
263
+ )
264
+
265
+ return demo
266
+
267
+ # Launch the application
268
  if __name__ == "__main__":
269
+ demo = create_udp_advisor_ui()
270
+ demo.launch()