WasifAKhan commited on
Commit
149ed7a
·
verified ·
1 Parent(s): 5f405c8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +130 -88
src/streamlit_app.py CHANGED
@@ -7,7 +7,6 @@ import os
7
  # PDF Extraction Function
8
  # -------------------------------------------------------
9
  def extract_pdf_table(uploaded_file):
10
- """Extract table data from PDF and convert into DataFrame."""
11
  rows = []
12
  with pdfplumber.open(uploaded_file) as pdf:
13
  for page in pdf.pages:
@@ -16,118 +15,161 @@ def extract_pdf_table(uploaded_file):
16
  rows.extend(table)
17
 
18
  if not rows:
19
- return None, "No table detected in PDF."
20
 
21
- num_cols = len(rows[0])
22
- auto_columns = [f"Column_{i+1}" for i in range(num_cols)]
 
23
 
24
- df = pd.DataFrame(rows[1:], columns=auto_columns)
25
- return df, "PDF extracted successfully!"
26
 
27
  # -------------------------------------------------------
28
- # UI START
29
  # -------------------------------------------------------
30
- st.title("📸 Camera Pricelist & Quotation System")
 
 
31
 
32
  # -------------------------------------------------------
33
- # Load Default PDF from Repo (Optional)
34
  # -------------------------------------------------------
35
- st.subheader("1️⃣ Pricelist Loading")
36
-
37
- PDF_PATH = "Pollo Price List 11.07.25.pdf" # rename your file to this
38
- pricelist_df = None
39
 
40
- if os.path.exists(PDF_PATH):
41
- st.success(f"Loaded pricelist from: {PDF_PATH}")
42
- with open(PDF_PATH, "rb") as file:
43
- pricelist_df, msg = extract_pdf_table(file)
44
- st.info(msg)
45
 
46
- if pricelist_df is not None:
47
- st.dataframe(pricelist_df)
48
- else:
49
- st.warning("No pricelist file found. Upload below instead.")
50
 
51
  # -------------------------------------------------------
52
- # Upload PDF from User
53
  # -------------------------------------------------------
54
- uploaded_pdf = st.file_uploader("Upload your PDF pricelist", type=["pdf"])
55
 
56
- if uploaded_pdf:
57
- pricelist_df, msg = extract_pdf_table(uploaded_pdf)
58
- st.success(msg)
59
- if pricelist_df is not None:
60
- st.dataframe(pricelist_df)
61
 
62
- st.write("---")
 
 
63
 
64
- # -------------------------------------------------------
65
- # Product Selection UI
66
- # -------------------------------------------------------
67
- st.header("2️⃣ Product / Service Selection")
68
 
69
- service_or_product = st.selectbox("Select Type", ["Services", "Products"])
 
 
70
 
71
- product_category = st.selectbox(
72
- "Select Product Category",
73
- ["Camera", "Video Recorder", "POE Switch", "Cables", "Accessories"]
74
- )
75
 
76
- if product_category == "Camera":
77
- camera_type = st.selectbox("Camera Type", ["Analog Camera", "Digital Camera"])
78
- placement_type = st.selectbox("Placement Type", ["Outdoor (Bullet)", "Indoor (Dome)"])
79
- resolution = st.selectbox("Camera Resolution", ["1MP", "2MP", "4MP", "5MP", "8MP", "4K"])
80
- ir_range = st.multiselect("Infrared Range", ["20m", "30m", "50m", "150m", "300m", "500m"])
81
- night_vision = st.selectbox("Night Vision / Color Camera", ["Yes", "No"])
82
- feature = st.selectbox("Additional Feature", ["None", "Battery", "4G", "Solar", "Heat Sensing", "AI Based"])
83
- else:
84
- camera_type = "N/A"
85
- placement_type = "N/A"
86
- resolution = "N/A"
87
- ir_range = []
88
- night_vision = "N/A"
89
- feature = "None"
90
 
91
- st.write("---")
92
 
93
  # -------------------------------------------------------
94
- # Quotation Section
95
  # -------------------------------------------------------
96
- st.header("3️⃣ Quotation Section")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
- quotation_type = st.selectbox("Quotation System Type", ["Analog System", "Digital System"])
 
 
 
 
 
 
99
 
