write a simple app
To upload files, please first save the app
import streamlit as st
import pandas as pd
def main():
st.title("Order Management System")
# Initialize session state for order list if not exists
if "orders" not in st.session_state:
st.session_state.orders = []
col_input, col_table = st.columns([1, 2])
with col_input:
st.write("### Add Product")
product_name = st.text_input("Product Name")
product_price = st.number_input("Price", min_value=0.0, format="%.2f")
product_priority = st.selectbox("Priority", ["high", "medium", "low"])
if st.button("Add Product"):
if not product_name:
st.error("Please provide name")
elif product_price <= 0:
st.error("Price should be positive number")
else:
st.session_state.orders.append({"Product": product_name, "Price": product_price, "Priority": product_priority})
with col_table:
st.write("### Total Price: $", f"{sum([item['Price'] for item in st.session_state.orders]):.2f}")
st.write("### Order Summary")
if st.session_state.orders:
priority_order = {"high": 1, "medium": 2, "low": 3}
df = pd.DataFrame(st.session_state.orders)
df = df.sort_values(by="Priority", key=lambda x: x.map(priority_order))
for i, row in df.iterrows():
col1, col2, col3, col4 = st.columns([3, 1, 1, 1])
col1.write(row["Product"])
col2.write(f"${row['Price']:.2f}")
col3.write(row["Priority"].capitalize())
if col4.button("❌", key=f"del_{i}"):
st.session_state.orders.pop(i)
st.rerun()
if __name__ == "__main__":
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?