Spaces:
Sleeping
Sleeping
File size: 3,665 Bytes
93e917d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
import pandas as pd
from openai import OpenAI
from dotenv import load_dotenv
import os
import sys
sys.path.append(".")
from prompts import SYSTEM_PROMPT, PERSONA_DESCR, CAMPAIGN_DESCR
load_dotenv("../.env")
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def generate_summary(customer_data):
customer_value = "high" if customer_data["Revenue"] >= 250 else "low"
customer_recency = "recent" if customer_data["Recency"] <= 60 else "not recent"
seg = customer_data["Segment"]
if seg == "Artist":
cust_seg_descr = PERSONA_DESCR["Artist"]
elif seg == "Creator":
cust_seg_descr = PERSONA_DESCR["Creator"]
elif seg == "Curator":
cust_seg_descr = PERSONA_DESCR["Curator"]
elif seg == "Seeker":
cust_seg_descr = PERSONA_DESCR["Seeker"]
else:
print("Invalid Segment")
summary = (
f"This is a {customer_value} value customer who has spent a total of {customer_data['Revenue']} dollars. "
f"Their most recent transaction was {customer_data['Recency']} days ago, which makes him/her a {customer_recency} customer. "
f"The latest product they purchased was {customer_data['LatestProduct']}. "
f"Their favorite department is {customer_data['FavoriteDepartment']}. "
f"{cust_seg_descr} ({seg})"
)
return summary
def generate_welcome_message(summary, campaign_name):
campaign_description = "The personalize message should align with the marketing campaign described below: "
if campaign_name == "Summer Clearance":
campaign_description += CAMPAIGN_DESCR["Summer Clearance"] + "\n"
elif campaign_name == "Makehaul":
campaign_description += CAMPAIGN_DESCR["Makehaul"] + "\n"
elif campaign_name == "Lowest Prices Of the Season":
campaign_description += CAMPAIGN_DESCR["Lowest Prices Of the Season"] + "\n"
else:
print("Invalid Campaign Name")
summary += f"{campaign_description}"
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": summary},
],
)
message = response.choices[0].message.content
return message
def generate_dummy_data():
data = {
"Name": [
"Alice",
"Bob",
"Charlie",
"David",
"Eva",
"Frank",
"Grace",
"Henry",
"Ivy",
"John",
],
"Recency": [20, 50, 100, 10, 120, 70, 30, 150, 60, 40],
"Revenue": [200, 350, 150, 400, 100, 250, 300, 80, 330, 280],
"LatestProduct": [
"All Strung Beads",
"Permanent and Removable Vinyl",
"Creatology Baskets",
"Kids Storage",
"Lap Trays",
"Lemax Spooky Town Collection",
"Frames & Shadow Boxes",
"ALL Fall Stems",
"Folding Step Stool",
"Mini Sticker Printer",
],
"FavoriteDepartment": [
"KIDS ART & EDUCATION",
"HOBBY CRAFTS",
"BAKEWARE",
"FRAMES",
"PAPERCRAFTING",
"STORAGE",
"HOBBY CRAFTS",
"FLORAL ACCESSORIES",
"HOBBY CRAFTS",
"KIDS ART & EDUCATION",
],
"Segment": [
"Artist",
"Creator",
"Curator",
"Artist",
"Seeker",
"Curator",
"Artist",
"Seeker",
"Creator",
"Curator",
],
}
return pd.DataFrame(data)
|