Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import json
|
4 |
|
5 |
# JSON ํ์ผ ์ฝ๊ธฐ
|
6 |
-
with open('
|
7 |
node_info = json.load(file)
|
8 |
|
9 |
##############################################################################
|
@@ -43,21 +43,27 @@ def classifier(utterance):
|
|
43 |
|
44 |
top = stack.peek()
|
45 |
|
46 |
-
|
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
|
104 |
["missing"],
|
105 |
["select tooth 5 buccal mesial pocket depth"],
|
106 |
-
["save"]
|
107 |
-
]
|
108 |
-
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
-
demo.launch(
|
|
|
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()
|