omarash2016 commited on
Commit
59cf03e
·
verified ·
1 Parent(s): dcc6065

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -7,6 +7,9 @@ import os
7
 
8
  # Get your secret key from Hugging Face Space Secrets
9
  NEBIUS_API_KEY = os.environ.get("NEBIUS_API_KEY")
 
 
 
10
  NEBIUS_BASE_URL = "https://api.tokenfactory.nebius.com/v1/" # Use the URL from your Nebius dashboard
11
  TEXT_MODEL = "meta-llama/Llama-3.3-70B-Instruct" # Use a text model from your dashboard
12
  IMAGE_MODEL = "black-forest-labs/flux-schnell" # Use an image model from your dashboard
@@ -66,40 +69,51 @@ def call_image_gen_tool(prompt: str) -> str:
66
  def run_brand_agent_plan(company_name, business_type, style, progress=gr.Progress()):
67
 
68
  # 1. PLANNING
69
- # The agent creates its 3-step plan autonomously.
70
  progress(0, desc="Agent is creating a plan...")
71
 
72
- # *** UPDATED: Plan now includes the color palette prompt ***
73
  plan = [
74
- {"step": 1, "action": call_image_gen_tool, "prompt": f"A {style} logo for a {business_type} named '{company_name}'. Clean, high-resolution, white background."},
75
- {"step": 2, "action": call_image_gen_tool, "prompt": f"A refined {style} color palette presentation for a {company_name} {business_type}. Show 5 distinct, harmonious colors in a modern, clean layout. Photorealistic, minimalist, with subtle textures. No text."},
76
- {"step": 3, "action": call_text_gen_tool, "prompt": f"Write 3 short, catchy social media posts (for X/Twitter) announcing a new {business_type} called '{company_name}'. The vibe is {style}."}
 
77
  ]
78
 
79
  log_message = "Agent Plan Created:\n"
80
- log_message += f"- Step 1: {plan[0]['action'].__name__}\n"
81
- log_message += f"- Step 2: {plan[1]['action'].__name__} (Color Palette)\n"
82
- log_message += f"- Step 3: {plan[2]['action'].__name__}\n"
 
83
 
84
  results = {}
85
 
86
  # 2. EXECUTION
87
 
88
- # Step 1: Generate Logo
89
- progress(0.2, desc="Executing Step 1: Calling Nebius Image Tool (Logo)...")
90
- results["logo_url"] = plan[0]["action"](plan[0]["prompt"])
91
- log_message += f"Step 1 Complete. Logo URL acquired.\n"
92
-
93
- # Step 2: Generate Color Palette
94
- progress(0.5, desc="Executing Step 2: Calling Nebius Image Tool (Color Palette)...")
95
- results["palette_url"] = plan[1]["action"](plan[1]["prompt"])
96
- log_message += f"Step 2 Complete. Color Palette URL acquired.\n"
 
 
 
 
 
 
 
 
 
97
 
98
- # Step 3: Generate Social Copy
99
- progress(0.8, desc="Executing Step 3: Calling Nebius Text Tool (Copy)...")
100
  system_prompt_kit = "You are a helpful branding assistant. Be creative and concise."
101
- results["copy_text"] = plan[2]["action"](plan[2]["prompt"], system_prompt_kit)
102
- log_message += "Step 3 Complete. Copy generated.\n"
103
 
104
  progress(1.0, desc="Agent Execution Complete!")
105
  log_message += "Plan executed successfully."
@@ -154,7 +168,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
154
  with gr.TabItem("Brand Kit Results"):
155
  with gr.Row():
156
  logo_output = gr.Image(label="Generated Logo (from Nebius)", height=400)
157
- # *** UPDATED: Renamed component to 'color_palette_output' ***
158
  color_palette_output = gr.Image(label="Generated Color Palette (from Nebius)", height=400)
159
  copy_output = gr.Textbox(label="Generated Social Media Copy (from Nebius)", lines=8, interactive=True)
160
 
@@ -170,7 +183,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
170
 
171
  # --- Wire up the UI ---
172
 
