muhammadmaazuddin commited on
Commit
2eaa145
·
1 Parent(s): 7cb6847

working on post generation

Browse files
Files changed (2) hide show
  1. src/_agents.py +12 -11
  2. src/main.py +23 -18
src/_agents.py CHANGED
@@ -19,8 +19,11 @@ import fal_client
19
  from PIL import Image
20
  from io import BytesIO
21
  from IPython.display import display
22
-
23
  import logging
 
 
 
24
  logging.basicConfig(level=logging.INFO)
25
 
26
 
@@ -30,6 +33,11 @@ aspect_ratios = {
30
  }
31
 
32
 
 
 
 
 
 
33
  #----------------------- content agent ----------------------------------
34
 
35
  def content_prompt(context: RunContextWrapper, agent: Agent):
@@ -123,7 +131,7 @@ post_schema = """
123
 
124
 
125
  @function_tool
126
- def generate_designSpec_from_brief(design_brief: str, defaultValues:str) -> dict:
127
  """Generates a detailed design specification in JSON format from a high-level design brief.
128
 
129
  This function takes a natural language description of a social media post and uses an AI model
@@ -132,7 +140,6 @@ def generate_designSpec_from_brief(design_brief: str, defaultValues:str) -> dict
132
 
133
  Args:
134
  design_brief: A string containing the high-level creative brief for the social media post.
135
- defaultValues: A string providing default values to consider, such as aspect ratio (e.g., "aspect_ratio:1:1").
136
 
137
  Returns:
138
  A dictionary containing the detailed design specification in JSON format.
@@ -158,11 +165,10 @@ Rules:
158
  design_brief:
159
  {design_brief}
160
 
161
- defaultValues:{defaultValues}
162
  """
163
 
164
 
165
- prompt = schema_template.format(design_brief=design_brief,defaultValues=defaultValues,post_schema=post_schema, )
166
 
167
 
168
  response = client.models.generate_content(
@@ -183,7 +189,6 @@ defaultValues:{defaultValues}
183
 
184
  def image_generate_prompt(design_brief, designSpec):
185
  return f"""
186
- You are a professional social media AI specialized in creating high-quality, visually striking images for social media posts.
187
  Your goal is to generate attention-grabbing, brand-aligned images that clearly communicate the given message, following design best practices and platform-specific guidelines.
188
 
189
  Design Brief:
@@ -219,10 +224,6 @@ async def generate_post_image(
219
  ):
220
  """Generates a social media post image based on a design brief and a detailed specification.
221
 
222
- This function uses an AI image generation service to create a visual based on a natural
223
- language design brief and a structured JSON design specification. It returns the URL
224
- of the generated image.
225
-
226
  Args:
227
  design_brief: A string containing the high-level creative brief for the image.
228
  designSpec: A string containing the detailed JSON design specification.
@@ -284,7 +285,7 @@ async def generate_post_image(
284
 
285
  def media_agent_prompt(context: RunContextWrapper, agent: Agent):
286
  return """
287
- You are Media Agent, a professional AI specialized in creating social media post.
288
 
289
  Your task:
290
  1. Receive a high-level user brief describing a social media post idea.
 
19
  from PIL import Image
20
  from io import BytesIO
21
  from IPython.display import display
22
+ from google import genai
23
  import logging
24
+
25
+
26
+
27
  logging.basicConfig(level=logging.INFO)
28
 
29
 
 
33
  }
34
 
35
 
36
+ client = genai.Client(
37
+ # vertexai=True, project='1089055075981', location='us-central1'
38
+ )
39
+
40
+
41
  #----------------------- content agent ----------------------------------
42
 
43
  def content_prompt(context: RunContextWrapper, agent: Agent):
 
131
 
132
 
133
  @function_tool
134
+ def generate_designSpec_from_brief(design_brief: str) -> dict:
135
  """Generates a detailed design specification in JSON format from a high-level design brief.
136
 
137
  This function takes a natural language description of a social media post and uses an AI model
 
140
 
141
  Args:
142
  design_brief: A string containing the high-level creative brief for the social media post.
 
143
 
144
  Returns:
145
  A dictionary containing the detailed design specification in JSON format.
 
165
  design_brief:
166
  {design_brief}
167
 
 
168
  """
169
 
170
 
171
+ prompt = schema_template.format(design_brief=design_brief,post_schema=post_schema, )
172
 
173
 
