jonathanjordan21 commited on
Commit
f7ffbe2
·
verified ·
1 Parent(s): 8420bc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -40,21 +40,25 @@ codes = """001 - Vehicle Registration (New)
40
  033 - Other/Undetected""".split("\n")
41
 
42
 
 
 
43
  model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
 
44
 
45
  def respond(
46
  message,
47
  history: list[tuple[str, str]],
48
  ):
 
 
49
  # messages = [{"role": "system", "content": system_message}]
50
  pattern = r'\b([A-Z]{1,2})\s?(\d{4})\s?([A-Z]{3})\b'
51
- pattern = r'\b([A-Z]{1,2})\s?(\d{4})\s?([A-Z]{3})\b'
52
 
53
  matches = re.findall(pattern, message)
54
 
55
  plate_numbers = ", ".join([" ".join(x) for i,x in enumerate(matches)])
56
 
57
- codes_emb = model.encode(codes)
58
  text_emb = model.encode(message)
59
  scores = cos_sim(codes_emb, text_emb)[:,0]
60
 
@@ -88,10 +92,21 @@ def respond(
88
  """
89
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
90
  """
91
- demo = gr.ChatInterface(
92
- respond,
93
- )
 
 
 
 
 
 
 
 
 
94
 
 
 
95
 
96
  if __name__ == "__main__":
97
  demo.launch()
 
40
  033 - Other/Undetected""".split("\n")
41
 
42
 
43
+
44
+
45
  model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
46
+ codes_emb = model.encode(codes)
47
 
48
  def respond(
49
  message,
50
  history: list[tuple[str, str]],
51
  ):
52
+ global codes_emb
53
+
54
  # messages = [{"role": "system", "content": system_message}]
55
  pattern = r'\b([A-Z]{1,2})\s?(\d{4})\s?([A-Z]{3})\b'
56
+ pattern = r'\b([A-Z]{1,2})\s?(\d{4})\s?([A-Z]{1,3})\b'
57
 
58
  matches = re.findall(pattern, message)
59
 
60
  plate_numbers = ", ".join([" ".join(x) for i,x in enumerate(matches)])
61
 
 
62
  text_emb = model.encode(message)
63
  scores = cos_sim(codes_emb, text_emb)[:,0]
64
 
 
92
  """
93
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
94
  """
95
+ # demo = gr.ChatInterface(
96
+ # respond,
97
+ # )
98
+
99
+
100
+ with gr.Blocks() as demo:
101
+ # Add header title and description
102
+ gr.Markdown("# List of Request Numbers")
103
+ gr.Markdown("\n".join(codes))
104
+ gr.Markdown("# Valid License Plate Number Criteria:")
105
+ gr.Markdown("(1-2 letter) (4 numbers) (1-3 letters)")
106
+ # gr.Markdown("This is a demo chat interface where you can ask questions and receive responses.")
107
 
108
+ # Add chat interface
109
+ chat_interface = gr.ChatInterface(respond)
110
 
111
  if __name__ == "__main__":
112
  demo.launch()