173
- # *** UPDATED: Changed one of the outputs to 'color_palette_output' ***
174
  submit_btn.click(
175
  fn=run_brand_agent_plan,
176
  inputs=[company_input, business_type_input, style_input],
 
7
 
8
  # Get your secret key from Hugging Face Space Secrets
9
  NEBIUS_API_KEY = os.environ.get("NEBIUS_API_KEY")
10
+
11
+ # --- UPDATE THESE VALUES ---
12
+ # Make sure to include "https://" and the "/v1/" path
13
  NEBIUS_BASE_URL = "https://api.tokenfactory.nebius.com/v1/" # Use the URL from your Nebius dashboard
14
  TEXT_MODEL = "meta-llama/Llama-3.3-70B-Instruct" # Use a text model from your dashboard
15
  IMAGE_MODEL = "black-forest-labs/flux-schnell" # Use an image model from your dashboard
 
69
  def run_brand_agent_plan(company_name, business_type, style, progress=gr.Progress()):
70
 
71
  # 1. PLANNING
72
+ # The agent creates its 4-step plan autonomously.
73
  progress(0, desc="Agent is creating a plan...")
74
 
75
+ # *** NEW 4-STEP PLAN ***
76
  plan = [
77
+ {"step": 1, "action": "generate_color_text", "prompt": f"Generate a 5-color palette for a {business_type} with a {style} vibe. List the colors as a simple, comma-separated string, e.g., 'Deep espresso brown, warm cream, rustic bronze, slate grey, soft olive green'."},
78
+ {"step": 2, "action": "generate_logo_from_colors"}, # Will be defined in execution
79
+ {"step": 3, "action": "generate_palette_from_colors"}, # Will be defined in execution
80
+ {"step": 4, "action": "generate_social_copy", "prompt": f"Write 3 short, catchy social media posts (for X/Twitter) announcing a new {business_type} called '{company_name}'. The vibe is {style}."}
81
  ]
82
 
83
  log_message = "Agent Plan Created:\n"
84
+ log_message += f"- Step 1: Generate color palette (as text)\n"
85
+ log_message += f"- Step 2: Generate logo from colors\n"
86
+ log_message += f"- Step 3: Generate palette image from colors\n"
87
+ log_message += f"- Step 4: Generate social media copy\n"
88
 
89
  results = {}
90
 
91
  # 2. EXECUTION
92
 
93
+ # Step 1: Generate Color Palette (as Text)
94
+ progress(0.2, desc="Executing Step 1: Calling Nebius Text Tool (for Colors)...")
95
+ system_prompt_colors = "You are a concise branding expert. Only output a single, comma-separated list of 5 colors. Do not add any other text, labels, or explanations."
96
+ color_palette_text = call_text_gen_tool(plan[0]["prompt"], system_prompt_colors)
97
+ results["color_text"] = color_palette_text.strip() # Store the colors
98
+ log_message += f"Step 1 Complete. Colors decided: {results['color_text']}\n"
99
+
100
+ # Step 2: Generate Logo (using colors from Step 1)
101
+ progress(0.4, desc="Executing Step 2: Calling Nebius Image Tool (Logo)...")
102
+ logo_prompt = f"A {style} logo for a {business_type} named '{company_name}'. Use *only* the following colors: {results['color_text']}. The logo should be an abstract icon or geometric mark. NO TEXT."
103
+ results["logo_url"] = call_image_gen_tool(logo_prompt)
104
+ log_message += f"Step 2 Complete. Logo URL acquired.\n"
105
+
106
+ # Step 3: Generate Color Palette Image (using colors from Step 1)
107
+ progress(0.7, desc="Executing Step 3: Calling Nebius Image Tool (Color Palette)...")
108
+ palette_prompt = f"A refined color palette presentation. Show 5 distinct, harmonious colors in a modern, clean layout. The colors are: {results['color_text']}. No text."
109
+ results["palette_url"] = call_image_gen_tool(palette_prompt)
110
+ log_message += f"Step 3 Complete. Color Palette URL acquired.\n"
111
 
112
+ # Step 4: Generate Social Copy
113
+ progress(0.9, desc="Executing Step 4: Calling Nebius Text Tool (Copy)...")
114
  system_prompt_kit = "You are a helpful branding assistant. Be creative and concise."
115
+ results["copy_text"] = call_text_gen_tool(plan[3]["prompt"], system_prompt_kit)
116
+ log_message += "Step 4 Complete. Copy generated.\n"
117
 
118
  progress(1.0, desc="Agent Execution Complete!")
119
  log_message += "Plan executed successfully."
 
168
  with gr.TabItem("Brand Kit Results"):
169
  with gr.Row():
170
  logo_output = gr.Image(label="Generated Logo (from Nebius)", height=400)
 
171
  color_palette_output = gr.Image(label="Generated Color Palette (from Nebius)", height=400)
172
  copy_output = gr.Textbox(label="Generated Social Media Copy (from Nebius)", lines=8, interactive=True)
173
 
 
183
 
184
  # --- Wire up the UI ---
185
 
 
186
  submit_btn.click(
187
  fn=run_brand_agent_plan,
188
  inputs=[company_input, business_type_input, style_input],