100
- area_value = st.text_input("Approx. Covered Area")
101
- area_unit = st.radio("Area Unit", ["Marla", "Sq. Yd"], horizontal=True)
102
 
103
- # -------------------------------------------------------
104
- # Quotation Generator
105
- # -------------------------------------------------------
106
- def generate_quote():
107
- result = f"""
108
- # 📄 Quotation Summary
109
- ### ▶ Selection Details
110
- - **Type:** {service_or_product}
111
- - **Category:** {product_category}
112
- - **Camera Type:** {camera_type}
113
- - **Placement:** {placement_type}
114
- - **Resolution:** {resolution}
115
- - **IR Range:** {", ".join(ir_range) if ir_range else "None"}
116
- - **Night Vision:** {night_vision}
117
- - **Feature:** {feature}
118
- ---
119
- ### ▶ System
120
- - **System Type:** {quotation_type}
121
- - **Approx. Area:** {area_value} {area_unit}
122
- ---
123
- """
124
- if pricelist_df is not None:
125
- result += "### ▶ Pricelist Preview\n"
126
- result += pricelist_df.head().to_markdown(index=False)
127
- else:
128
- result += "_No pricelist loaded._"
129
 
130
- return result
 
131
 
132
- if st.button("Generate Quotation"):
133
- st.markdown(generate_quote())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # PDF Extraction Function
8
  # -------------------------------------------------------
9
  def extract_pdf_table(uploaded_file):
 
10
  rows = []
11
  with pdfplumber.open(uploaded_file) as pdf:
12
  for page in pdf.pages:
 
15
  rows.extend(table)
16
 
17
  if not rows:
18
+ return None, "No table detected in this PDF."
19
 
20
+ columns = [f"Column_{i+1}" for i in range(len(rows[0]))]
21
+ df = pd.DataFrame(rows[1:], columns=columns)
22
+ return df, "Pricelist extracted successfully!"
23
 
 
 
24
 
25
  # -------------------------------------------------------
26
+ # APP TITLE
27
  # -------------------------------------------------------
28
+ st.title("📸 CCTV Pricelist & Quotation Generator")
29
+
30
+ st.write("### 1️⃣ Select what you want to generate:")
31
 
32
  # -------------------------------------------------------
33
+ # MAIN DROPDOWN: SERVICES OR PRODUCTS
34
  # -------------------------------------------------------
35
+ choice = st.selectbox(
36
+ "Choose Option",
37
+ ["Select Option", "Products", "Services"]
38
+ )
39
 
40
+ st.write("---")
 
 
 
 
41
 
 
 
 
 
42
 
43
  # -------------------------------------------------------
44
+ # SERVICES UI SECTION
45
  # -------------------------------------------------------
46
+ if choice == "Services":
47
 
48
+ st.header("📝 Service Quotation")
 
 
 
 
49
 
50
+ service_name = st.text_input("Service Name")
51
+ service_desc = st.text_area("Service Description")
52
+ service_cost = st.number_input("Service Price", min_value=0.0)
53
 
54
+ area_value = st.text_input("Approx. Area Covered")
55
+ area_unit = st.radio("Area Unit", ["Marla", "Sq. Yd"], horizontal=True)
 
 
56
 
57
+ if st.button("Generate Service Quotation"):
58
+ st.markdown(f"""
59
+ # 📄 Service Quotation
60
 
61
+ ### Service Details
62
+ - **Name:** {service_name}
63
+ - **Description:** {service_desc}
64
+ - **Cost:** {service_cost}
65
 
66
+ ### Site Details
67
+ - **Area:** {area_value} {area_unit}
68
+ """)
 
 
 
 
 
 
 
 
 
 
 
69
 
 
70
 
71
  # -------------------------------------------------------
72
+ # PRODUCTS UI SECTION
73
  # -------------------------------------------------------
