File size: 7,635 Bytes
22d0fa7
 
8135ce6
78fb7b6
8135ce6
 
 
 
 
 
 
22d0fa7
e639f71
1177031
e7b8eec
22d0fa7
 
b9832c7
 
 
 
 
 
 
 
 
 
a0037e0
 
34c249a
b9832c7
 
 
34c249a
b9832c7
 
 
a06df16
b9832c7
 
 
 
 
 
 
 
22d0fa7
 
 
 
 
 
34c249a
8a9455d
22d0fa7
 
 
 
e639f71
1177031
e7b8eec
22d0fa7
 
b9832c7
 
 
 
 
 
 
 
 
 
 
 
22d0fa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e639f71
1177031
e7b8eec
22d0fa7
 
b9832c7
 
 
a06df16
b9832c7
 
 
a06df16
b9832c7
 
 
 
 
 
 
 
22d0fa7
78fb7b6
22d0fa7
 
 
 
 
 
e639f71
1177031
e7b8eec
22d0fa7
 
b9832c7
 
 
 
 
 
 
22d0fa7
 
 
 
 
 
 
e639f71
1177031
e7b8eec
22d0fa7
 
b9832c7
 
 
 
 
 
 
 
 
 
 
 
22d0fa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7b8eec
 
 
 
 
22d0fa7
78fb7b6
 
77ee07f
 
 
 
 
78fb7b6
 
8135ce6
 
 
 
 
cad5f45
 
8135ce6
78fb7b6
22d0fa7
 
 
 
 
 
 
 
 
 
 
a0037e0
22d0fa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e639f71
e7b8eec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import gradio as gr
import json
from smolagents import CodeAgent, tool, Tool, FinalAnswerTool, HfApiModel, load_tool

final_answer = FinalAnswerTool()
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
)

class ProjectScopingTool(Tool):
    name = "project_scoping_tool"
    description = """
    Handles project scoping by collecting key details such as type, domain, budget, and timeline.
    """

    inputs = {
        "project_type": {
            "type": "string",
            "description": "The type of project (e.g., 'web', 'blockchain', 'ai').",
        },
        "domain": {
            "type": "string",
            "description": "The industry or field related to the project (e.g., 'finance', 'healthcare').",
        },
        "budget_min"
: {
            "type": "number",
            "description": "The minimum budget allocated for the project.",
        },
        "budget_max": {
            "type": "number",
            "description": "The maximum budget allocated for the project.",
        },
        "timeline_months": {
            "type": "number",
            "description": "The expected duration of the project in months.",
        },
    }

    output_type = "json"

    def forward(self, project_type: str, domain: str, budget_min: float, budget_max: float, timeline_months: int):

        """
        Collects and structures project details from user input.
        """
        self.project_details = {
            "type": project_type,
            "domain": domain,

            "budget_range": {"min": budget_min, "max": budget_max},
            "timeline": {"months": timeline_months}
        }
        return json.dumps(self.project_details, indent=2)

class TechnicalArchitectureTool(Tool):
    name = "technical_architecture_tool"
    description = """
    Determines the appropriate technical architecture based on the project type.
    """

    inputs = {
        "project_type": {
            "type": "string",
            "description": "The type of project (e.g., 'web', 'blockchain', 'ai').",
        }
    }

    output_type = "json"

    def forward(self, project_type: str):

        architectures = {
            "web": {
                "frontend": ["React", "Next.js", "Tailwind"],
                "backend": ["FastAPI", "Django", "Express"],
                "database": ["PostgreSQL", "MongoDB"]
            },
            "blockchain": {
                "blockchain_type": "EVM-compatible",
                "smart_contract_language": "Solidity",
                "consensus_mechanism": "Proof of Stake"
            },
            "ai": {
                "model_type": "Transformer",
                "inference_strategy": "Cloud-based",
                "data_processing": "Distributed"
            }
        }
        return json.dumps(architectures.get(project_type, "Invalid project type"), indent=2)

