subashpoudel commited on
Commit
eb40d68
·
1 Parent(s): 3a3fe92

Refined the files

Browse files
.gitignore CHANGED
@@ -8,4 +8,5 @@ my_agent/utils/check.py
8
  /pages
9
  streamlit_app.py
10
  data
11
- extracted_data.csv
 
 
8
  /pages
9
  streamlit_app.py
10
  data
11
+ extracted_data.csv
12
+ Research
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/state.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/state.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/state.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc differ
 
brainstroming_agent/utils/nodes.py CHANGED
@@ -2,7 +2,7 @@ import pandas as pd
2
  import ast
3
  from .state import State
4
  from .tools import retrieve_tool
5
- from langchain_core.messages import SystemMessage
6
  from utils.models_loader import llm , ST
7
  from utils.data_loader import load_influencer_data
8
  from groq import Groq
@@ -37,6 +37,8 @@ def caption_image(state: State) -> State:
37
  }
38
  ],
39
  model="meta-llama/llama-4-scout-17b-16e-instruct",
 
 
40
  )
41
  response=chat_completion.choices[0].message.content
42
  state.image_captions.append(response)
@@ -59,7 +61,7 @@ def retrieve(state: State) -> State:
59
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
60
 
61
  # Construct a list of dictionaries for this topic
62
- result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['agentic_story'])]
63
  retrievals.append(result)
64
  print('Retrieval process completed......')
65
  state.retrievals.append(retrievals)
@@ -73,14 +75,11 @@ def retrieve(state: State) -> State:
73
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
74
 
75
  # Construct a list of dictionaries for this topic
76
- result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['agentic_story'])]
77
  retrievals.append(result)
78
  print('Retrieval process completed for preferred_topics......')
79
  state.latest_preferred_topics=[]
80
  state.retrievals.append(retrievals)
81
-
82
- # print('The retrieval is:\n',state.retrievals )
83
- # return State(messages="Retrieved",topic=state.topic,retrievals=state.retrievals)
84
  return state
85
 
86
  def generate_story(state:State)-> State:
@@ -98,7 +97,8 @@ def generate_story(state:State)-> State:
98
 
99
  # and {state.image_captions[-1]}
100
 
101
- messages = [SystemMessage(content=template)]
 
102
 
103
  response = react_agent.invoke({'messages':messages})
104
  response = response['messages'][-1].content
 
2
  import ast
3
  from .state import State
4
  from .tools import retrieve_tool
5
+ from langchain_core.messages import SystemMessage ,HumanMessage
6
  from utils.models_loader import llm , ST
7
  from utils.data_loader import load_influencer_data
8
  from groq import Groq
 
37
  }
38
  ],
39
  model="meta-llama/llama-4-scout-17b-16e-instruct",
40
+ max_completion_tokens=50,
41
+ temperature = 1
42
  )
43
  response=chat_completion.choices[0].message.content
44
  state.image_captions.append(response)
 
61
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
62
 
63
  # Construct a list of dictionaries for this topic
64
+ result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['story'])]
65
  retrievals.append(result)
66
  print('Retrieval process completed......')
67
  state.retrievals.append(retrievals)
 
75
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
76
 
77
  # Construct a list of dictionaries for this topic
78
+ result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['story'])]
79
  retrievals.append(result)
80
  print('Retrieval process completed for preferred_topics......')
81
  state.latest_preferred_topics=[]
82
  state.retrievals.append(retrievals)
 
 
 
83
  return state
84
 
85
  def generate_story(state:State)-> State:
 
97
 
98
  # and {state.image_captions[-1]}
99
 
