jonathanjordan21 commited on
Commit
b704197
·
verified ·
1 Parent(s): 86936a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -13
app.py CHANGED
@@ -2,11 +2,24 @@ import gradio as gr
2
  import re
3
  import inspect
4
  import numpy as np
 
5
 
6
  from sentence_transformers import SentenceTransformer
7
  from sentence_transformers.util import cos_sim
8
  from sentence_transformers import CrossEncoder
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  codes = """001 - Vehicle Registration (New)
12
  002 - Vehicle Registration Renewal
@@ -724,6 +737,43 @@ def reload(chosen_model_id):
724
  return f"Model {chosen_model_id} is ready!"
725
 
726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
727
 
728
  with gr.Blocks() as demo:
729
  # Add header title and description
@@ -750,20 +800,20 @@ with gr.Blocks() as demo:
750
 
751
  gr.Markdown("# Chatbot Interface:")
752
  chat_interface = gr.ChatInterface(
753
- respond,
754
- additional_inputs=[
755
- gr.Number(0.44, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
756
- gr.Checkbox(True, label="multiple", info="Allow multiple request code numbers"),
757
- gr.Number(3, label="maximum number of request codes", show_label=True, minimum=0, step=1, precision=0)
758
- ],
759
- # type="messages",
760
  chatbot=gr.Chatbot(height=800),
761
- # textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
762
- # title="SamSat Virtual Assistant",
763
- # description="Ask Yes Man any question",
764
- # theme="soft",
765
- # examples=["balik nama D 3456 DEF", "bayar pajak B 1234 BCA", "halo, selamat pagi!"],
766
- # cache_examples=True,
 
 
 
 
 
 
767
  )
768
 
769
  if __name__ == "__main__":
 
2
  import re
3
  import inspect
4
  import numpy as np
5
+ import pandas as pd
6
 
7
  from sentence_transformers import SentenceTransformer
8
  from sentence_transformers.util import cos_sim
9
  from sentence_transformers import CrossEncoder
10
 
11
+ import mysql.connector
12
+
13
+ db_user = os.environ["DB_USER"]
14
+
15
+ mydb = mysql.connector.connect(
16
+ host=os.environ["DB_HOST"],
17
+ user=db_user,
18
+ password=os.environ["DB_PASSWORD"]
19
+ )
20
+
21
+ df_sample = pd.read_sql(f"SELECT * FROM {db_user}.mytable", mydb)
22
+ df_bobot = pd.read_sql(f"SELECT * FROM {db_user}.bobot", mydb)
23
 
24
  codes = """001 - Vehicle Registration (New)
25
  002 - Vehicle Registration Renewal
 
737
  return f"Model {chosen_model_id} is ready!"
738
 
739
 
740
+ def respond_pkb(message, history: list[tuple[str, str]]):
741
+ tarif_pkb = 1.5/100
742
+ tarif_bbnkb = 0.1
743
+
744
+ pattern = r'\b([A-Za-z]{1,2})\s?(\d{2,4})\s?([A-Za-z]{1,3})\b'
745
+
746
+ matches = re.findall(pattern, message)
747
+
748
+ plates = [" ".join(x).upper() for i,x in enumerate(matches)]
749
+
750
+ out = ""
751
+
752
+ for inp in plates:
753
+
754
+ vehicle = df_sample[df_sample["no_polisi"] == inp.strip()].copy()
755
+
756
+ if vehicle.shape[0] == 0:
757
+ out += f"\n\n---\nKendaraan {plate} Tidak Ditemukan\n"
758
+ else:
759
+ v_type = vehicle["nm_jenis_kb"].values[0]
760
+ nilai_jual = vehicle["nilai_jual"].values[0]
761
+
762
+ bobot = df_bobot[df_bobot["JENIS KENDARAAN"]==v_type]["BOBOT"].values[0]
763
+
764
+ bbnkb = tarif_bbnkb * nilai_jual * 1 # pengenaan
765
+ pkb = tarif_pkb * bobot * nilai_jual * 1 # pengenaan
766
+
767
+ vehicle["nilai_jual"] = f"{int(nilai_jual):,}"
768
+ out += "\n\n---\nDetail Kendaraan:"
769
+ for k,v in vehicle.iloc[0].items():
770
+ out += f"\n{k} \t\t: {v}"
771
+ out += "\n=================================================================="
772
+ out += f"\nBea Balik Nama Kendaraan Bermotor (BBNKB) : {int(bbnkb):,}"
773
+ out += f"\nPajak Kendaraan Bermotor (PKB) : {int(pkb):,}\n"
774
+
775
+ return out
776
+
777
 
778
  with gr.Blocks() as demo:
779
  # Add header title and description
 
800
 
801
  gr.Markdown("# Chatbot Interface:")
802
  chat_interface = gr.ChatInterface(
803
+ respond_pkb,
 
 
 
 
 
 
804
  chatbot=gr.Chatbot(height=800),
805
+ # additional_inputs=[
806
+ # gr.Number(0.44, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
807
+ # gr.Checkbox(True, label="multiple", info="Allow multiple request code numbers"),
808
+ # gr.Number(3, label="maximum number of request codes", show_label=True, minimum=0, step=1, precision=0)
809
+ # ],
810
+ # # type="messages",
811
+ # # textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
812
+ # # title="SamSat Virtual Assistant",
813
+ # # description="Ask Yes Man any question",
814
+ # # theme="soft",
815
+ # # examples=["balik nama D 3456 DEF", "bayar pajak B 1234 BCA", "halo, selamat pagi!"],
816
+ # # cache_examples=True,
817
  )
818
 
819
  if __name__ == "__main__":