jonathanjordan21 commited on
Commit
32aedb1
·
verified ·
1 Parent(s): 6a8f5aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -11
app.py CHANGED
@@ -103,6 +103,9 @@ codes = """001 - Pendaftaran Kendaraan
103
  008 - Pelaporan dan Bantuan Terkait Kendaraan
104
  009 - Penangguhan atau Deklarasi Perubahan Penggunaan Kendaraan""".split("\n")
105
 
 
 
 
106
  # documents = """Vehicle Registration
107
  # Vehicle Data Update
108
  # Vehicle Ownership or Change of Name
@@ -416,8 +419,8 @@ def load_model(model_id):
416
  return model, None
417
  else:
418
  model = SentenceTransformer(model_id, trust_remote_code=True)
419
- # codes_emb = model.encode([x[6:] for x in codes])
420
- codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
421
  # codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
422
  return model, codes_emb
423
 
@@ -740,9 +743,20 @@ def reload(chosen_model_id):
740
  return f"Model {chosen_model_id} is ready!"
741
 
742
 
743
- def respond_pkb(message, history: list[tuple[str, str]]):
744
- tarif_pkb = 1.5/100
745
- tarif_bbnkb = 0.1
 
 
 
 
 
 
 
 
 
 
 
746
 
747
  pattern = r'\b([A-Za-z]{1,2})\s?(\d{2,4})\s?([A-Za-z]{1,3})\b'
748
 
@@ -750,6 +764,19 @@ def respond_pkb(message, history: list[tuple[str, str]]):
750
 
751
  plates = [" ".join(x).upper() for i,x in enumerate(matches)]
752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
753
  out = ""
754
 
755
  for inp in plates:
@@ -772,10 +799,24 @@ def respond_pkb(message, history: list[tuple[str, str]]):
772
  for k,v in vehicle.iloc[0].items():
773
  out += f"\n{k} \t\t: {v}"
774
  # out += "\n=================================================================="
775
- out += "\n--"
776
- out += f"\nBea Balik Nama Kendaraan Bermotor (BBNKB) : Rp{int(bbnkb):,}"
777
- out += f"\nPajak Kendaraan Bermotor (PKB) : Rp{int(pkb):,}\n"
778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779
  return out
780
 
781
 
@@ -810,11 +851,13 @@ with gr.Blocks() as demo:
810
  chat_interface = gr.ChatInterface(
811
  respond_pkb,
812
  chatbot=gr.Chatbot(height=670),#800
813
- # additional_inputs=[
814
- # gr.Number(0.44, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
 
 
815
  # gr.Checkbox(True, label="multiple", info="Allow multiple request code numbers"),
816
  # gr.Number(3, label="maximum number of request codes", show_label=True, minimum=0, step=1, precision=0)
817
- # ],
818
  # # type="messages",
819
  # # textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
820
  # # title="SamSat Virtual Assistant",
 
103
  008 - Pelaporan dan Bantuan Terkait Kendaraan
104
  009 - Penangguhan atau Deklarasi Perubahan Penggunaan Kendaraan""".split("\n")
105
 
106
+ codes = """003 - Alih Kepemilikan atau Balik Nama Kendaraan
107
+ 005 - Pembayaran dan Pengelolaan Pajak Kendaraan""".split("\n")
108
+
109
  # documents = """Vehicle Registration
110
  # Vehicle Data Update
111
  # Vehicle Ownership or Change of Name
 
419
  return model, None
420
  else:
421
  model = SentenceTransformer(model_id, trust_remote_code=True)
422
+ codes_emb = model.encode([x[6:] for x in codes])
423
+ # codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
424
  # codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
425
  return model, codes_emb
426
 
 
743
  return f"Model {chosen_model_id} is ready!"
744
 
745
 
746
+ def respond_pkb(
747
+ message,
748
+ history: list[tuple[str, str]],
749
+ threshold,
750
+ tarif_pkb,
751
+ tarif_bbnkb,
752
+ ):
753
+ global codes_emb
754
+ global undetected
755
+
756
+ undetected_code = undetected[:3]
757
+
758
+ # tarif_pkb = 1.5/100
759
+ # tarif_bbnkb = 0.1
760
 
761
  pattern = r'\b([A-Za-z]{1,2})\s?(\d{2,4})\s?([A-Za-z]{1,3})\b'
762
 
 
764
 
765
  plates = [" ".join(x).upper() for i,x in enumerate(matches)]
766
 
767
+
768
+ if type(model) == CrossEncoder:
769
+ sentence_pairs = [[message, v["name"]] for v in detail_perhitungan.values()]
770
+ scores = model.predict(sentence_pairs, convert_to_tensor=True)
771
+ # weights = [1,1]
772
+ else:
773
+ text_emb = model.encode(message)
774
+ scores = cos_sim(codes_emb, text_emb).mean(axis=-1)#[:,0]
775
+ # weights = [19,8]
776
+
777
+ # scores_argsort = scores.argsort(descending=True)
778
+
779
+
780
  out = ""
781
 
782
  for inp in plates:
 
799
  for k,v in vehicle.iloc[0].items():
800
  out += f"\n{k} \t\t: {v}"
801
  # out += "\n=================================================================="
 
 
 
802
 
803
+ out += "\n--"
804
+
805
+ if scores[0] > threshold:
806
+ out += "\nRumus Bea Balik Nama Kendaraan Bermotor (BBNKB) : TARIF x NJKB x PENGENAAN"
807
+ out += f"\nKalkulasi : 10% x Rp{int(nilai_jual):,} x 100%"
808
+ out += f"\nTotal Pembayaran : Rp{int(bbnkb):,}\n"
809
+ if scores[1] > threshold:
810
+ out += "\nRumus Pokok Pajak Kendaraan Bermotor (PKB) : TARIF * NJKB * BOBOT * PENGENAAN"
811
+ out += f"\nKalkulasi : 1% * Rp{int(nilai_jual):,} * {bobot} * 100%"
812
+ out += f"\nTotal Pembayaran : Rp{int(pkb):,}\n"
813
+
814
+ if not out:
815
+ if scores[0] > threshold:
816
+ out += "\nRumus Bea Balik Nama Kendaraan Bermotor (BBNKB) : TARIF x NJKB x PENGENAAN"
817
+ if scores[1] > threshold:
818
+ out += "\nRumus Pokok Pajak Kendaraan Bermotor (PKB) : TARIF * NJKB * BOBOT * PENGENAAN"
819
+
820
  return out
821
 
822
 
 
851
  chat_interface = gr.ChatInterface(
852
  respond_pkb,
853
  chatbot=gr.Chatbot(height=670),#800
854
+ additional_inputs=[
855
+ gr.Number(0.25, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
856
+ gr.Number(0.015, label="tarif pajak kendaraan bermotor (pkb)", show_label=True, minimum=0., maximum=1.0, step=0.01),
857
+ gr.Number(0.1, label="tarif bea balik nama kendaraan bermotor (bbnkb)", show_label=True, minimum=0., maximum=1.0, step=0.05),
858
  # gr.Checkbox(True, label="multiple", info="Allow multiple request code numbers"),
859
  # gr.Number(3, label="maximum number of request codes", show_label=True, minimum=0, step=1, precision=0)
860
+ ],
861
  # # type="messages",
862
  # # textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
863
  # # title="SamSat Virtual Assistant",