import sys from PIL import Image sys.path.append(".") from utils import ( generate_dummy_data, generate_summary, generate_welcome_message, ) from prompts import CAMPAIGN_DESCR import gradio as gr df = generate_dummy_data() print(df) campaign_names = list(CAMPAIGN_DESCR.keys()) def process_customer_selection(customer_name, campaign_name): customer_data = df[df["Name"] == customer_name].iloc[0] print(customer_data) summary = generate_summary(customer_data) message = generate_welcome_message(summary, campaign_name) # select the appropriate hero image for each campaign if campaign_name == "Summer Clearance": campaign_image = "../img/strung-beads.png" elif campaign_name == "Makehaul": campaign_image = "../img/canvas.png" elif campaign_name == "Lowest Prices Of the Season": campaign_image = "../img/photo-keeper.png" else: print("Invalid Campaign Name") image = Image.open(campaign_image) return summary, message, image def create_gradio_app(): customer_names = df["Name"].tolist() interface = gr.Interface( fn=process_customer_selection, inputs=[ gr.Dropdown(choices=customer_names, label="Select a Customer"), gr.Dropdown(choices=campaign_names, label="Select a Campaign"), ], outputs=[ gr.Textbox(label="Customer Summary [Input]"), gr.Textbox(label="Personalized Welcome Message [Output]"), gr.Image(label="Campaign Hero Product"), ], title="Personalized Email Content Generator", ) interface.launch(share=True) # Run the Gradio app create_gradio_app()