class CostEstimationTool(Tool):
    name = "cost_estimation_tool"
    description = """
    Estimates the cost based on the architecture complexity and timeline.
    """

    inputs = {
        "architecture_size": {
            "type": "number",
            "description": "The estimated complexity of the architecture on a scale from 1 to 10.",
        },
        "timeline_months": {
            "type": "number",
            "description": "The project duration in months.",
        }
    }

    output_type = "json"

    def forward(self, architecture_size: int, timeline_months: int):

        base_costs = {
            "development": 5000 * (architecture_size * 0.5),
            "infrastructure": 500 * (architecture_size * 0.3),
            "maintenance": 1000 * (architecture_size * 0.2)
        }
        total_cost = sum(base_costs.values())
        return json.dumps({"total_estimated_cost": total_cost, "breakdown": base_costs}, indent=2)

class DeploymentTool(Tool):
    name = "deployment_tool"
    description = """
    Suggests a deployment strategy based on best practices.
    """

    inputs = {}

    output_type = "json"

    def forward(self):

        return json.dumps({
            "container_strategy": "Docker + Kubernetes",
            "cloud_provider": "AWS",
            "services": ["ECS", "Lambda", "S3", "RDS"],
            "ci_cd_pipeline": "GitHub Actions"
        }, indent=2)

class MeetingPreparationTool(Tool):
    name = "meeting_preparation_tool"
    description = """
    Provides meeting agendas depending on the project stage.
    """

    inputs = {
        "project_stage": {
            "type": "string",
            "description": "The current stage of the project (e.g., 'initial_discovery', 'architecture_review').",
        }
    }

    output_type = "json"

    def forward(self, project_stage: str):

        agendas = {
            "initial_discovery": [
                "Project Vision Validation",
                "Technical Feasibility Discussion",
                "Initial Scope Definition"
            ],
            "architecture_review": [
                "Technical Architecture Walkthrough",
                "Technology Stack Validation",
                "Performance Considerations"
            ]
        }
        return json.dumps(agendas.get(project_stage, "No agenda found for this stage"), indent=2)

# Instantiate tools
scoping_tool = ProjectScopingTool()
tech_arch_tool = TechnicalArchitectureTool()
cost_tool = CostEstimationTool()
deploy_tool = DeploymentTool()
meeting_tool = MeetingPreparationTool()

# Define the agent
tools = [
    scoping_tool,
    tech_arch_tool,
    cost_tool,
    deploy_tool,
    meeting_tool
]

agent = CodeAgent(
    model=model,
    tools=[final_answer, tools], # add your tools here (don't remove final_answer)
    max_steps=6,
    verbosity_level=1,
    name="webchainai",
    description="Sets up first project mockups"
)

# Define Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# 🏗️ Project Scoping & Cost Estimation Tool")

    with gr.Row():
        project_type = gr.Dropdown(["web", "blockchain", "ai"], label="Select Project Type")
        domain = gr.Textbox(label="Enter Project Domain")

    with gr.Row():
        budget_min = gr.Number(label="Min Budget ($)")
        budget_max = gr.Number(label="Max Budget ($)")
        timeline_months = gr.Number(label="Timeline (Months)")

    project_output = gr.Textbox(label="Project Details", interactive=False)
    arch_output = gr.Textbox(label="Technical Architecture", interactive=False)
    cost_output = gr.Textbox(label="Estimated Cost", interactive=False)
    deploy_output = gr.Textbox(label="Deployment Strategy", interactive=False)
    meeting_output = gr.Textbox(label="Meeting Agenda", interactive=False)

    def process_inputs(p_type, dom, min_b, max_b, months):
        project_details = scoping_tool.collect_project_details(p_type, dom, min_b, max_b, months)
        architecture = tech_arch_tool.generate_architecture(p_type)
        estimated_cost = cost_tool.estimate_project_cost(len(architecture), months)
        deployment_strategy = deploy_tool.generate_deployment_strategy()
        meeting_agenda = meeting_tool.generate_meeting_agenda("initial_discovery")
        return project_details, architecture, estimated_cost, deployment_strategy, meeting_agenda

    process_button = gr.Button("Generate Estimates")
    process_button.click(process_inputs, inputs=[project_type, domain, budget_min, budget_max, timeline_months], 
                         outputs=[project_output, arch_output, cost_output, deploy_output, meeting_output])

# Launch the Gradio App
demo(agent).launch()