74
+ elif choice == "Products":
75
+
76
+ st.subheader("📄 Pricelist Loading")
77
+
78
+ # Use your exact file name
79
+ PDF_PATH = "Pollo Price List 11.07.25.pdf"
80
+ pricelist_df = None
81
+
82
+ # -------------------------------------------------------
83
+ # AUTO LOAD DEFAULT PDF IF PRESENT
84
+ # -------------------------------------------------------
85
+ if os.path.exists(PDF_PATH):
86
+ st.success(f"Loaded pricelist: {PDF_PATH}")
87
+ with open(PDF_PATH, "rb") as file:
88
+ pricelist_df, msg = extract_pdf_table(file)
89
+ st.info(msg)
90
+ if pricelist_df is not None:
91
+ st.dataframe(pricelist_df)
92
+ else:
93
+ st.warning("Default pricelist not found. Upload your own below.")
94
+
95
+ # -------------------------------------------------------
96
+ # USER PDF UPLOAD
97
+ # -------------------------------------------------------
98
+ uploaded_pdf = st.file_uploader("Upload PDF Pricelist", type=["pdf"])
99
+
100
+ if uploaded_pdf:
101
+ pricelist_df, msg = extract_pdf_table(uploaded_pdf)
102
+ st.success(msg)
103
+ if pricelist_df is not None:
104
+ st.dataframe(pricelist_df)
105
+
106
+ st.write("---")
107
+
108
+ # -------------------------------------------------------
109
+ # PRODUCT SELECTION
110
+ # -------------------------------------------------------
111
+ st.header("🛒 Product Selection")
112
+
113
+ product_category = st.selectbox(
114
+ "Select Product Category",
115
+ ["Camera", "Video Recorder", "POE Switch", "Cables", "Accessories"]
116
+ )
117
+
118
+ # ------------------- CAMERA UI --------------------
119
+ if product_category == "Camera":
120
+ camera_type = st.selectbox("Camera Type", ["Analog Camera", "Digital Camera"])
121
+ placement = st.selectbox("Placement", ["Outdoor (Bullet)", "Indoor (Dome)"])
122
+ resolution = st.selectbox("Resolution", ["1MP", "2MP", "4MP", "5MP", "8MP", "4K"])
123
+ ir_range = st.multiselect("Infrared Range", ["20m", "30m", "50m", "150m", "300m", "500m"])
124
+ night_vision = st.selectbox("Night Vision", ["Yes", "No"])
125
+ feature = st.selectbox("Additional Feature", ["None", "Battery", "4G", "Solar", "AI Based"])
126
 
127
+ else:
128
+ camera_type = "N/A"
129
+ placement = "N/A"
130
+ resolution = "N/A"
131
+ ir_range = []
132
+ night_vision = "N/A"
133
+ feature = "None"
134
 
135
+ st.write("---")
 
136
 
137
+ # -------------------------------------------------------
138
+ # PRODUCT QUOTATION SECTION
139
+ # -------------------------------------------------------
140
+ st.header("📦 Product System Quotation")
141
+
142
+ system_type = st.selectbox("System Type", ["Analog System", "Digital System"])
143
+
144
+ area_value = st.text_input("Approx. Area Covered")
145
+ area_unit = st.radio("Area Unit", ["Marla", "Sq. Yd"], horizontal=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
+ if st.button("Generate Product Quotation"):
148
+ ir_display = ", ".join(ir_range) if ir_range else "None"
149
 
150
+ st.markdown(f"""
151
+ # 📄 Product Quotation
152
+
153
+ ### ▶ Product Details
154
+ - **Category:** {product_category}
155
+ - **Camera Type:** {camera_type}
156
+ - **Placement:** {placement}
157
+ - **Resolution:** {resolution}
158
+ - **Infrared:** {ir_display}
159
+ - **Night Vision:** {night_vision}
160
+ - **Feature:** {feature}
161
+
162
+ ### ▶ System Details
163
+ - **System Type:** {system_type}
164
+ - **Coverage Area:** {area_value} {area_unit}
165
+
166
+ """)
167
+
168
+ if pricelist_df is not None:
169
+ st.write("### ▶ Pricelist Preview")
170
+ st.dataframe(pricelist_df.head())
171
+ else:
172
+ st.info("No pricelist available.")
173
+
174
+ else:
175
+ st.info("Please choose **Products** or **Services** to begin.")