XPMaster commited on
Commit
36c1546
·
1 Parent(s): a766add

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -10,7 +10,7 @@ import datetime
10
  g_mapping = None
11
 
12
  elems = """
13
- #red-button {
14
  /* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#f6e6b4+0,ed9017+100;Yellow+3D+%231 */
15
  background: #f6e6b4; /* Old browsers */
16
  background: -moz-linear-gradient(top, #f6e6b4 0%, #ed9017 100%); /* FF3.6-15 */
@@ -365,14 +365,15 @@ def valid(text):
365
  match = re.search(pattern, text, flags=re.IGNORECASE)
366
  return bool(match)
367
 
368
- def op_outcome(name,msg,state):
369
  name = os.path.basename(name)
370
- return name+msg+state
371
 
372
  def process(files,button):
373
- fail = ' ❌'
374
- passe = ' ✔️'
375
- warn = ' ️'
 
376
  status = []
377
  cleaned_names = []
378
  if files is None:
@@ -402,17 +403,17 @@ def process(files,button):
402
  if "summ" in name:
403
  df,columns = filter_premiums(df)
404
  if columns == None:
405
- print(name,'has no LOB column\n')
406
  print("--"*50)
407
- status.append(op_outcome(name,' has no LOB column',fail))
408
  continue
409
  altnames = get_alts('summ')
410
  else:
411
  df,columns = filter_claims(df)
412
  if columns == None:
413
- print(name,'has no LOB column\n')
414
  print("--"*50)
415
- status.append(op_outcome(name,' has no LOB column',fail))
416
  continue
417
  altnames = get_alts('claim')
418
 
@@ -437,19 +438,23 @@ def process(files,button):
437
  df.to_csv(c_name,index=False)
438
 
439
  cleaned_names.append(c_name)
 
 
 
 
440
  if msg == None:
441
- status.append(op_outcome(name,' was successfully cleansed',passe))
442
  else:
443
- status.append(op_outcome(name,msg,warn))
444
  else:
445
  name = os.path.basename(name)
446
- status.append(op_outcome(name,' Failed (Only .csv, .xlsx, .zip are allowed)',fail))
447
 
448
  if len(cleaned_names) > 0 :
449
  final_file = zip_files(cleaned_names)
450
  else:
451
  final_file = None
452
- msg = '\n'.join(f"{index + 1}. {value}" for index, value in enumerate(status))
453
  return gr.File.update(value=final_file,visible=True),msg
454
  #return(str(files)+'fole')
455
 
@@ -487,7 +492,7 @@ with gr.Blocks(css=elems) as demo:
487
  with gr.Row():
488
  inp = gr.File(label='Input file/s')
489
  with gr.Row():
490
- bt = gr.Button(value='Clean',elem_id='red-button')
491
  #bt1 = gr.Button(value='Restart')
492
 
493
  for _ in range(2):
@@ -501,4 +506,4 @@ with gr.Blocks(css=elems) as demo:
501
 
502
  bt.click(fn = process, inputs=[inp,bt], outputs=[out,log])
503
 
504
- demo.launch(debug = False,show_api=False)
 
10
  g_mapping = None
11
 
12
  elems = """
13
+ #button {
14
  /* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#f6e6b4+0,ed9017+100;Yellow+3D+%231 */
15
  background: #f6e6b4; /* Old browsers */
16
  background: -moz-linear-gradient(top, #f6e6b4 0%, #ed9017 100%); /* FF3.6-15 */
 
365
  match = re.search(pattern, text, flags=re.IGNORECASE)
366
  return bool(match)
367
 
368
+ def op_outcome(name,msg):
369
  name = os.path.basename(name)
370
+ return name+msg
371
 
372
  def process(files,button):
373
+ global warnings
374
+ fail = ' ❌\n'
375
+ passe = ' \n'
376
+ warn = ' ⚠️\n'
377
  status = []
378
  cleaned_names = []
379
  if files is None:
 
403
  if "summ" in name:
404
  df,columns = filter_premiums(df)
405
  if columns == None:
406
+ print(name,'has no LOB column')
407
  print("--"*50)
408
+ status.append(op_outcome(name,' has no LOB column'+fail))
409
  continue
410
  altnames = get_alts('summ')
411
  else:
412
  df,columns = filter_claims(df)
413
  if columns == None:
414
+ print(name,'has no LOB column')
415
  print("--"*50)
416
+ status.append(op_outcome(name,' has no LOB column'+fail))
417
  continue
418
  altnames = get_alts('claim')
419
 
 
438
  df.to_csv(c_name,index=False)
439
 
440
  cleaned_names.append(c_name)
441
+
442
+ formatted_warnings = ''
443
+ if len(warnings) > 0:
444
+ formatted_warnings = '📝:\n'+'\n'.join(warnings)
445
  if msg == None:
446
+ status.append(op_outcome(name,' was processed'+passe+formatted_warnings))
447
  else:
448
+ status.append(op_outcome(name,msg+warn+formatted_warnings))
449
  else:
450
  name = os.path.basename(name)
451
+ status.append(op_outcome(name,' Failed (Only .csv, .xlsx, .zip are allowed)'+fail))
452
 
453
  if len(cleaned_names) > 0 :
454
  final_file = zip_files(cleaned_names)
455
  else:
456
  final_file = None
457
+ msg = '\n'.join(f"{index + 1}.{value}" for index, value in enumerate(status))
458
  return gr.File.update(value=final_file,visible=True),msg
459
  #return(str(files)+'fole')
460
 
 
492
  with gr.Row():
493
  inp = gr.File(label='Input file/s')
494
  with gr.Row():
495
+ bt = gr.Button(value='Clean',elem_id='button')
496
  #bt1 = gr.Button(value='Restart')
497
 
498
  for _ in range(2):
 
506
 
507
  bt.click(fn = process, inputs=[inp,bt], outputs=[out,log])
508
 
509
+ demo.launch(debug = False)