copilot-test / app.py
MariamBM's picture
Upload 3 files
8db7b5b verified
import streamlit as st
import json
from copilot import build_global_graph
# Build global graph once
global_app = build_global_graph()
st.set_page_config(
page_title="AI Marketing Copilot",
page_icon="πŸ€–",
layout="centered",
initial_sidebar_state="collapsed",
)
# --- HEADER ---
st.image("logo.png", width=150) # <- replace with your project logo
st.title("AI Marketing Copilot")
st.markdown("Your intelligent assistant for **post generation & scheduling** ✨")
st.divider()
# --- PRODUCT INPUT FORM ---
st.subheader("πŸ›’ Product Information")
with st.form("product_form"):
# Required fields
product_id = st.text_input("Product ID *", "PEN0001")
product_name = st.text_input("Product Name *", "EcoWave Stainless Steel Insulated Bottle")
product_category = st.text_input("Category *", "Drinkware")
product_description = st.text_area(
"Description *",
"Durable, eco-friendly insulated bottle for everyday use."
)
# Optional fields in expander
with st.expander("πŸ”§ Advanced fields (optional)"):
product_type = st.text_input("Type", "Bottle")
product_price = st.text_input("Price", "24.99")
product_currency = st.text_input("Currency", "USD")
product_stock = st.number_input("Stock Quantity", value=42, step=1)
product_sku = st.text_input("SKU", "ECO-SS-500")
product_options = st.text_area(
"Options (JSON list)",
'[{"name": "Size", "value": "500ml"}]'
)
product_on_sale = st.checkbox("On Sale?", value=True)
# Platform selection
platform = st.selectbox("πŸ“± Target Platform *", ["Instagram", "Twitter", "Facebook", "LinkedIn", "TikTok"])
submitted = st.form_submit_button("πŸš€ Generate & Schedule")
if submitted:
try:
# Parse options safely
try:
options = json.loads(product_options)
if not isinstance(options, list):
options = []
except Exception:
options = []
# Build product dict
product = {
"id": product_id,
"name": product_name,
"category": product_category,
"type": product_type,
"price": product_price,
"currency": product_currency,
"description": product_description,
"stock_quantity": product_stock,
"sku": product_sku,
"images": [],
"options": options,
"on_sale": product_on_sale,
}
# Templates placeholder (normally loaded from DB)
templates = []
with st.spinner("πŸ€– Generating post and scheduling..."):
state = {
"product": product,
"platform": platform,
"templates": templates,
}
result = global_app.invoke(state)
st.success("βœ… Post Generated & Scheduled!")
# --- MAIN OUTPUT CARD ---
st.subheader("πŸ“’ Final Post")
final_post = result.get("final_post_struct", {}).get("post_text", "⚠️ No post generated")
st.markdown(
f"""
<div style="padding:1.2em; border-radius:10px; background-color:#F0F9FF; border:1px solid #90CAF9;">
<p style="font-size:1.1em;">{final_post}</p>
</div>
""",
unsafe_allow_html=True
)
# Scheduled time
st.subheader("⏰ Scheduled Time")
st.info(result.get("scheduled_post", {}).get("scheduled_time", "Not scheduled"))
# --- EXTRA: Ranked Templates ---
if st.button("πŸ“Š Show Template Rankings"):
ranked = result.get("ranked_templates", [])
if ranked:
st.markdown("### Template Scores")
st.dataframe(ranked)
else:
st.warning("No ranked templates available.")
except Exception as e:
st.error(f"An error occurred: {e}")
# --- FOOTER ---
st.divider()
st.caption("⚑ Powered by LangGraph + Hugging Face Spaces")