Spaces:
Runtime error
Runtime error
mkw18
commited on
Commit
•
de34c46
1
Parent(s):
9eec015
Chinese
Browse files
app.py
CHANGED
@@ -90,7 +90,7 @@ def predict(input, chatbot, messages, idx, answer):
|
|
90 |
response = response
|
91 |
finish = False
|
92 |
else:
|
93 |
-
response += f'恭喜您已经猜到汤底,汤底是:{answer}\n
|
94 |
finish = True
|
95 |
data = {'predict': messages, 'idx': idx, 'isfinished': finish, 'answer': answer}
|
96 |
requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
@@ -102,10 +102,9 @@ def reset_user_input():
|
|
102 |
return gr.update(value='')
|
103 |
|
104 |
|
105 |
-
def reset_state(
|
106 |
global host_cnt
|
107 |
host = request.client.host
|
108 |
-
|
109 |
if not host in host_cnt:
|
110 |
host_cnt[host] = time.time()
|
111 |
else:
|
@@ -120,16 +119,16 @@ def reset_state(chatbot, messages, answer_output, answerBtn, answer, idx, questi
|
|
120 |
messages = data['messages']
|
121 |
answer = data['answer']
|
122 |
idx = data['idx']
|
123 |
-
return chatbot, messages, gr.update(value=""), gr.update(value="
|
124 |
|
125 |
|
126 |
def show_hide_answer(answer, show_ans):
|
127 |
if show_ans:
|
128 |
show_ans = False
|
129 |
-
return gr.update(value=""), gr.update(value="
|
130 |
else:
|
131 |
show_ans = True
|
132 |
-
return gr.update(value=answer), gr.update(value="
|
133 |
|
134 |
|
135 |
host_cnt = {}
|
@@ -138,8 +137,7 @@ with gr.Blocks() as demo:
|
|
138 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
139 |
|
140 |
with gr.Row():
|
141 |
-
rule = gr.Textbox(label='规则', value='
|
142 |
-
lines=1, max_lines=3).style(container=False)
|
143 |
data = {'refresh': ''}
|
144 |
|
145 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
@@ -158,12 +156,12 @@ with gr.Blocks() as demo:
|
|
158 |
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=3, max_lines=3).style(
|
159 |
container=False)
|
160 |
with gr.Column(min_width=32, scale=1):
|
161 |
-
submitBtn = gr.Button("
|
162 |
-
emptyBtn = gr.Button("
|
163 |
with gr.Column(scale=1):
|
164 |
answer_output = gr.Textbox(show_label=False, lines=6, max_lines=6).style(
|
165 |
container=False)
|
166 |
-
answerBtn = gr.Button("
|
167 |
|
168 |
messages = gr.State(data['messages'])
|
169 |
|
@@ -172,7 +170,7 @@ with gr.Blocks() as demo:
|
|
172 |
show_progress=True)
|
173 |
submitBtn.click(reset_user_input, [], [user_input])
|
174 |
|
175 |
-
emptyBtn.click(reset_state,
|
176 |
|
177 |
answerBtn.click(show_hide_answer, [answer, show_ans], outputs=[answer_output, answerBtn, show_ans])
|
178 |
|
|
|
90 |
response = response
|
91 |
finish = False
|
92 |
else:
|
93 |
+
response += f'恭喜您已经猜到汤底,汤底是:{answer}\n点击“再来一局”按钮开始下一局游戏。'
|
94 |
finish = True
|
95 |
data = {'predict': messages, 'idx': idx, 'isfinished': finish, 'answer': answer}
|
96 |
requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
|
|
102 |
return gr.update(value='')
|
103 |
|
104 |
|
105 |
+
def reset_state(request: gr.Request):
|
106 |
global host_cnt
|
107 |
host = request.client.host
|
|
|
108 |
if not host in host_cnt:
|
109 |
host_cnt[host] = time.time()
|
110 |
else:
|
|
|
119 |
messages = data['messages']
|
120 |
answer = data['answer']
|
121 |
idx = data['idx']
|
122 |
+
return chatbot, messages, gr.update(value=""), gr.update(value="显示答案"), answer, idx, gr.update(value=data['story'].strip()), False
|
123 |
|
124 |
|
125 |
def show_hide_answer(answer, show_ans):
|
126 |
if show_ans:
|
127 |
show_ans = False
|
128 |
+
return gr.update(value=""), gr.update(value="显示答案"), show_ans
|
129 |
else:
|
130 |
show_ans = True
|
131 |
+
return gr.update(value=answer), gr.update(value="隐藏答案"), show_ans
|
132 |
|
133 |
|
134 |
host_cnt = {}
|
|
|
137 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
138 |
|
139 |
with gr.Row():
|
140 |
+
rule = gr.Textbox(label='规则', value='海龟汤是一个推理类游戏,游戏开始时会给出一段隐去关键信息的叙述,即汤面,玩家根据汤面推理,提出能够通过“是”或“否”来回答的问题,通过提问不同可能性,缩小真相的范围,直到最终猜到真相(即汤底)的关键信息。玩家可以点击“再来一局”按钮随机一场新的游戏,点击“显示答案”可查看汤底。', lines=1, max_lines=3).style(container=False)
|
|
|
141 |
data = {'refresh': ''}
|
142 |
|
143 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
|
|
156 |
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=3, max_lines=3).style(
|
157 |
container=False)
|
158 |
with gr.Column(min_width=32, scale=1):
|
159 |
+
submitBtn = gr.Button("发送", variant="primary")
|
160 |
+
emptyBtn = gr.Button("再来一局")
|
161 |
with gr.Column(scale=1):
|
162 |
answer_output = gr.Textbox(show_label=False, lines=6, max_lines=6).style(
|
163 |
container=False)
|
164 |
+
answerBtn = gr.Button("显示答案")
|
165 |
|
166 |
messages = gr.State(data['messages'])
|
167 |
|
|
|
170 |
show_progress=True)
|
171 |
submitBtn.click(reset_user_input, [], [user_input])
|
172 |
|
173 |
+
emptyBtn.click(reset_state, outputs=[chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans], show_progress=True)
|
174 |
|
175 |
answerBtn.click(show_hide_answer, [answer, show_ans], outputs=[answer_output, answerBtn, show_ans])
|
176 |
|