Ninad077 commited on
Commit
cad9b32
·
verified ·
1 Parent(s): bee5ce2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -25
app.py CHANGED
@@ -3,6 +3,8 @@ import pandas as pd
3
  from datetime import datetime
4
  import os
5
  import configparser # For activating the config
 
 
6
 
7
  global_user_data = [] # For appending user_data
8
 
@@ -22,6 +24,11 @@ def save_user_data(user_data):
22
  st.session_state.data.append(user_data)
23
 
24
 
 
 
 
 
 
25
  # Function to generate PM_id
26
  def generate_rule_id(user_data):
27
  company_id = user_data.get('Company ID', '')
@@ -150,6 +157,51 @@ st.set_page_config(
150
  )
151
 
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  # Section 1: Plan Info
154
  st.sidebar.image('Fynd_logo2.png', width=300)
155
  st.sidebar.title(":blue[Plan maker]")
@@ -284,15 +336,17 @@ if bundle_by == "Feature specific":
284
  st.write("Enter values for Slab based fee structure:")
285
 
286
  # Initialize an empty list to store data rows
 
287
  global_data_rows = []
288
 
289
  def add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold):
290
- # Convert values to int if not None
291
  max_value = int(max_value.strip()) if max_value else None
292
  user_input = int(user_input.strip()) if user_input else None
293
  Usage = int(Usage.strip()) if Usage else None
294
  Capping_or_Minimum_Guarantee = int(Capping_or_Minimum_Guarantee.strip()) if Capping_or_Minimum_Guarantee else None
295
-
 
296
  new_row = {
297
  "Slab": slab,
298
  "Max_value": max_value,
@@ -301,46 +355,46 @@ if bundle_by == "Feature specific":
301
  "Capping/Min_Guarantee_value": Capping_or_Minimum_Guarantee,
302
  "Threshold": threshold
303
  }
304
-
305
- # Append new_row to global list of rows
306
  global_data_rows.append(new_row)
 
307
 
308
- # Streamlit UI code
 
 
 
 
 
 
309
  def main():
310
  st.title("Slab Data Management")
311
-
312
- # Inputs for adding data
313
- # Input fields for user data
314
  col1, col2 = st.columns([2, 2])
315
-
316
  with col1:
317
  slab = st.selectbox("Slab:", [1, 2, 3], key="slab_select")
318
- with col2:
319
- max_value = st.text_input("Max value:", key="max_value_input")
320
- with col1:
321
  user_input = st.text_input("Commercial Value:", key="user_input")
322
- with col2:
323
- Usage = st.text_input("Usage:", key="Usage_input")
324
- with col1:
325
  Capping_or_Minimum_Guarantee = st.text_input("Capping/Min_Guarantee:", key="Capping_or_Minimum_Guarantee_input")
326
  with col2:
 
 
327
  threshold = st.text_input("Threshold:", key="threshold_input")
328
-
329
- # Button to add data
330
  if st.button("Add Data", key="add_data_button"):
331
- add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold)
332
- st.success(f"Data for Slab '{slab}' added successfully!")
 
 
 
333
 
334
- # Display all rows in a table
335
- if global_data_rows:
336
- st.subheader("Added Slabs")
337
- for i, row in enumerate(global_data_rows):
338
- st.write(f"Entry {i + 1}:")
339
- st.table([row])
340
 
341
  if __name__ == "__main__":
342
  main()
343
 
 
344
  elif selected_fee_nature in ["Fixed %", "Flat currency"]:
345
  user_input = st.number_input("Commercial value:", min_value=0.0, help="Enter a valid number")
346
 
 
3
  from datetime import datetime
4
  import os
5
  import configparser # For activating the config
6
+ from PIL import Image, ImageFilter
7
+ import io
8
 
9
  global_user_data = [] # For appending user_data
10
 
 
24
  st.session_state.data.append(user_data)
25
 
26
 
27
+ # Function to save Slab data
28
+ def save_slab_data(new_row):
29
+ st.session_state.data.append(new_row)
30
+
31
+
32
  # Function to generate PM_id
33
  def generate_rule_id(user_data):
34
  company_id = user_data.get('Company ID', '')
 
157
  )
158
 
159
 
