Spaces:
Sleeping
Sleeping
| 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" | |
| 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] | |
| }} |