CCTVQuotation / src /streamlit_app.py
WasifAKhan's picture
Update src/streamlit_app.py
149ed7a verified
import streamlit as st
import pandas as pd
import pdfplumber
import os
# -------------------------------------------------------
# PDF Extraction Function
# -------------------------------------------------------
def extract_pdf_table(uploaded_file):
rows = []
with pdfplumber.open(uploaded_file) as pdf:
for page in pdf.pages:
table = page.extract_table()
if table:
rows.extend(table)
if not rows:
return None, "No table detected in this PDF."
columns = [f"Column_{i+1}" for i in range(len(rows[0]))]
df = pd.DataFrame(rows[1:], columns=columns)
return df, "Pricelist extracted successfully!"
# -------------------------------------------------------
# APP TITLE
# -------------------------------------------------------
st.title("πŸ“Έ CCTV Pricelist & Quotation Generator")
st.write("### 1️⃣ Select what you want to generate:")
# -------------------------------------------------------
# MAIN DROPDOWN: SERVICES OR PRODUCTS
# -------------------------------------------------------
choice = st.selectbox(
"Choose Option",
["Select Option", "Products", "Services"]
)
st.write("---")
# -------------------------------------------------------
# SERVICES UI SECTION
# -------------------------------------------------------
if choice == "Services":
st.header("πŸ“ Service Quotation")
service_name = st.text_input("Service Name")
service_desc = st.text_area("Service Description")
service_cost = st.number_input("Service Price", min_value=0.0)
area_value = st.text_input("Approx. Area Covered")
area_unit = st.radio("Area Unit", ["Marla", "Sq. Yd"], horizontal=True)
if st.button("Generate Service Quotation"):
st.markdown(f"""
# πŸ“„ Service Quotation
### β–Ά Service Details
- **Name:** {service_name}
- **Description:** {service_desc}
- **Cost:** {service_cost}
### β–Ά Site Details
- **Area:** {area_value} {area_unit}
""")
# -------------------------------------------------------
# PRODUCTS UI SECTION
# -------------------------------------------------------
elif choice == "Products":
st.subheader("πŸ“„ Pricelist Loading")
# Use your exact file name
PDF_PATH = "Pollo Price List 11.07.25.pdf"
pricelist_df = None
# -------------------------------------------------------
# AUTO LOAD DEFAULT PDF IF PRESENT
# -------------------------------------------------------
if os.path.exists(PDF_PATH):
st.success(f"Loaded pricelist: {PDF_PATH}")
with open(PDF_PATH, "rb") as file:
pricelist_df, msg = extract_pdf_table(file)
st.info(msg)
if pricelist_df is not None:
st.dataframe(pricelist_df)
else:
st.warning("Default pricelist not found. Upload your own below.")
# -------------------------------------------------------
# USER PDF UPLOAD
# -------------------------------------------------------
uploaded_pdf = st.file_uploader("Upload PDF Pricelist", type=["pdf"])
if uploaded_pdf:
pricelist_df, msg = extract_pdf_table(uploaded_pdf)
st.success(msg)
if pricelist_df is not None:
st.dataframe(pricelist_df)
st.write("---")
# -------------------------------------------------------
# PRODUCT SELECTION
# -------------------------------------------------------
st.header("πŸ›’ Product Selection")
product_category = st.selectbox(
"Select Product Category",
["Camera", "Video Recorder", "POE Switch", "Cables", "Accessories"]
)
# ------------------- CAMERA UI --------------------
if product_category == "Camera":
camera_type = st.selectbox("Camera Type", ["Analog Camera", "Digital Camera"])
placement = st.selectbox("Placement", ["Outdoor (Bullet)", "Indoor (Dome)"])
resolution = st.selectbox("Resolution", ["1MP", "2MP", "4MP", "5MP", "8MP", "4K"])
ir_range = st.multiselect("Infrared Range", ["20m", "30m", "50m", "150m", "300m", "500m"])
night_vision = st.selectbox("Night Vision", ["Yes", "No"])
feature = st.selectbox("Additional Feature", ["None", "Battery", "4G", "Solar", "AI Based"])
else:
camera_type = "N/A"
placement = "N/A"
resolution = "N/A"
ir_range = []
night_vision = "N/A"
feature = "None"
st.write("---")
# -------------------------------------------------------
# PRODUCT QUOTATION SECTION
# -------------------------------------------------------
st.header("πŸ“¦ Product System Quotation")
system_type = st.selectbox("System Type", ["Analog System", "Digital System"])
area_value = st.text_input("Approx. Area Covered")
area_unit = st.radio("Area Unit", ["Marla", "Sq. Yd"], horizontal=True)
if st.button("Generate Product Quotation"):
ir_display = ", ".join(ir_range) if ir_range else "None"
st.markdown(f"""
# πŸ“„ Product Quotation
### β–Ά Product Details
- **Category:** {product_category}
- **Camera Type:** {camera_type}
- **Placement:** {placement}
- **Resolution:** {resolution}
- **Infrared:** {ir_display}
- **Night Vision:** {night_vision}
- **Feature:** {feature}
### β–Ά System Details
- **System Type:** {system_type}
- **Coverage Area:** {area_value} {area_unit}
""")
if pricelist_df is not None:
st.write("### β–Ά Pricelist Preview")
st.dataframe(pricelist_df.head())
else:
st.info("No pricelist available.")
else:
st.info("Please choose **Products** or **Services** to begin.")