Spaces:
Sleeping
Sleeping
File size: 1,377 Bytes
583f6dd |
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 |
from fastapi import APIRouter
from api.stored_data import stored_data
from pydantic import BaseModel
from typing import Optional
from src.genai.brainstroming_agent.agent import brainstroming_graph
router=APIRouter()
brainstrom_graph = brainstroming_graph()
class BrainstormRequest(BaseModel):
preferred_topics: Optional[list] = []
image_base64_list: Optional[list] = []
thread_id: Optional[str]="default-session"
@router.post("/brainstorm")
def brainstroming_endpoint(
request: BrainstormRequest, # 🔥 Full JSON body here
):
idea = (
[stored_data['refined_ideation']]
if stored_data.get('refined_ideation')
else [str(stored_data['final_ideation'])]
if stored_data.get('final_ideation')
else ['''I don't have any idea right now. Create your own **very creative** and **out of the box** video idea and generate the story for now.'''])
result = brainstrom_graph.invoke({
'idea': idea,
'images': request.image_base64_list,
'latest_preferred_topics': request.preferred_topics,
'business_details': stored_data['business_details']
},
config={"configurable": {"thread_id": request.thread_id}})
stored_data['brainstroming_response'] = result
return {'response':{
"story": result['stories'][-1],
"brainstorming_topics": result['brainstroming_topics'][-1]
}} |