mkw18 commited on
Commit
0234ead
1 Parent(s): a41ffcc

add submit

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -51,10 +51,16 @@ def parse_text(text):
51
  return text
52
 
53
 
54
- def test(chatbot):
55
- chatbot.append((None, parse_text('测试')))
56
- chatbot.append((parse_text('测试'), None))
57
- return chatbot
 
 
 
 
 
 
58
 
59
  def CheckTrue(chatbot, key):
60
  data = {'AgentCheck': True, 'key': key}
@@ -104,13 +110,14 @@ with gr.Blocks() as demo:
104
  with gr.Column(scale=1):
105
  falseBtn = gr.Button('否')
106
  with gr.Column(scale=1):
107
- falseBtn = gr.Button('无关')
108
  with gr.Column(scale=1):
109
  termBtn = gr.Button('达到终止条件')
110
 
111
- user_key.submit(CheckTerm, [chatbot, user_key], [chatbot, story, answer])
112
  trueBtn.click(CheckTrue, [chatbot, user_key], [chatbot])
113
  falseBtn.click(CheckFalse, [chatbot, user_key], [chatbot])
 
114
  termBtn.click(CheckTerm, [chatbot, user_key], [chatbot, story, answer])
115
 
116
  demo.queue().launch()
 
51
  return text
52
 
53
 
54
+ def SubmitKey(chatbot, key):
55
+ data = {'AgentStart': True, 'key': key}
56
+ response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
57
+ msg = str(response.content, encoding="utf-8")
58
+ if not response.status_code == 200:
59
+ chatbot = [(None, parse_text(msg))]
60
+ return chatbot, gr.update(value=msg), gr.update(value=msg)
61
+ response = json.loads(msg)
62
+ chatbot = response['chatbot']
63
+ return chatbot, gr.update(value=response['story']), gr.update(value=response['answer'])
64
 
65
  def CheckTrue(chatbot, key):
66
  data = {'AgentCheck': True, 'key': key}
 
110
  with gr.Column(scale=1):
111
  falseBtn = gr.Button('否')
112
  with gr.Column(scale=1):
113
+ irreBtn = gr.Button('无关')
114
  with gr.Column(scale=1):
115
  termBtn = gr.Button('达到终止条件')
116
 
117
+ user_key.submit(SubmitKey, [chatbot, user_key], [chatbot, story, answer])
118
  trueBtn.click(CheckTrue, [chatbot, user_key], [chatbot])
119
  falseBtn.click(CheckFalse, [chatbot, user_key], [chatbot])
120
+ irreBtn.click(CheckIrrelevant, [chatbot, user_key], [chatbot])
121
  termBtn.click(CheckTerm, [chatbot, user_key], [chatbot, story, answer])
122
 
123
  demo.queue().launch()