omarash2016 commited on
Commit
ebdd354
·
verified ·
1 Parent(s): bd84a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -26,6 +26,7 @@ def bytes_to_pil(image_bytes: bytes):
26
 
27
  # --- 2. MCP TOOL FUNCTIONS ---
28
  def tool_web_search(query: str):
 
29
  print(f"🔍 Search Tool: {query}...")
30
  try:
31
  results = DDGS().text(query, max_results=4)
@@ -37,6 +38,7 @@ def tool_web_search(query: str):
37
  return f"Search Error: {str(e)}"
38
 
39
  def tool_generate_image(prompt: str):
 
40
  print(f"🎨 Image Tool: {prompt[:40]}...")
41
  try:
42
  response = nebius_client.images.generate(
@@ -50,6 +52,7 @@ def tool_generate_image(prompt: str):
50
  b64_data = response.data[0].b64_json
51
  image_bytes = base64.b64decode(b64_data)
52
  img = Image.open(io.BytesIO(image_bytes))
 
53
  filename = f"gen_{abs(hash(prompt))}.png"
54
  img.save(filename)
55
  return filename
@@ -100,14 +103,17 @@ def tool_summarize_market_insights(text: str):
100
 
101
  # --- 3. AUTONOMOUS BRAND AGENT ---
102
  def run_autonomous_agent(company_name, business_type, style, progress=gr.Progress()):
 
103
  progress(0.1, desc="Step 1: Planning & Palette...")
104
  color_prompt = (
105
  f"Create a distinct, 5-color palette for a {business_type} named '{company_name}' "
106
  f"with a {style} style. Return ONLY a comma-separated list of hex codes."
107
  )
108
  colors_text = tool_generate_text(color_prompt, "You are a design expert. Output only the requested list.").strip().strip('.')
109
- log = f"✅ Brand Plan Started for {company_name}\n🎨 Palette: {colors_text}\n"
 
110
 
 
111
  progress(0.3, desc="Step 2: Generating Logo...")
112
  logo_prompt = (
113
  f"A professional minimalist logo for a {business_type} named '{company_name}'. "
@@ -116,6 +122,7 @@ def run_autonomous_agent(company_name, business_type, style, progress=gr.Progres
116
  logo_path = tool_generate_image(logo_prompt)
117
  log += "🖼️ Logo Generated.\n"
118
 
 
119
  progress(0.5, desc="Step 3: Color Palette Asset...")
120
  asset_prompt = (
121
  f"A professional color palette guide with 5 circular swatches arranged in a row. "
@@ -124,15 +131,18 @@ def run_autonomous_agent(company_name, business_type, style, progress=gr.Progres
124
  asset_path = tool_generate_image(asset_prompt)
125
  log += "🖼️ Palette Asset Generated.\n"
126
 
 
127
  progress(0.65, desc="Step 4: Raw Market Research...")
128
  search_query = f"marketing trends for {business_type} 2025"
129
  raw_research = tool_web_search(search_query)
130
  log += f"🔍 Market Data Retrieved: {search_query}\n"
131
 
 
132
  progress(0.8, desc="Step 4.5: Summarizing Insights...")
133
  summarized = tool_summarize_market_insights(raw_research)
134
  log += f"🧠 Market Insights Summary: {summarized[:150]}...\n"
135
 
 
136
  progress(0.95, desc="Step 5: Writing Social Content...")
137
  copy_prompt = f"""
138
  Write 3 engaging Twitter/X posts for a new {business_type} called '{company_name}'.
@@ -141,7 +151,8 @@ def run_autonomous_agent(company_name, business_type, style, progress=gr.Progres
141
  {summarized}
142
  """
143
  social_copy = tool_generate_text(copy_prompt, "You are a professional social media strategist.", max_tokens=1500)
144
- log += "✍️ Social Copy Generated.\n✅ Autonomy Cycle Complete."
 
145
 
146
  return logo_path, asset_path, social_copy, log, summarized
147
 
@@ -167,8 +178,7 @@ def chat_response(message, history):
167
  history.append({"role": "assistant", "content": f"Error: {e}"})
168
  return history, ""
169
 
170
- # --- 5. GRADIO UI (Compatible with v6) ---
171
- custom_css = """#main-header {text-align: center; margin-bottom: 2rem;}"""
172
  theme = gr.themes.Soft(
173
  primary_hue="indigo",
174
  secondary_hue="blue",
@@ -181,13 +191,17 @@ theme = gr.themes.Soft(
181
  block_shadow="0 4px 6px rgba(0,0,0,0.1)",
182
  )
183
 
184
- demo = gr.Blocks(css=custom_css, title="AutoBrand MCP Studio")
185
- demo.theme = theme # set theme AFTER creating Blocks
 
 
 
 
186
 
187
  with demo:
188
  # HEADER
189
  with gr.Column(elem_id="main-header"):
190
- gr.Markdown("# 🖼️ AutoBrand Studio")
191
  gr.Markdown("Autonomous Agent powered by AI Models, MCP Tools & Web Search. Connect Claude Desktop to use these tools!")
192
 
193
  with gr.Row():
@@ -204,17 +218,20 @@ with demo:
204
  # RIGHT PANEL
205
  with gr.Column(scale=2):
206
  with gr.Tabs():
 
207
  with gr.TabItem("🎨 Brand Identity"):
208
  with gr.Row():
209
  out_logo = gr.Image(label="Logo Concept", height=350, type="filepath")
210
  out_asset = gr.Image(label="Color Palette", height=350, type="filepath")
211
  out_copy = gr.TextArea(label="Generated Social Content", lines=15, show_copy_button=True, interactive=False)
212
 
 
213
  with gr.TabItem("💬 Brand Consultant"):
214
  chatbot = gr.Chatbot(label="AI Consultant", height=650, type="messages")
215
  chat_input = gr.Textbox(show_label=False, placeholder="Ask something...")
216
  chat_btn = gr.Button("Send")
217
 
 
218
  with gr.TabItem("📊 Market Insight Summary"):
219
  summary_box = gr.TextArea(label="Summarized Market Insights", lines=20, interactive=False, show_copy_button=True)
220
 
@@ -226,7 +243,7 @@ with demo:
226
  generate_btn.click(
227
  run_agent_and_extract_summary,
228
  [company_input, type_input, style_input],
229
- [out_logo, out_asset, out_copy, out_log, summary_box]
230
  )
231
 
232
  chat_btn.click(chat_response, [chat_input, chatbot], [chatbot, chat_input])
 
26
 
27
  # --- 2. MCP TOOL FUNCTIONS ---
28
  def tool_web_search(query: str):
29
+ """Performs a market research search using DuckDuckGo."""
30
  print(f"🔍 Search Tool: {query}...")
31
  try:
32
  results = DDGS().text(query, max_results=4)
 
38
  return f"Search Error: {str(e)}"
39
 
40
  def tool_generate_image(prompt: str):
41
+ """Generates an image and returns the local file path."""
42
  print(f"🎨 Image Tool: {prompt[:40]}...")
43
  try:
44
  response = nebius_client.images.generate(
 
52
  b64_data = response.data[0].b64_json
53
  image_bytes = base64.b64decode(b64_data)
54
  img = Image.open(io.BytesIO(image_bytes))
55
+
56
  filename = f"gen_{abs(hash(prompt))}.png"
57
  img.save(filename)
58
  return filename
 
103
 
104
  # --- 3. AUTONOMOUS BRAND AGENT ---
105
  def run_autonomous_agent(company_name, business_type, style, progress=gr.Progress()):
106
+ # PHASE 1: COLOR PALETTE
107
  progress(0.1, desc="Step 1: Planning & Palette...")
108
  color_prompt = (
109
  f"Create a distinct, 5-color palette for a {business_type} named '{company_name}' "
110
  f"with a {style} style. Return ONLY a comma-separated list of hex codes."
111
  )
112
  colors_text = tool_generate_text(color_prompt, "You are a design expert. Output only the requested list.").strip().strip('.')
113
+ log = f"✅ Brand Plan Started for {company_name}\n"
114
+ log += f"🎨 Palette: {colors_text}\n"
115
 
116
+ # PHASE 2: LOGO
117
  progress(0.3, desc="Step 2: Generating Logo...")
118
  logo_prompt = (
119
  f"A professional minimalist logo for a {business_type} named '{company_name}'. "
 
122
  logo_path = tool_generate_image(logo_prompt)
123
  log += "🖼️ Logo Generated.\n"
124
 
125
+ # PHASE 3: COLOR PALETTE ASSET
126
  progress(0.5, desc="Step 3: Color Palette Asset...")
127
  asset_prompt = (
128
  f"A professional color palette guide with 5 circular swatches arranged in a row. "
 
131
  asset_path = tool_generate_image(asset_prompt)
132
  log += "🖼️ Palette Asset Generated.\n"
133
 
134
+ # PHASE 4: RAW MARKET RESEARCH
135
  progress(0.65, desc="Step 4: Raw Market Research...")
136
  search_query = f"marketing trends for {business_type} 2025"
137
  raw_research = tool_web_search(search_query)
138
  log += f"🔍 Market Data Retrieved: {search_query}\n"
139
 
140
+ # PHASE 4.5: SUMMARIZE MARKET INSIGHTS
141
  progress(0.8, desc="Step 4.5: Summarizing Insights...")
142
  summarized = tool_summarize_market_insights(raw_research)
143
  log += f"🧠 Market Insights Summary: {summarized[:150]}...\n"
144
 
145
+ # PHASE 5: SOCIAL MEDIA COPY
146
  progress(0.95, desc="Step 5: Writing Social Content...")
147
  copy_prompt = f"""
148
  Write 3 engaging Twitter/X posts for a new {business_type} called '{company_name}'.
 
151
  {summarized}
152
  """
153
  social_copy = tool_generate_text(copy_prompt, "You are a professional social media strategist.", max_tokens=1500)
154
+ log += "✍️ Social Copy Generated.\n"
155
+ log += "✅ Autonomy Cycle Complete."
156
 
157
  return logo_path, asset_path, social_copy, log, summarized
158
 
 
178
  history.append({"role": "assistant", "content": f"Error: {e}"})
179
  return history, ""
180
 
181
+ # --- 5. GRADIO UI ---
 
182
  theme = gr.themes.Soft(
183
  primary_hue="indigo",
184
  secondary_hue="blue",
 
191
  block_shadow="0 4px 6px rgba(0,0,0,0.1)",
192
  )
193
 
194
+ custom_css = "#main-header {text-align: center; margin-bottom: 2rem;}"
195
+
196
+ # Create Blocks (Gradio 6 compatible)
197
+ demo = gr.Blocks()
198
+ demo.theme = theme
199
+ demo.css = custom_css
200
 
201
  with demo:
202
  # HEADER
203
  with gr.Column(elem_id="main-header"):
204
+ gr.Markdown("# 🖼️ AutoBrand MCP Studio")
205
  gr.Markdown("Autonomous Agent powered by AI Models, MCP Tools & Web Search. Connect Claude Desktop to use these tools!")
206
 
207
  with gr.Row():
 
218
  # RIGHT PANEL
219
  with gr.Column(scale=2):
220
  with gr.Tabs():
221
+ # BRAND IDENTITY TAB
222
  with gr.TabItem("🎨 Brand Identity"):
223
  with gr.Row():
224
  out_logo = gr.Image(label="Logo Concept", height=350, type="filepath")
225
  out_asset = gr.Image(label="Color Palette", height=350, type="filepath")
226
  out_copy = gr.TextArea(label="Generated Social Content", lines=15, show_copy_button=True, interactive=False)
227
 
228
+ # BRAND CONSULTANT CHATBOT TAB
229
  with gr.TabItem("💬 Brand Consultant"):
230
  chatbot = gr.Chatbot(label="AI Consultant", height=650, type="messages")
231
  chat_input = gr.Textbox(show_label=False, placeholder="Ask something...")
232
  chat_btn = gr.Button("Send")
233
 
234
+ # MARKET INSIGHT SUMMARY TAB
235
  with gr.TabItem("📊 Market Insight Summary"):
236
  summary_box = gr.TextArea(label="Summarized Market Insights", lines=20, interactive=False, show_copy_button=True)
237
 
 
243
  generate_btn.click(
244
  run_agent_and_extract_summary,
245
  [company_input, type_input, style_input],
246
+ [out_logo, out_asset, out_copy, out_log, summary_box],
247
  )
248
 
249
  chat_btn.click(chat_response, [chat_input, chatbot], [chatbot, chat_input])