160
+ # Background image
161
+
162
+ def set_bg_hack_url(image_url, width='10%', height='10vh'):
163
+ '''
164
+ A function to set a background image from a URL with custom dimensions and shift it to the right.
165
+ Parameters
166
+ ----------
167
+ image_url : str
168
+ The URL of the image.
169
+ width : str, optional
170
+ Width of the background image. Defaults to '30%'.
171
+ height : str, optional
172
+ Height of the background image. Defaults to '20vh' (20% of viewport height).
173
+ '''
174
+ st.markdown(
175
+ f"""
176
+ <style>
177
+ :root {{
178
+ --bg-width: {width};
179
+ --bg-height: {height};
180
+ }}
181
+ .stApp {{
182
+ background: url("{image_url}");
183
+ background-size: cover;
184
+ background-position: center; /* Shifts the image to the right */
185
+ width: var(--bg-width);
186
+ height: var(--bg-height);
187
+ position: fixed;
188
+ top: 0;
189
+ left: 0;
190
+ z-index: -1;
191
+ }}
192
+ </style>
193
+ """,
194
+ unsafe_allow_html=True
195
+ )
196
+
197
+ # Example usage with a demo URL and custom dimensions
198
+ demo_image_url = "https://cdn.pixelbin.io/v2/falling-surf-7c8bb8/fyprod/wrkr/platform/pictures/free-logo/original/oanADZQ9B-platform-meta-image.jpeg"
199
+ set_bg_hack_url(demo_image_url, width='100%', height='100vh')
200
+
201
+
202
+
203
+
204
+
205
  # Section 1: Plan Info
206
  st.sidebar.image('Fynd_logo2.png', width=300)
207
  st.sidebar.title(":blue[Plan maker]")
 
336
  st.write("Enter values for Slab based fee structure:")
337
 
338
  # Initialize an empty list to store data rows
339
+ # Global list to store slab data rows
340
  global_data_rows = []
341
 
342
  def add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold):
343
+ # Convert values to int if not None
344
  max_value = int(max_value.strip()) if max_value else None
345
  user_input = int(user_input.strip()) if user_input else None
346
  Usage = int(Usage.strip()) if Usage else None
347
  Capping_or_Minimum_Guarantee = int(Capping_or_Minimum_Guarantee.strip()) if Capping_or_Minimum_Guarantee else None
348
+
349
+ # Create a new row dictionary
350
  new_row = {
351
  "Slab": slab,
352
  "Max_value": max_value,
 
355
  "Capping/Min_Guarantee_value": Capping_or_Minimum_Guarantee,
356
  "Threshold": threshold
357
  }
358
+
359
+ # Append new_row to global list of rows
360
  global_data_rows.append(new_row)
361
+ save_slab_data(new_row)
362
 
363
+ # Display all rows in a table
364
+ st.subheader("Added Slabs")
365
+ for i, row in enumerate(global_data_rows):
366
+ st.write(f"Entry {i + 1}:")
367
+ st.table([row])
368
+
369
+ # Streamlit UI code
370
  def main():
371
  st.title("Slab Data Management")
372
+
373
+ # Inputs for adding data
 
374
  col1, col2 = st.columns([2, 2])
 
375
  with col1:
376
  slab = st.selectbox("Slab:", [1, 2, 3], key="slab_select")
 
 
 
377
  user_input = st.text_input("Commercial Value:", key="user_input")
 
 
 
378
  Capping_or_Minimum_Guarantee = st.text_input("Capping/Min_Guarantee:", key="Capping_or_Minimum_Guarantee_input")
379
  with col2:
380
+ max_value = st.text_input("Max value:", key="max_value_input")
381
+ Usage = st.text_input("Usage:", key="Usage_input")
382
  threshold = st.text_input("Threshold:", key="threshold_input")
383
+
384
+ # Button to add data
385
  if st.button("Add Data", key="add_data_button"):
386
+ if not (slab and user_input and Capping_or_Minimum_Guarantee):
387
+ st.warning("Please fill in all required fields.")
388
+ else:
389
+ add_data(slab, max_value, user_input, Usage, Capping_or_Minimum_Guarantee, threshold)
390
+ st.success(f"Data for Slab '{slab}' added successfully!")
391
 
392
+
 
 
 
 
 
393
 
394
  if __name__ == "__main__":
395
  main()
396
 
397
+
398
  elif selected_fee_nature in ["Fixed %", "Flat currency"]:
399
  user_input = st.number_input("Commercial value:", min_value=0.0, help="Enter a valid number")
400