Spaces:
Runtime error
Runtime error
mkw18
commited on
Commit
·
bca6c3c
1
Parent(s):
c12a800
ip detect
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import random as rd
|
|
5 |
import os
|
6 |
import json
|
7 |
import time
|
|
|
8 |
import openai
|
9 |
import requests
|
10 |
|
@@ -101,7 +102,19 @@ def reset_user_input():
|
|
101 |
return gr.update(value='')
|
102 |
|
103 |
|
104 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
data = {'refresh': ''}
|
106 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
107 |
data = json.loads(str(data, encoding="utf-8"))
|
@@ -121,6 +134,8 @@ def show_hide_answer(answer, show_ans):
|
|
121 |
return gr.update(value=answer), gr.update(value="Hide Answer"), show_ans
|
122 |
|
123 |
|
|
|
|
|
124 |
with gr.Blocks() as demo:
|
125 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
126 |
|
@@ -128,6 +143,7 @@ with gr.Blocks() as demo:
|
|
128 |
rule = gr.Textbox(label='规则', value='海龟汤是一个推理类游戏,游戏开始时会给出一段隐去关键信息的叙述,即汤面,玩家根据汤面提出问题,问题需要能够通过“是”或“否”来回答。玩家通过提问不同可能性,缩小真相的范围,直到最终猜到真相(即汤底)的关键信息。玩家可以点击"New Game"按钮开始新的游戏,点击"Show Answer"可查看汤底。',
|
129 |
lines=1, max_lines=3).style(container=False)
|
130 |
data = {'refresh': ''}
|
|
|
131 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
132 |
data = json.loads(str(data, encoding="utf-8"))
|
133 |
chatbot = gr.Chatbot(data['chatbot'])
|
@@ -158,7 +174,7 @@ with gr.Blocks() as demo:
|
|
158 |
show_progress=True)
|
159 |
submitBtn.click(reset_user_input, [], [user_input])
|
160 |
|
161 |
-
emptyBtn.click(reset_state, outputs=[chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans], show_progress=True)
|
162 |
|
163 |
answerBtn.click(show_hide_answer, [answer, show_ans], outputs=[answer_output, answerBtn, show_ans])
|
164 |
|
|
|
5 |
import os
|
6 |
import json
|
7 |
import time
|
8 |
+
import schedule
|
9 |
import openai
|
10 |
import requests
|
11 |
|
|
|
102 |
return gr.update(value='')
|
103 |
|
104 |
|
105 |
+
def rate_cnt():
|
106 |
+
global host_cnt
|
107 |
+
host_cnt = {}
|
108 |
+
|
109 |
+
def reset_state(chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans, request: gr.Request):
|
110 |
+
global host_cnt
|
111 |
+
host = request.client.host
|
112 |
+
if not host in host_cnt:
|
113 |
+
host_cnt[host] = 1
|
114 |
+
else:
|
115 |
+
host_cnt[host] += 1
|
116 |
+
if host_cnt[host] >= 10:
|
117 |
+
return chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans
|
118 |
data = {'refresh': ''}
|
119 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
120 |
data = json.loads(str(data, encoding="utf-8"))
|
|
|
134 |
return gr.update(value=answer), gr.update(value="Hide Answer"), show_ans
|
135 |
|
136 |
|
137 |
+
host_cnt = {}
|
138 |
+
|
139 |
with gr.Blocks() as demo:
|
140 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
141 |
|
|
|
143 |
rule = gr.Textbox(label='规则', value='海龟汤是一个推理类游戏,游戏开始时会给出一段隐去关键信息的叙述,即汤面,玩家根据汤面提出问题,问题需要能够通过“是”或“否”来回答。玩家通过提问不同可能性,缩小真相的范围,直到最终猜到真相(即汤底)的关键信息。玩家可以点击"New Game"按钮开始新的游戏,点击"Show Answer"可查看汤底。',
|
144 |
lines=1, max_lines=3).style(container=False)
|
145 |
data = {'refresh': ''}
|
146 |
+
schedule.every(1).minutes.do(rate_cnt)
|
147 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
148 |
data = json.loads(str(data, encoding="utf-8"))
|
149 |
chatbot = gr.Chatbot(data['chatbot'])
|
|
|
174 |
show_progress=True)
|
175 |
submitBtn.click(reset_user_input, [], [user_input])
|
176 |
|
177 |
+
emptyBtn.click(reset_state, [chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans], outputs=[chatbot, messages, answer_output, answerBtn, answer, idx, question, show_ans], show_progress=True)
|
178 |
|
179 |
answerBtn.click(show_hide_answer, [answer, show_ans], outputs=[answer_output, answerBtn, show_ans])
|
180 |
|