Boardroom / app.py
ianiket23's picture
Update app.py
cac3e42 verified
import gradio as gr
import asyncio
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_google_genai import ChatGoogleGenerativeAI
import os
import json
creds_json = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
# Write it to a temporary file
with open("cred.json", "w") as f:
f.write(creds_json)
# Point the environment variable to it
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "cred.json"
GKEY = os.getenv("GAPI_KEY")
llm = ChatGoogleGenerativeAI(
model = "gemini-1.5-flash",
GOOGLE_API_KEY = GKEY,
)
PROMPTS = {
"ceo": "You are a greedy CEO. Your main goal is maximizing company profit while keeping costs low. Given this product: {input}, what is the best marketing strategy to achieve that?",
"marketing_intern": "You are a Marketing Intern. Your ideas are sometimes genius, sometimes dumb, and sometimes cliché. Given this product: {input}, suggest creative marketing ideas.",
"marketing_strategist": "You are a Marketing Strategist. Given this product: {input} and the ideas from the Marketing Intern, analyze the pros and cons.",
}
def run_agent(role, input_text):
"""Run a specific agent based on its role."""
messages = [
SystemMessage(content=PROMPTS[role].format(input=input_text)),
HumanMessage(content=input_text),
]
response = llm(messages)
return response.content
async def marketing_conversation(product_description):
"""Run a timed multi-agent marketing conversation."""
last_response = product_description
conversation = []
ceo_output = run_agent("ceo", last_response)
intern_output = run_agent("marketing_intern", ceo_output)
strategist_output = run_agent("marketing_strategist", intern_output)
response = (
f"\n 🤑 *CEO:* {ceo_output}\n"
f"\n 🎨 *Marketing Intern:* {intern_output}\n"
f"\n 📊 *Marketing Strategist:* {strategist_output}\n"
"---"
)
conversation.append(response)
last_response = strategist_output
return "\n".join(conversation)
def start_conversation(product_description):
return asyncio.run(marketing_conversation(product_description))
# Create Gradio Interface
gr.Interface(
fn=start_conversation,
inputs=gr.Textbox(label="Enter Product Description"),
outputs=gr.Textbox(label="Marketing Discussion"),
title="Marketing Strategy Discussion",
description="A CEO, Marketing Intern, and Marketing Strategist discuss how to market a product.",
).launch(share=True)