Spaces:
Sleeping
Sleeping
File size: 3,881 Bytes
a9f99c3 be3a5c4 93a5bf9 be3a5c4 a9f99c3 93a5bf9 24b940c 93a5bf9 eb40d68 946d35b a9f99c3 946d35b be3a5c4 93a5bf9 eb40d68 93a5bf9 be3a5c4 946d35b eb40d68 b55b8d4 93a5bf9 db141d0 24b940c 946d35b b55b8d4 85a68fb 508df21 93a5bf9 db141d0 92115be eb40d68 85a68fb b55b8d4 da1776b eb40d68 a9f99c3 93a5bf9 eb40d68 d604e49 a9f99c3 eb40d68 85a68fb 946d35b 708437f 946d35b 708437f 946d35b 708437f 06e8ef4 708437f 946d35b |
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 |
from fastapi import FastAPI , UploadFile , File , Form
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from brainstroming_agent.agent import brainstroming_graph
import pandas as pd
from typing import Optional , List
from context_analysis_agent.agent import IntroductionChatbot
from business_interaction_agent.agent import BusinessInteractionChatbot
from context_analysis_agent.utils.utils import save_to_db
import ast
from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
from fastapi import Body, Query
from ideation_agent.agent import ideation_graph
import json
# Store brainstorming results per thread_id
app = FastAPI()
context_analysis_graph = IntroductionChatbot()
business_interaction_graph = BusinessInteractionChatbot()
idea_graph = ideation_graph()
brainstrom_graph = brainstroming_graph()
stored_data={}
stored_data['business_details']={"business_type": "cosmetic", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali skin care products", "Challenges_faced": "finding new customers, attracting large customers"}
# stored_data['business_details']={}
class UserMessage(BaseModel):
message: str
@app.post("/context-analysis")
def context_analysis(msg: UserMessage):
response = context_analysis_graph.chat(msg.message)
if context_analysis_graph.is_complete(response):
details = context_analysis_graph.extract_details()
if type(details) != dict:
details = details.model_dump()
print('Business_details:',details)
if isinstance(details, str):
details= ast.literal_eval(details)
print('Details Type:',type(details))
save_to_db(details)
stored_data['business_details'] = details
return {"response": response, "business_details": details, "complete": True}
return {"response": response, "complete": False}
@app.post("/business-interaction")
def business_interaction(interaction: str):
response,business_details = business_interaction_graph.chat(interaction , stored_data['business_details'])
stored_data['business_details']=business_details
return {'response': response}
class IdeationRequest(BaseModel):
topic : List[str]
business_details: dict
@app.post("/ideation")
def ideation_endpoint(request:IdeationRequest):
result = idea_graph.invoke({
'topic': request.topic,
'business_details': stored_data['business_details']
})
return {'response':result}
class BrainstormRequest(BaseModel):
query: List[str]
preferred_topics: Optional[List] = []
image_base64_list: Optional[List] = []
thread_id: Optional[str]="default-session"
@app.post("/brainstrom")
def brainstroming_endpoint(
request: BrainstormRequest, # 🔥 Full JSON body here
# thread_id: Optional[str] = Query("default-session"), # Separate query param
):
result = brainstrom_graph.invoke({
'topic': request.query,
'images': request.image_base64_list,
'latest_preferred_topics': request.preferred_topics,
'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
},
config={"configurable": {"thread_id": request.thread_id}})
stored_data['brainstroming_response'] = result
return {'response': result}
@app.post("/generate-final-story")
def generate_final_story_endpoint():
final_story = generate_final_story(stored_data["brainstroming_response"])
stored_data['final_story']=final_story
return {
'response': final_story
}
@app.post("/generate-image")
def generate_image_endpoint():
image = generate_image(str(stored_data['final_story']))
stored_data['generated_image']=image
return {
'response':image
}
|