Update app.py
Browse files
app.py
CHANGED
|
@@ -7,9 +7,7 @@ import os
|
|
| 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 |
-
NEBIUS_BASE_URL = "https://api.tokenfactory.nebius.com/v1/" # Use the URL from your Nebius dashboard" # Use the URL from your Nebius dashboard
|
| 13 |
TEXT_MODEL = "meta-llama/Llama-3.3-70B-Instruct" # Use a text model from your dashboard
|
| 14 |
IMAGE_MODEL = "black-forest-labs/flux-schnell" # Use an image model from your dashboard
|
| 15 |
|
|
@@ -65,23 +63,22 @@ def call_image_gen_tool(prompt: str) -> str:
|
|
| 65 |
|
| 66 |
# --- 3. DEFINE THE AUTONOMOUS AGENT LOGIC ---
|
| 67 |
|
| 68 |
-
# *** UPDATED: Added 'business_type' as an input ***
|
| 69 |
def run_brand_agent_plan(company_name, business_type, style, progress=gr.Progress()):
|
| 70 |
|
| 71 |
# 1. PLANNING
|
| 72 |
# The agent creates its 3-step plan autonomously.
|
| 73 |
progress(0, desc="Agent is creating a plan...")
|
| 74 |
|
| 75 |
-
# *** UPDATED:
|
| 76 |
plan = [
|
| 77 |
{"step": 1, "action": call_image_gen_tool, "prompt": f"A {style} logo for a {business_type} named '{company_name}'. Clean, high-resolution, white background."},
|
| 78 |
-
{"step": 2, "action": call_image_gen_tool, "prompt": f"A
|
| 79 |
{"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}."}
|
| 80 |
]
|
| 81 |
|
| 82 |
log_message = "Agent Plan Created:\n"
|
| 83 |
log_message += f"- Step 1: {plan[0]['action'].__name__}\n"
|
| 84 |
-
log_message += f"- Step 2: {plan[1]['action'].__name__}\n"
|
| 85 |
log_message += f"- Step 3: {plan[2]['action'].__name__}\n"
|
| 86 |
|
| 87 |
results = {}
|
|
@@ -93,10 +90,10 @@ def run_brand_agent_plan(company_name, business_type, style, progress=gr.Progres
|
|
| 93 |
results["logo_url"] = plan[0]["action"](plan[0]["prompt"])
|
| 94 |
log_message += f"Step 1 Complete. Logo URL acquired.\n"
|
| 95 |
|
| 96 |
-
# Step 2: Generate
|
| 97 |
-
progress(0.5, desc="Executing Step 2: Calling Nebius Image Tool (
|
| 98 |
-
results["
|
| 99 |
-
log_message += f"Step 2 Complete.
|
| 100 |
|
| 101 |
# Step 3: Generate Social Copy
|
| 102 |
progress(0.8, desc="Executing Step 3: Calling Nebius Text Tool (Copy)...")
|
|
@@ -109,10 +106,9 @@ def run_brand_agent_plan(company_name, business_type, style, progress=gr.Progres
|
|
| 109 |
|
| 110 |
# 3. RESULT
|
| 111 |
# The agent returns all 3 results to the UI.
|
| 112 |
-
return results["logo_url"], results["
|
| 113 |
|
| 114 |
-
# --- 4.
|
| 115 |
-
# (This function is already general, no changes needed)
|
| 116 |
def chat_with_brand_agent(message, history):
|
| 117 |
system_prompt_chat = "You are a friendly and creative branding expert. A user is asking for ideas for their new brand. Give them suggestions, ask clarifying questions, and help them brainstorm."
|
| 118 |
|
|
@@ -146,7 +142,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 146 |
"""
|
| 147 |
)
|
| 148 |
|
| 149 |
-
# *** UPDATED: Added 'business_type_input' and changed default values ***
|
| 150 |
with gr.Row():
|
| 151 |
company_input = gr.Textbox(label="Company Name", value="Aura")
|
| 152 |
business_type_input = gr.Textbox(label="Business Type / Industry", value="Skincare Brand")
|
|
@@ -159,7 +154,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 159 |
with gr.TabItem("Brand Kit Results"):
|
| 160 |
with gr.Row():
|
| 161 |
logo_output = gr.Image(label="Generated Logo (from Nebius)", height=400)
|
| 162 |
-
|
|
|
|
| 163 |
copy_output = gr.Textbox(label="Generated Social Media Copy (from Nebius)", lines=8, interactive=True)
|
| 164 |
|
| 165 |
# --- TAB 2: AGENT LOG ---
|
|
@@ -169,17 +165,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 169 |
# --- TAB 3: CHATBOT ---
|
| 170 |
with gr.TabItem("Brand Chatbot"):
|
| 171 |
chatbot = gr.Chatbot(label="Brand Brainstormer")
|
| 172 |
-
# *** UPDATED: Changed placeholder text to be generic ***
|
| 173 |
chat_msg = gr.Textbox(label="Ask for ideas...", placeholder="e.g., 'What are some good names for my new skincare brand?'")
|
| 174 |
chat_btn = gr.Button("Send")
|
| 175 |
|
| 176 |
# --- Wire up the UI ---
|
| 177 |
|
| 178 |
-
# *** UPDATED:
|
| 179 |
submit_btn.click(
|
| 180 |
fn=run_brand_agent_plan,
|
| 181 |
inputs=[company_input, business_type_input, style_input],
|
| 182 |
-
outputs=[logo_output,
|
| 183 |
)
|
| 184 |
|
| 185 |
# Click handlers for the new chatbot
|
|
|
|
| 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
|
| 13 |
|
|
|
|
| 63 |
|
| 64 |
# --- 3. DEFINE THE AUTONOMOUS AGENT LOGIC ---
|
| 65 |
|
|
|
|
| 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 = {}
|
|
|
|
| 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)...")
|
|
|
|
| 106 |
|
| 107 |
# 3. RESULT
|
| 108 |
# The agent returns all 3 results to the UI.
|
| 109 |
+
return results["logo_url"], results["palette_url"], results["copy_text"], log_message
|
| 110 |
|
| 111 |
+
# --- 4. CHATBOT FUNCTION ---
|
|
|
|
| 112 |
def chat_with_brand_agent(message, history):
|
| 113 |
system_prompt_chat = "You are a friendly and creative branding expert. A user is asking for ideas for their new brand. Give them suggestions, ask clarifying questions, and help them brainstorm."
|
| 114 |
|
|
|
|
| 142 |
"""
|
| 143 |
)
|
| 144 |
|
|
|
|
| 145 |
with gr.Row():
|
| 146 |
company_input = gr.Textbox(label="Company Name", value="Aura")
|
| 147 |
business_type_input = gr.Textbox(label="Business Type / Industry", value="Skincare Brand")
|
|
|
|
| 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 |
|
| 161 |
# --- TAB 2: AGENT LOG ---
|
|
|
|
| 165 |
# --- TAB 3: CHATBOT ---
|
| 166 |
with gr.TabItem("Brand Chatbot"):
|
| 167 |
chatbot = gr.Chatbot(label="Brand Brainstormer")
|
|
|
|
| 168 |
chat_msg = gr.Textbox(label="Ask for ideas...", placeholder="e.g., 'What are some good names for my new skincare brand?'")
|
| 169 |
chat_btn = gr.Button("Send")
|
| 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],
|
| 177 |
+
outputs=[logo_output, color_palette_output, copy_output, log_output]
|
| 178 |
)
|
| 179 |
|
| 180 |
# Click handlers for the new chatbot
|