174
  response = client.models.generate_content(
 
189
 
190
  def image_generate_prompt(design_brief, designSpec):
191
  return f"""
 
192
  Your goal is to generate attention-grabbing, brand-aligned images that clearly communicate the given message, following design best practices and platform-specific guidelines.
193
 
194
  Design Brief:
 
224
  ):
225
  """Generates a social media post image based on a design brief and a detailed specification.
226
 
 
 
 
 
227
  Args:
228
  design_brief: A string containing the high-level creative brief for the image.
229
  designSpec: A string containing the detailed JSON design specification.
 
285
 
286
  def media_agent_prompt(context: RunContextWrapper, agent: Agent):
287
  return """
288
+ You are Media Agent, a professional and specialized in creating social media for post.
289
 
290
  Your task:
291
  1. Receive a high-level user brief describing a social media post idea.
src/main.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import asyncio
3
  from dataclasses import dataclass
4
  from agents import set_tracing_disabled, Runner, SQLiteSession, Agent, AgentHooks , RunHooks, RunContextWrapper, TContext, Tool
5
- from _agents import content_agent, WebInspectorAgent
6
  from pydantic import BaseModel, Field, ConfigDict
7
  from model import get_model
8
  from typing import Optional
@@ -56,32 +56,31 @@ class AgentContext(BaseModel):
56
 
57
 
58
  def media_post_prompt(context: RunContextWrapper, agent: Agent):
59
-
60
- # 4. Provide the generated content and relevant details to the Media Generation Agent to create images or media.
61
- # 5. Combine all outputs into a coherent final post suitable for the requested platform.
62
-
63
- return """You are the Post Generation Agent for Social media.
64
  Your task is to coordinate multiple agents to produce a complete social media post.
65
 
66
- You can execute the follow tasks:
67
  - Content Generation
68
  - Media Generation
69
 
70
  Steps for Generating Content:
71
- 1. Extract text website.
72
- 2. Pass the extracted text and user brief to the Content Agent to generate engaging platform-specific post text.
73
 
74
  Steps for Generating Media:
75
- 1. Extract text website.
76
-
77
 
78
- AT THE END RETURN FULL REPORT TO THE UESR
 
 
79
 
80
  Rules:
81
  - Do not generate text or media yourself.
82
- - Always follow the above order.
83
  - Validate each agent's output before proceeding to the next step.
84
- - Ask the user for clarification only if the input is missing or ambiguous."""
 
85
 
86
 
87
  async def main():
@@ -110,20 +109,26 @@ Generates engaging social media post content based on user input.
110
  tool_name="WebInspectorAgent",
111
  tool_description="""Extracts details from a website using given URL, such as visible text content, theme colors etc."""
112
  ),
 
 
 
 
 
 
 
 
113
  ],
114
  model=get_model('gemini-2.0-flash'),
115
 
116
  )
117
 
118
  result = await Runner.run(social_media_post_gen_agent,
119
- input="""
120
- Create a LinkedIn post about the importance of AI in modern business strategies for this website https://denovers.com
121
- """ ,
122
  session=session,
123
  context=agent_context,
124
  )
125
  print('-----------------------------session--------------------------')
126
- print(await session.get_items())
127
  # print(result)
128
 
129
 
 
2
  import asyncio
3
  from dataclasses import dataclass
4
  from agents import set_tracing_disabled, Runner, SQLiteSession, Agent, AgentHooks , RunHooks, RunContextWrapper, TContext, Tool
5
+ from _agents import content_agent, WebInspectorAgent, media_agent
6
  from pydantic import BaseModel, Field, ConfigDict
7
  from model import get_model
8
  from typing import Optional
 
56
 
57
 
58
  def media_post_prompt(context: RunContextWrapper, agent: Agent):
59
+ return """You are the Post Generation Agent for Social Media.
 
 
 
 
60
  Your task is to coordinate multiple agents to produce a complete social media post.
61
 
62
+ You can execute the following tasks:
63
  - Content Generation
64
  - Media Generation
65
 
66
  Steps for Generating Content:
67
+ 1. Extract website text using the Web Inspector Tool.
68
+ 2. Provide the extracted text along with the user's brief to the Content Tool to generate engaging, platform-specific post text.
69
 
70
  Steps for Generating Media:
71
+ 1. Extract key text and theme colors from the website.
72
+ 2. Provide the extracted website content, the user's brief, and the design brief to the Media Tool.
73
 
74
+ Final Step:
75
+ - Combine all outputs into a coherent, platform-ready social media post.
76
+ - Return a full report to the user, including the generated content, images, and any design details.
77
 
78
  Rules:
79
  - Do not generate text or media yourself.
80
+ - Always follow the steps in order.
81
  - Validate each agent's output before proceeding to the next step.
82
+ - Ask the user for clarification only if the input is missing or ambiguous.
83
+ """
84
 
85
 
86
  async def main():
 
109
  tool_name="WebInspectorAgent",
110
  tool_description="""Extracts details from a website using given URL, such as visible text content, theme colors etc."""
111
  ),
112
+ media_agent.as_tool(
113
+ tool_name="media_agent",
114
+ tool_description="""
115
+ Generates high-quality, brand-aligned social media images based on the user's brief,
116
+ design specifications, and extracted website content (text, colors, and theme).
117
+ Follows design guidelines for style, composition, typography, colors, dark/light theme and platform-specific requirements.
118
+ """
119
+ )
120
  ],
121
  model=get_model('gemini-2.0-flash'),
122
 
123
  )
124
 
125
  result = await Runner.run(social_media_post_gen_agent,
126
+ input="""Create a LinkedIn post this website https://denovers.com, Post related the services we provide""" ,
 
 
127
  session=session,
128
  context=agent_context,
129
  )
130
  print('-----------------------------session--------------------------')
131
+ # print(await session.get_items())
132
  # print(result)
133
 
134