Spaces:
Sleeping
Sleeping
File size: 2,089 Bytes
4067b64 |
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 |
from fastapi import APIRouter, Response
from src.models.analysis_models import InputModel
from src.workflows.analysis_workflow import MLAnalysisWorkflow, MLImplementationPlanner
from datetime import datetime
from phi.storage.workflow.sqlite import SqlWorkflowStorage
from phi.utils.pprint import pprint_run_response
from phi.utils.log import logger
from typing import Iterator
router = APIRouter()
@router.get("/")
async def read_root():
return Response("Ml-Analysis workflow from user problem is Up!")
@router.post("/analyze-problem")
async def analyze_problem(data: InputModel):
analysis_workflow = MLAnalysisWorkflow(
session_id=f"ml-analysis-{datetime.now().strftime('%Y%m%d_%H%M%S')}",
storage=SqlWorkflowStorage(
table_name="ml_analysis_workflows",
db_file="storage/workflows.db"
)
)
analysis_response: Iterator[RunResponse] = analysis_workflow.run(data.problem_statement)
pprint_run_response(analysis_response, markdown=True)
requirements_result = analysis_workflow.requirements_analyst.run_response.content if analysis_workflow.requirements_analyst.run_response else None
research_result = analysis_workflow.technical_researcher.run_response.content if analysis_workflow.technical_researcher.run_response else None
if requirements_result:
logger.info("===Planning Phase===")
planning_workflow = MLImplementationPlanner(
session_id=f"ml-planning-{datetime.now().strftime('%Y%m%d_%H%M%S')}",
storage=SqlWorkflowStorage(
table_name="ml_planning_workflows",
db_file="storage/workflows.db"
)
)
# run and print planning workflow
planning_response_stream: Iterator[RunResponse] = planning_workflow.run(requirements_result, research_result)
pprint_run_response(planning_response_stream, markdown=True)
return {"Response": planning_workflow.writer.run_response.content}
else:
return {"Error": "Requirements analysis did not complete successfully."}
|