Spaces:
Sleeping
Sleeping
File size: 5,768 Bytes
bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a bf1aafa 149ed7a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
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.") |