100
+ messages = [SystemMessage(content=template),
101
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n''')]
102
 
103
  response = react_agent.invoke({'messages':messages})
104
  response = response['messages'][-1].content
brainstroming_agent/utils/prompts.py CHANGED
@@ -11,43 +11,94 @@ Desired output:
11
  '''
12
 
13
  image_captioning_prompt = '''
14
- Analyze the image deeply and give the story of the image what it wants to say?
15
  '''
16
 
17
 
18
  def initial_story_prompt(state):
19
- return (
20
- f'''
21
- I want to create a detailed storyline for a video in any domain. You have to provide me that storyline what to include in the video.
22
- Now, i am giving you the topic of the video. But the need is to generate the story focusing on the response of the tool provided to you..
23
-
24
- \n\n Now let's start creating the storyline for my topic. The idea of the video is: \n\n{state.topic}\n\n and the business details are:\n {state.business_details}'''
25
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  def refined_story_prompt(state):
28
- return(
29
- f'''
30
- I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
31
- Now, i am giving you the topic of the video. But the need is to generate the story focusing on the response of the tool provided to you..
32
- Now, i am giving you the topic of the video.
33
- \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{state.topic}\n\n and the business details are:\n {state.business_details}
34
 
35
- **Final and must Reminder**: Please You have to strongly focus on these topics while creating the storyline: {state.preferred_topics[-1]} and {state.image_captions[-1]}'''
36
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def brainstroming_prompt(state):
39
- return(
40
- f'''
41
- I want to brainstorm ways to diversify or improve a storyline in exactly 4 sentences.
42
- The goal is to generate creative and actionable ideas that are not on the storyline on how the storyline can be expanded or modified for better engagement.
43
- For example: If the storyline is about creating a promotional video for a restaurant, the new suggestions might include:
44
- - I want to showcase the chef preparing a signature dish.
45
- - I want to add a sequence of customers sharing their experiences at the restaurant.
46
- - I want to highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
47
- - I want to include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
48
- - I want to feature a quick interview with the owner sharing the story behind the restaurant.
49
- Now, I will provide you with the storyline. The storyline is:\n{state.stories[-1]}'''
50
- )
 
 
 
 
 
 
 
 
 
51
 
52
  def final_story_prompt(final_state):
53
  return(
 
11
  '''
12
 
13
  image_captioning_prompt = '''
14
+ Analyze the image deeply and give the story of the image what it potraits in just 50 words.
15
  '''
16
 
17
 
18
  def initial_story_prompt(state):
19
+ return f"""
20
+ You are an expert video content strategist who generates the storyline of a video in exactly 300 words..
21
+
22
+ Your task is to generate a **detailed and creative storyline** for a promotional video on the **given topic**. The storyline should be structured, engaging, and highly relevant to the following **business details** and **inspiration from the image context if it contains some informations*.
23
+ Another important thing is that you have to give the response focusing on the response of the tool provided to you. The tool contains the video stories and contents created by the influencers.
24
+ Use that responses of tool for your reference. You can use your creativity but inside the boundary of tool's response.
25
+
26
+ ---
27
+
28
+ **Video Topic**:
29
+ {state.topic}
30
+
31
+ **Business Details**:
32
+ {state.business_details}
33
+
34
+
35
+ **Inspiration from Image Context** (must be strongly incorporated):
36
+ {state.image_captions[-1]}
37
+
38
+ ---
39
+
40
+ 🎯 **Important Instructions**:
41
+ - Creatively connect the image cues to make the storyline compelling. (If provided).
42
+ - Structure the storyline logically (e.g., beginning, middle, end), showing what scenes or visuals to include.
43
+ - Match the tone and depth to the business type (e.g., fun, luxurious, emotional, professional).
44
+
45
+ Now, generate the final storyline for the video topic..
46
+ """
47
 
48
  def refined_story_prompt(state):
49
+ return f"""
50
+ You are an expert video content strategist who generates the storyline of a video in exactly 300 words..
 
 
 
 
51
 
52
+ Your task is to generate a **detailed and creative storyline** for a promotional video on the **given topic**. The storyline should be structured, engaging, and highly relevant to the following **business details** , **preferred focus areas** and **inspiration from the image context(if any)**.
53
+ Another important thing is that you have to give the response only focusing on the response of the tool provided to you. The tool contains the video stories and contents created by the influencers.
54
+ Use that responses of tool for your reference. You can use your creativity but inside the boundary of tool's response.
55
+
56
+ ---
57
+
58
+ **Video Topic**:
59
+ {state.topic}
60
+
61
+ **Business Details**:
62
+ {state.business_details}
63
+
64
+ **Preferred Focus Areas** *(must be strongly incorporated)*:
65
+ {state.preferred_topics[-1]}
66
+
67
+ **Inspiration from Image Context** (must be strongly incorporated):
68
+ {state.image_captions[-1]}
69
+
70
+ ---
71
+
72
+ 🎯 **Important Instructions**:
73
+ - Creatively connect the preferred topics and image cues to make the storyline compelling.
74
+ - Structure the storyline logically (e.g., beginning, middle, end), showing what scenes or visuals to include.
75
+ - Match the tone and depth to the business type (e.g., fun, luxurious, emotional, professional).
76
+
77
+ Now, generate the final storyline for the video topic..
78
+ """
79
 
80
  def brainstroming_prompt(state):
81
+ return f'''
82
+ You are a creative consultant tasked with enhancing a storyline.
83
+
84
+ Suggest **4 unique and creative enhancements** to the following storyline. Each suggestion must:
85
+ - Be just 1 sentence long”
86
+ - Add something **new or different** (not rephrasing what’s already in the story)
87
+ - Improve the storyline’s **engagement, emotional depth, or audience appeal**
88
+
89
+ Output format: a numbered list from 1 to 4.
90
+
91
+ Here’s an example for a restaurant promo storyline:
92
+ 1. Showcase the chef preparing a signature dish.
93
+ 2. Add a sequence of customers sharing their experiences at the restaurant.
94
+ 3. Highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
95
+ 4. Include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
96
+
97
+ Now, here is the current storyline you need to enhance:
98
+
99
+ "{state.stories[-1]}"
100
+ '''
101
+
102
 
103
  def final_story_prompt(final_state):
104
  return(
brainstroming_agent/utils/state.py CHANGED
@@ -25,6 +25,6 @@ class BrainstromTopicFormatter(BaseModel):
25
  topic4:str=Field(description="Fourth brainstorming topic of the story")
26
 
27
  class QueryFormatter(BaseModel):
28
- messages: str = Field(description="The message that user passes to the agent")
29
- business_details: dict = Field (description="The business details that user passes to the agent")
30
 
 
25
  topic4:str=Field(description="Fourth brainstorming topic of the story")
26
 
27
  class QueryFormatter(BaseModel):
28
+ video_topic: str = Field(description="The video topic that user passes to the agent")
29
+ # business_details: dict = Field (description="The business details that user passes to the agent")
30
 
brainstroming_agent/utils/tools.py CHANGED
@@ -7,7 +7,6 @@ import numpy as np
7
  from langchain_core.tools import tool
8
  from utils.data_loader import load_influencer_data
9
  from utils.models_loader import ST , llm
10
- from sklearn.metrics.pairwise import cosine_similarity
11
  import numpy as np
12
  from langchain_core.messages import SystemMessage
13
  import re
@@ -18,10 +17,10 @@ from .state import QueryFormatter
18
 
19
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
20
  @tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
21
- def retrieve_tool(messages, business_details):
22
  '''
23
  Always invoke this tool.
24
- Retrieve influencer's data by semantic search of **user messages** and the **business details**.
25
  '''
26
  # === Load CSV ===
27
  csv_path = 'extracted_data.csv'
@@ -39,8 +38,8 @@ def retrieve_tool(messages, business_details):
39
  # === Load SentenceTransformer model ===
40
 
41
  # === Encode the query and search ===
42
- query_embedding = ST.encode(str(messages)+str(business_details)).reshape(1, -1).astype('float32')
43
- top_k=10
44
  distances, indices = index.search(query_embedding, top_k)
45
 
46
 
 
7
  from langchain_core.tools import tool
8
  from utils.data_loader import load_influencer_data
9
  from utils.models_loader import ST , llm
 
10
  import numpy as np
11
  from langchain_core.messages import SystemMessage
12
  import re
 
17
 
18
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
19
  @tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
20
+ def retrieve_tool(video_topic):
21
  '''
22
  Always invoke this tool.
23
+ Retrieve influencer's data by semantic search of **video topic**.
24
  '''
25
  # === Load CSV ===
26
  csv_path = 'extracted_data.csv'
 
38
  # === Load SentenceTransformer model ===
39
 
40
  # === Encode the query and search ===
41
+ query_embedding = ST.encode(str(video_topic)).reshape(1, -1).astype('float32')
42
+ top_k=7
43
  distances, indices = index.search(query_embedding, top_k)
44
 
45
 
business_interaction_agent/utils/__pycache__/prompts.cpython-312.pyc CHANGED
Binary files a/business_interaction_agent/utils/__pycache__/prompts.cpython-312.pyc and b/business_interaction_agent/utils/__pycache__/prompts.cpython-312.pyc differ
 
business_interaction_agent/utils/prompts.py CHANGED
@@ -38,7 +38,7 @@ Rules:
38
  - Do NOT invent or assume any information beyond what is explicitly provided in the retrievals and business details.
39
 
40
  Keep your response:
41
- - Context-aware
42
  - Grounded only in the given data
43
  - Helpful, concise, and user-friendly
44
  '''.strip()
 
38
  - Do NOT invent or assume any information beyond what is explicitly provided in the retrievals and business details.
39
 
40
  Keep your response:
41
+ - Context-aware, direct and short as possible
42
  - Grounded only in the given data
43
  - Helpful, concise, and user-friendly
44
  '''.strip()
main.py CHANGED
@@ -9,7 +9,8 @@ from business_interaction_agent.agent import BusinessInteractionChatbot
9
  from context_analysis_agent.utils.utils import save_to_db
10
  import ast
11
  from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
12
-
 
13
 
14
  import json
15
 
@@ -18,11 +19,12 @@ import json
18
  app = FastAPI()
19
  context_analysis_graph = IntroductionChatbot()
20
  business_interaction_graph = BusinessInteractionChatbot()
 
21
  brainstrom_graph = brainstroming_graph()
22
 
23
  stored_data={}
24
- stored_data['business_details']={"business_type": "restaurant", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali foods", "Challenges_faced": "finding new customers, attracting large customers"}
25
-
26
  class UserMessage(BaseModel):
27
  message: str
28
  @app.post("/context-analysis")
@@ -49,32 +51,44 @@ def business_interaction(interaction: str):
49
  stored_data['business_details']=business_details
50
  return {'response': response}
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  @app.post("/brainstrom")
54
  def brainstroming_endpoint(
55
- query: List[str], # sent as JSON body
56
- preferred_topics: Optional[list] = [],
57
- images: Optional[List[UploadFile]] = [], # ✅ Optional UploadFile list
58
- thread_id: Optional[str] = "default-session",
59
  ):
60
- # Convert uploaded images to base64
61
- image_base64_list = [encode_image_to_base64(img) for img in images]
62
-
63
- # Invoke LangGraph
64
  result = brainstrom_graph.invoke({
65
- 'topic': query,
66
- 'images': image_base64_list,
67
- 'latest_preferred_topics':preferred_topics,
68
  'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
69
-
70
  },
71
- config={"configurable": {"thread_id": thread_id}})
72
- stored_data['brainstroming_response']=result
73
- # brainstorm_store[thread_id] = result
 
 
 
74
 
75
- return {
76
- 'response': result,
77
- }
78
 
79
  @app.post("/generate-final-story")
80
  def generate_final_story_endpoint():
 
9
  from context_analysis_agent.utils.utils import save_to_db
10
  import ast
11
  from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
12
+ from fastapi import Body, Query
13
+ from ideation_agent.agent import ideation_graph
14
 
15
  import json
16
 
 
19
  app = FastAPI()
20
  context_analysis_graph = IntroductionChatbot()
21
  business_interaction_graph = BusinessInteractionChatbot()
22
+ idea_graph = ideation_graph()
23
  brainstrom_graph = brainstroming_graph()
24
 
25
  stored_data={}
26
+ 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"}
27
+ # stored_data['business_details']={}
28
  class UserMessage(BaseModel):
29
  message: str
30
  @app.post("/context-analysis")
 
51
  stored_data['business_details']=business_details
52
  return {'response': response}
53
 
54
+ class IdeationRequest(BaseModel):
55
+ topic : List[str]
56
+ business_details: dict
57
+
58
+ @app.post("/ideation")
59
+ def ideation_endpoint(request:IdeationRequest):
60
+ result = idea_graph.invoke({
61
+ 'topic': request.topic,
62
+ 'business_details': stored_data['business_details']
63
+ })
64
+ return {'response':result}
65
+
66
+
67
+
68
+ class BrainstormRequest(BaseModel):
69
+ query: List[str]
70
+ preferred_topics: Optional[List] = []
71
+ image_base64_list: Optional[List] = []
72
+ thread_id: Optional[str]="default-session"
73
 
74
  @app.post("/brainstrom")
75
  def brainstroming_endpoint(
76
+ request: BrainstormRequest, # 🔥 Full JSON body here
77
+ # thread_id: Optional[str] = Query("default-session"), # Separate query param
 
 
78
  ):
 
 
 
 
79
  result = brainstrom_graph.invoke({
80
+ 'topic': request.query,
81
+ 'images': request.image_base64_list,
82
+ 'latest_preferred_topics': request.preferred_topics,
83
  'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
 
84
  },
85
+ config={"configurable": {"thread_id": request.thread_id}})
86
+
87
+ stored_data['brainstroming_response'] = result
88
+
89
+ return {'response': result}
90
+
91
 
 
 
 
92
 
93
  @app.post("/generate-final-story")
94
  def generate_final_story_endpoint():
utils/__pycache__/models_loader.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/models_loader.cpython-312.pyc and b/utils/__pycache__/models_loader.cpython-312.pyc differ
 
utils/models_loader.py CHANGED
@@ -14,19 +14,19 @@ login(os.environ['HUGGINGFACEHUB_ACCESS_TOKEN'])
14
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
15
 
16
 
17
- llm = ChatGroq(
18
- model="llama-3.3-70b-versatile",
 
 
 
 
 
 
 
19
  temperature=0.3,
20
  max_tokens=500,
21
-
22
  )
23
 
24
- # llm = ChatOpenAI(
25
- # model="gpt-4o-mini",
26
- # temperature=0,
27
- # max_tokens=500,
28
- # )
29
-
30
 
31
  class HFEmbeddingAPI:
32
  def __init__(self, api_url, token):
@@ -52,3 +52,42 @@ ST = HFEmbeddingAPI(
52
  api_url="https://router.huggingface.co/hf-inference/models/mixedbread-ai/mxbai-embed-large-v1/pipeline/feature-extraction",
53
  token=os.environ.get('HUGGINGFACEHUB_ACCESS_TOKEN')
54
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
15
 
16
 
17
+ # llm = ChatGroq(
18
+ # model="llama3-8b-8192",
19
+ # temperature=0.3,
20
+ # max_tokens=500,
21
+
22
+ # )
23
+
24
+ llm = ChatOpenAI(
25
+ model="gpt-4o-mini",
26
  temperature=0.3,
27
  max_tokens=500,
 
28
  )
29
 
 
 
 
 
 
 
30
 
31
  class HFEmbeddingAPI:
32
  def __init__(self, api_url, token):
 
52
  api_url="https://router.huggingface.co/hf-inference/models/mixedbread-ai/mxbai-embed-large-v1/pipeline/feature-extraction",
53
  token=os.environ.get('HUGGINGFACEHUB_ACCESS_TOKEN')
54
  )
55
+
56
+ # Initiated the models for ideation
57
+
58
+ ideator_llm = ChatGroq(
59
+ model="llama3-8b-8192",
60
+ temperature=0.3,
61
+ max_tokens=500,
62
+
63
+ )
64
+
65
+ critic_llm = ChatGroq(
66
+ model="gemma2-9b-it",
67
+ temperature=0.3,
68
+ max_tokens=500,
69
+
70
+ )
71
+
72
+ # improver_llm = ChatOpenAI(
73
+ # model="gpt-4o-mini",
74
+ # temperature=0.3,
75
+ # max_tokens=500,
76
+ # )
77
+
78
+ improver_llm = ChatGroq(
79
+ model="meta-llama/llama-4-scout-17b-16e-instruct",
80
+ temperature=0.3,
81
+ max_tokens=500,
82
+
83
+ )
84
+
85
+
86
+ validator_llm = ChatGroq(
87
+ model="gemma2-9b-it",
88
+ temperature=0.3,
89
+ max_tokens=500,
90
+
91
+ )
92
+
93
+