Spaces:
Sleeping
Sleeping
Commit
Β·
fa8520f
1
Parent(s):
3c1150c
Next commit
Browse files- __pycache__/main.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc +0 -0
- brainstroming_agent/utils/nodes.py +1 -1
- brainstroming_agent/utils/prompts.py +1 -1
- context_analysis_agent/utils/__pycache__/prompts.cpython-312.pyc +0 -0
- context_analysis_agent/utils/prompts.py +1 -0
- main.py +11 -25
- orchestration_agent/agent.py +10 -4
- orchestration_agent/utils/prompts.py +29 -13
- orchestration_agent/utils/state.py +1 -0
- orchestration_agent/utils/utils.py +38 -0
__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/nodes.py
CHANGED
|
@@ -26,7 +26,7 @@ def caption_image(state: State) -> State:
|
|
| 26 |
{
|
| 27 |
"role": "user",
|
| 28 |
"content": [
|
| 29 |
-
{"type": "text", "text": image_captioning_prompt(state
|
| 30 |
{
|
| 31 |
"type": "image_url",
|
| 32 |
"image_url": {
|
|
|
|
| 26 |
{
|
| 27 |
"role": "user",
|
| 28 |
"content": [
|
| 29 |
+
{"type": "text", "text": image_captioning_prompt(state)},
|
| 30 |
{
|
| 31 |
"type": "image_url",
|
| 32 |
"image_url": {
|
brainstroming_agent/utils/prompts.py
CHANGED
|
@@ -34,7 +34,7 @@ Only use the visual cues from the image to inspire your caption, but ensure it f
|
|
| 34 |
|
| 35 |
Here are the provided **business details** and **video idea** for you. Strongly focus on these two contexts too.
|
| 36 |
1. Business details: {state.business_details}
|
| 37 |
-
2. Video idea: {state.
|
| 38 |
|
| 39 |
Now generate:
|
| 40 |
- A rich 100-word image caption, and
|
|
|
|
| 34 |
|
| 35 |
Here are the provided **business details** and **video idea** for you. Strongly focus on these two contexts too.
|
| 36 |
1. Business details: {state.business_details}
|
| 37 |
+
2. Video idea: {state.idea}
|
| 38 |
|
| 39 |
Now generate:
|
| 40 |
- A rich 100-word image caption, and
|
context_analysis_agent/utils/__pycache__/prompts.cpython-312.pyc
CHANGED
|
Binary files a/context_analysis_agent/utils/__pycache__/prompts.cpython-312.pyc and b/context_analysis_agent/utils/__pycache__/prompts.cpython-312.pyc differ
|
|
|
context_analysis_agent/utils/prompts.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
introduction_prompt = '''
|
| 2 |
You are a business assistant who collects only valid and relevant data.
|
| 3 |
Your job is to gather details from business owners in a friendly and conversational manner to understand their business better. Ask in very easy and short way.
|
|
|
|
| 4 |
|
| 5 |
We need these details:
|
| 6 |
1. Business Type (e.g., e-commerce, SaaS, consulting),
|
|
|
|
| 1 |
introduction_prompt = '''
|
| 2 |
You are a business assistant who collects only valid and relevant data.
|
| 3 |
Your job is to gather details from business owners in a friendly and conversational manner to understand their business better. Ask in very easy and short way.
|
| 4 |
+
No matter what the user asks, you have to say to user that we have to collect these details first and only you can move forward.
|
| 5 |
|
| 6 |
We need these details:
|
| 7 |
1. Business Type (e.g., e-commerce, SaaS, consulting),
|
main.py
CHANGED
|
@@ -9,6 +9,7 @@ from business_interaction_agent.agent import BusinessInteractionChatbot
|
|
| 9 |
from context_analysis_agent.utils.utils import save_to_db
|
| 10 |
import ast
|
| 11 |
from orchestration_agent.agent import orchestration_chat
|
|
|
|
| 12 |
from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
|
| 13 |
from idea_to_budget_agent.agent import budget_calculator
|
| 14 |
from ideation_agent.agent import ideation_graph
|
|
@@ -25,39 +26,24 @@ business_interaction_graph = BusinessInteractionChatbot()
|
|
| 25 |
idea_graph = ideation_graph()
|
| 26 |
brainstrom_graph = brainstroming_graph()
|
| 27 |
human_refine_graph = human_refined_idea()
|
|
|
|
| 28 |
|
| 29 |
-
# stored_data={}
|
| 30 |
-
# # stored_data['business_details']={"business_type": "fitness and gym", "platform": "instagram, tiktok", "target_audience": "every software needed clients", "business_goals": "to expand in every cities of nepal", "offerings": "nepali cloths and products", "Challenges_faced": "finding new customers, attracting large customers"}
|
| 31 |
-
# stored_data['business_details'] = {
|
| 32 |
-
# "business_type": "fitness and gym",
|
| 33 |
-
# "platform": "Instagram, TikTok",
|
| 34 |
-
# "target_audience": "young Nepali adults (ages 18β40) who are health-conscious and active on social media",
|
| 35 |
-
# "business_goals": "to expand gym branches across all major cities of Nepal and build a strong fitness community",
|
| 36 |
-
# "offerings": "personal training, group fitness classes, modern workout equipment, nutrition guidance, and wellness programs",
|
| 37 |
-
# "Challenges_faced": "attracting loyal members, standing out in a competitive market, and promoting consistent engagement"
|
| 38 |
-
# }
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# stored_data['final_ideation']= ['''A street magician performs tricks, leaving a crowd awestruck. One trick falters, inspiring him to hit the gym. Months later, he fuses fitness with magic, showcasing strength through performance, proving that transformation can captivate and inspire a community''',
|
| 43 |
-
# '''A group of strangers attends a quirky food festival, each trying bizarre dishes. One adventurer finds a fitness coach among them. They bond over health, sparking a weekly workout group that brings the community together, blending fun and fitness effortlessly.''',
|
| 44 |
-
# '''A lost hiker discovers a hidden waterfall, but slips on the rocks, nearly falling. A passing fitness enthusiast helps him up, encouraging regular exercise for safety and strength. Together, they start a hiking club, uniting fitness and nature lovers in their city''',
|
| 45 |
-
# '''A young Nepali woman discovers a hidden strength within herself while hiking the Himalayas. She returns home, and her fitness journey begins at our gym. With the help of our personal trainers, she transforms her body and mind. The gym becomes her sanctuary, and her transformation inspires others to find their inner strength.''']
|
| 46 |
-
|
| 47 |
-
# stored_data['human_ideation_interactions'] = []
|
| 48 |
-
# stored_data['refined_ideation'] = '''A street magician's trick fails, inspiring a fitness journey. Months later, he fuses magic with strength, showcasing transformation. Meanwhile, a fitness coach bonds with foodies over health, sparking a community workout group, blending fun and fitness.'''
|
| 49 |
-
|
| 50 |
-
class UserMessage(BaseModel):
|
| 51 |
message: str
|
| 52 |
-
|
| 53 |
|
| 54 |
@app.post("/orchestration")
|
| 55 |
-
def orchestration_endpoint(
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
| 61 |
@app.post("/context-analysis")
|
| 62 |
def context_analysis(msg: UserMessage):
|
| 63 |
response = context_analysis_graph.chat(msg.message)
|
|
|
|
| 9 |
from context_analysis_agent.utils.utils import save_to_db
|
| 10 |
import ast
|
| 11 |
from orchestration_agent.agent import orchestration_chat
|
| 12 |
+
from orchestration_agent.utils.utils import caption_image
|
| 13 |
from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
|
| 14 |
from idea_to_budget_agent.agent import budget_calculator
|
| 15 |
from ideation_agent.agent import ideation_graph
|
|
|
|
| 26 |
idea_graph = ideation_graph()
|
| 27 |
brainstrom_graph = brainstroming_graph()
|
| 28 |
human_refine_graph = human_refined_idea()
|
| 29 |
+
# orchestrate_graph = orchestration_chat()
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
class OrchestrationRequest(BaseModel):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
message: str
|
| 34 |
+
image_base64 : Optional[list] = []
|
| 35 |
|
| 36 |
@app.post("/orchestration")
|
| 37 |
+
def orchestration_endpoint(request:OrchestrationRequest):
|
| 38 |
+
print('Image:',request.image_base64)
|
| 39 |
+
result = orchestration_chat(request.message , request.image_base64)
|
| 40 |
+
stored_data['image_caption']= result.image_caption
|
| 41 |
+
return {'tool_response': result.tool , 'message_response': result.message, 'image_caption':result.image_caption}
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
+
class UserMessage(BaseModel):
|
| 46 |
+
message: str
|
| 47 |
@app.post("/context-analysis")
|
| 48 |
def context_analysis(msg: UserMessage):
|
| 49 |
response = context_analysis_graph.chat(msg.message)
|
orchestration_agent/agent.py
CHANGED
|
@@ -3,21 +3,27 @@ from langgraph.checkpoint.memory import MemorySaver
|
|
| 3 |
from .utils.nodes import orchestration_node
|
| 4 |
from utils.models_loader import llm
|
| 5 |
from .utils.state import ValidationFormatter
|
|
|
|
| 6 |
import re
|
| 7 |
memory = MemorySaver()
|
| 8 |
|
| 9 |
|
| 10 |
-
def
|
| 11 |
workflow = StateGraph(MessagesState)
|
| 12 |
workflow.add_node("chatbot", orchestration_node)
|
| 13 |
workflow.add_edge(START, "chatbot")
|
| 14 |
workflow.add_edge("chatbot", END)
|
| 15 |
return workflow.compile(checkpointer=memory)
|
| 16 |
|
| 17 |
-
def orchestration_chat(user_input: str):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
config = {"configurable": {"thread_id": "orchestration-thread"}}
|
| 20 |
-
response = agent.invoke({"messages": [user_input]}, config)['messages'][-1].content
|
| 21 |
response=llm.with_structured_output(ValidationFormatter).invoke(response)
|
| 22 |
return response
|
| 23 |
|
|
|
|
| 3 |
from .utils.nodes import orchestration_node
|
| 4 |
from utils.models_loader import llm
|
| 5 |
from .utils.state import ValidationFormatter
|
| 6 |
+
from .utils.utils import caption_image
|
| 7 |
import re
|
| 8 |
memory = MemorySaver()
|
| 9 |
|
| 10 |
|
| 11 |
+
def orchestration_graph():
|
| 12 |
workflow = StateGraph(MessagesState)
|
| 13 |
workflow.add_node("chatbot", orchestration_node)
|
| 14 |
workflow.add_edge(START, "chatbot")
|
| 15 |
workflow.add_edge("chatbot", END)
|
| 16 |
return workflow.compile(checkpointer=memory)
|
| 17 |
|
| 18 |
+
def orchestration_chat(user_input: str, image_base64=[]):
|
| 19 |
+
if len(image_base64)>0:
|
| 20 |
+
caption_response = caption_image(image_base64, user_input)
|
| 21 |
+
else:
|
| 22 |
+
caption_response =''
|
| 23 |
+
|
| 24 |
+
agent = orchestration_graph()
|
| 25 |
config = {"configurable": {"thread_id": "orchestration-thread"}}
|
| 26 |
+
response = agent.invoke({"messages": [f'''The user's message is:\n {user_input}\nThe information of image is:\n{caption_response}\n''']}, config)['messages'][-1].content
|
| 27 |
response=llm.with_structured_output(ValidationFormatter).invoke(response)
|
| 28 |
return response
|
| 29 |
|
orchestration_agent/utils/prompts.py
CHANGED
|
@@ -1,29 +1,45 @@
|
|
| 1 |
orchestration_prompt = """
|
| 2 |
-
You are
|
|
|
|
| 3 |
|
| 4 |
-
Your job is to analyze the user's input and return a JSON object with:
|
| 5 |
1. `tool`: the most appropriate tool name from the list below (or `null` if not applicable)
|
| 6 |
-
2. `message`: a clear, helpful message to show to the user. This can be a question, guidance or even an action confirmation depending on the
|
| 7 |
-
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
| 11 |
### Available Tools:
|
| 12 |
1. **ideation** β Use if the user wants to create marketing video ideas.
|
| 13 |
2. **human-idea-refining** β Use if the user gives feedback or asks to improve/change ideas.
|
| 14 |
-
3. **
|
| 15 |
-
4. **generate-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
---
|
| 19 |
|
| 20 |
### Rules:
|
| 21 |
-
-
|
| 22 |
-
- If the
|
| 23 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
### Output Format:
|
| 26 |
"tool": "the exact name of the tool",
|
| 27 |
-
"message": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
orchestration_prompt = """
|
| 2 |
+
You are a perfect marketing guide and AI orchestration agent that reads the user's message and decides which one of the following tools should be called next. You're perfect at analyzing the intention of the user.
|
| 3 |
+
Also you have to analyze that if any information of the image is provided as te input too. If any information of image is provided, just return that information simply.
|
| 4 |
|
| 5 |
+
Your job is to analyze the **user's input** only **not the information of the image** and return a JSON object with:
|
| 6 |
1. `tool`: the most appropriate tool name from the list below (or `null` if not applicable)
|
| 7 |
+
2. `message`: a clear, helpful message to show to the user. This can be a question, guidance or even an action confirmation depending on the user query. You can guide the user according to their intention.
|
| 8 |
+
3. 'image_caption' : Information of the image if provided, otherwise return a text of **No any information**.
|
| 9 |
---
|
| 10 |
|
|
|
|
| 11 |
### Available Tools:
|
| 12 |
1. **ideation** β Use if the user wants to create marketing video ideas.
|
| 13 |
2. **human-idea-refining** β Use if the user gives feedback or asks to improve/change ideas.
|
| 14 |
+
3. **generate-story** β Use if the user talks about **creating the story** from their idea **OR** if the user talks about **creating story with brainstorming**.
|
| 15 |
+
4. **generate-ultimate-story** β Use if the user is ready for a final or ultimate story/script based on ideas and already brainstormed topics from the previous tool called **generate-story**.
|
| 16 |
+
Remember one thing, **generate-ultimate-story** is never invoked without invoking **generate-story**.
|
| 17 |
+
5. **generate-image** β Use if the user wants a visual or image based on the ultimate story.
|
| 18 |
|
| 19 |
---
|
| 20 |
|
| 21 |
### Rules:
|
| 22 |
+
- Only use the **user's message** for understanding the intent.
|
| 23 |
+
- If the user is **asking about the image**, return the image information as the `message` and set `"tool": null`.
|
| 24 |
+
- If the message **clearly maps to a tool**, return the tool name and a relevant message.
|
| 25 |
+
- If the message is **unclear or not actionable**, set `tool` to `null` and return a helpful clarification question in `message`.
|
| 26 |
+
- If there is no any provided information of image, just interact with the user according to your job.
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
|
| 30 |
### Output Format:
|
| 31 |
"tool": "the exact name of the tool",
|
| 32 |
+
"message": "Guidance to the business campaigns like asking questions, giving suggestions etc."
|
| 33 |
+
"image_caption" : Information of the image if provided, otherwise return a text of **No any information**.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
|
| 39 |
|
| 40 |
+
def captioning_prompt(user_input):
|
| 41 |
+
return f'''
|
| 42 |
+
Caption the image based on the user question if the user asks something about the image.
|
| 43 |
+
If the user question is not relevant to te image provided, just caption the image and give the information provided in the image in just 50 words.
|
| 44 |
+
The user input is:**{user_input}**
|
| 45 |
+
'''
|
orchestration_agent/utils/state.py
CHANGED
|
@@ -4,3 +4,4 @@ from pydantic import BaseModel, Field
|
|
| 4 |
class ValidationFormatter(BaseModel):
|
| 5 |
tool: str = Field(description="Returns the name of the tool.")
|
| 6 |
message: str = Field(description="Returns the message or response of the user query.")
|
|
|
|
|
|
| 4 |
class ValidationFormatter(BaseModel):
|
| 5 |
tool: str = Field(description="Returns the name of the tool.")
|
| 6 |
message: str = Field(description="Returns the message or response of the user query.")
|
| 7 |
+
image_caption: str = Field(description="Returns information of the image if provided. Otherwise returns null.")
|
orchestration_agent/utils/utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import ast
|
| 4 |
+
from groq import Groq
|
| 5 |
+
import os
|
| 6 |
+
from .prompts import captioning_prompt
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def caption_image(image_base64,user_input):
|
| 10 |
+
if len(image_base64)>0:
|
| 11 |
+
print('Captioning image')
|
| 12 |
+
client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
|
| 13 |
+
|
| 14 |
+
chat_completion = client.chat.completions.create(
|
| 15 |
+
messages=[
|
| 16 |
+
{
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": [
|
| 19 |
+
{"type": "text", "text": captioning_prompt(user_input)},
|
| 20 |
+
{
|
| 21 |
+
"type": "image_url",
|
| 22 |
+
"image_url": {
|
| 23 |
+
"url": f"data:image/jpg;base64,{image_base64[-1]}",
|
| 24 |
+
},
|
| 25 |
+
},
|
| 26 |
+
],
|
| 27 |
+
}
|
| 28 |
+
],
|
| 29 |
+
model="meta-llama/llama-4-scout-17b-16e-instruct",
|
| 30 |
+
max_completion_tokens=50,
|
| 31 |
+
temperature = 1
|
| 32 |
+
)
|
| 33 |
+
response=chat_completion.choices[0].message.content
|
| 34 |
+
return response
|
| 35 |
+
else:
|
| 36 |
+
return ''
|
| 37 |
+
|
| 38 |
+
|