Update app.py
Browse files1234567891013 unmodified lines242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import streamlit as stimport smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport osfrom datetime import datetimest.set_page_config(page_title="Packaging Box Cost Calculator", layout="wide")def calculate_box_cost(length, width, height, material_type):13 unmodified linesreturn blank_area, costdef send_email(recipient_email, subject, message):"""Sends email with calculation results."""try:# Get email settings from environment variablessender_email = os.getenv("SENDER_EMAIL")smtp_server = os.getenv("SMTP_SERVER", "smtp.gmail.com")smtp_port = int(os.getenv("SMTP_PORT", "587"))smtp_username = os.getenv("SMTP_USERNAME")smtp_password = os.getenv("SMTP_PASSWORD")# Validate email settingsif not all([sender_email, smtp_username, smtp_password]):return False, "Email settings not configured. Please set the required environment variables."# Create email messagemsg = MIMEMultipart()msg['From'] = sender_emailmsg['To'] = recipient_emailmsg['Subject'] = subject# Add message bodymsg.attach(MIMEText(message, 'html'))# Connect to SMTP server and send emailwith smtplib.SMTP(smtp_server, smtp_port) as server:server.starttls()server.login(smtp_username, smtp_password)server.send_message(msg)return True, "Email sent successfully!"except Exception as e:return False, f"Error sending email: {str(e)}"# Streamlit UIst.title("📦 Packaging Box Cost Calculator")st.markdown("### Calculate the cost of packaging boxes based on dimensions and material type.")# Input formwith st.form("box_cost_form"):company_name = st.text_input("Company Name (optional)")# Email fieldsemail_option = st.radio("Email Results", ["No", "Send to a specific email", "Send to configured inbox"])recipient_email = ""if email_option == "Send to a specific email":recipient_email = st.text_input("Recipient Email Address*")# Box dimensionscol1, col2, col3 = st.columns(3)with col1:box_length = st.number_input("Box Length (inches)*", min_value=0.1, value=12.0, step=0.1)with col2:box_width = st.number_input("Box Width (inches)*", min_value=0.1, value=10.0, step=0.1)with col3:box_height = st.number_input("Box Height (inches)*", min_value=0.1, value=6.0, step=0.1)# Material type selectionmaterial_type = st.selectbox("Material Type*",["32 ECT C-Flute", "44 ECT C-Flute", "200# C-Flute"])# Submit buttonsubmit_button = st.form_submit_button("Calculate Box Cost")if not all([box_length, box_width, box_height, material_type]):st.error("Please fill in all required fields marked with *")else:123413 unmodified lines18192021222324252627282930313233343536373839404142434445import streamlit as stst.set_page_config(page_title="Packaging Box Cost Calculator", layout="wide")def calculate_box_cost(length, width, height, material_type):13 unmodified linesreturn blank_area, cost# Streamlit UIst.title("📦 Packaging Box Cost Calculator")st.markdown("### Calculate the cost of packaging boxes based on dimensions and material type.")# Input formcompany_name = st.text_input("Company Name (optional)")# Box dimensionscol1, col2, col3 = st.columns(3)with col1:box_length = st.number_input("Box Length (inches)*", min_value=0.1, value=12.0, step=0.1)with col2:box_width = st.number_input("Box Width (inches)*", min_value=0.1, value=10.0, step=0.1)with col3:box_height = st.number_input("Box Height (inches)*", min_value=0.1, value=6.0, step=0.1)# Material type selectionmaterial_type = st.selectbox("Material Type*",["32 ECT C-Flute", "44 ECT C-Flute", "200# C-Flute"])# Calculate buttonif st.button("Calculate Box Cost"):if not all([box_length, box_width, box_height, material_type]):st.error("Please fill in all required fields marked with *")else:
app.py+17-64