JudyChoi commited on
Commit
992ab47
โ€ข
1 Parent(s): 8fd51b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import gradio as gr
2
-
3
  import json
4
 
5
  # JSON ํŒŒ์ผ ์ฝ๊ธฐ
6
- with open('node.json', 'r') as file:
7
  node_info = json.load(file)
8
 
9
  ##############################################################################
@@ -43,21 +43,27 @@ def classifier(utterance):
43
 
44
  top = stack.peek()
45
 
46
- if utterance == "save":
47
- while(True):
48
- if stack.size() == 0:
49
- return
50
- peek = stack.peek()
51
- if peek['start_node'] == 3:
52
- return
53
- else:
54
- stack.pop()
55
 
56
  # top node ์˜ dest node ๋ฅผ ๋ชจ๋‘ ๊ฐ€์ ธ์˜จ๋‹ค.
57
  for dest_node in top['dest_node']:
58
 
59
  # node_info ์—์„œ start_node == dest_node ์ธ ๋…ธ๋“œ๋ฅผ ์ฐพ๋Š”๋‹ค.
60
  for node in node_info["items"]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  if node['start_node'] == dest_node:
62
  # candidate_node.append(node)
63
  # ์ตœ์‹  ๋…ธ๋“œ๋ณด๋‹ค ๋ฐœํ™” ๋…ธ๋“œ๊ฐ€ ๋‹ค์Œ state ์ธ์ง€ ํ™•์ธ
@@ -92,20 +98,18 @@ stack.push(node_info["items"][0])
92
  ## ํŽ˜๋ฆฌ์˜ค ์ฐจํŠธ๋กœ ๋ถ„๊ธฐ
93
  stack.push(node_info["items"][1])
94
 
95
-
96
-
97
  demo = gr.Interface(fn=classifier, inputs="textbox", outputs="textbox",
98
  examples=[
99
  ["start listening"],
100
  ["select tooth 1"],
101
  ["pocket depth 1 2 3"],
102
  ["select tooth 2"],
103
- ["treatment plan"],
104
  ["missing"],
105
  ["select tooth 5 buccal mesial pocket depth"],
106
- ["save"]
107
- ]
108
- )
109
 
110
  if __name__ == "__main__":
111
- demo.launch(share=True)
 
1
  import gradio as gr
2
+ import re
3
  import json
4
 
5
  # JSON ํŒŒ์ผ ์ฝ๊ธฐ
6
+ with open('perio_demo.json', 'r') as file:
7
  node_info = json.load(file)
8
 
9
  ##############################################################################
 
43
 
44
  top = stack.peek()
45
 
46
+ global_check = re.compile(r'^#global')
 
 
 
 
 
 
 
 
47
 
48
  # top node ์˜ dest node ๋ฅผ ๋ชจ๋‘ ๊ฐ€์ ธ์˜จ๋‹ค.
49
  for dest_node in top['dest_node']:
50
 
51
  # node_info ์—์„œ start_node == dest_node ์ธ ๋…ธ๋“œ๋ฅผ ์ฐพ๋Š”๋‹ค.
52
  for node in node_info["items"]:
53
+
54
+ if node["utterance"] == utterance:
55
+ if node["fallback"] is not None:
56
+ if global_check.match(node["fallback"]):
57
+ node["fallback"] = int(re.sub(r'\D', '', node["fallback"]))
58
+ while(True):
59
+ if stack.size() == 0:
60
+ return
61
+ peek = stack.peek()
62
+ if peek['start_node'] == node["fallback"]:
63
+ return str(str(node['depth']) + ':' + node['intent'])
64
+ else:
65
+ stack.pop()
66
+
67
  if node['start_node'] == dest_node:
68
  # candidate_node.append(node)
69
  # ์ตœ์‹  ๋…ธ๋“œ๋ณด๋‹ค ๋ฐœํ™” ๋…ธ๋“œ๊ฐ€ ๋‹ค์Œ state ์ธ์ง€ ํ™•์ธ
 
98
  ## ํŽ˜๋ฆฌ์˜ค ์ฐจํŠธ๋กœ ๋ถ„๊ธฐ
99
  stack.push(node_info["items"][1])
100
 
 
 
101
  demo = gr.Interface(fn=classifier, inputs="textbox", outputs="textbox",
102
  examples=[
103
  ["start listening"],
104
  ["select tooth 1"],
105
  ["pocket depth 1 2 3"],
106
  ["select tooth 2"],
107
+ ["treatment note"],
108
  ["missing"],
109
  ["select tooth 5 buccal mesial pocket depth"],
110
+ ["save"],
111
+ ["stop listening"]
112
+ ])
113
 
114
  if __name__ == "__main__":
115
+ demo.launch()