Spaces:
Sleeping
Sleeping
mkw18
commited on
Commit
•
8970855
1
Parent(s):
43a01f6
add term
Browse files
app.py
CHANGED
@@ -60,7 +60,7 @@ def CheckTrue(chatbot, key):
|
|
60 |
data = {'AgentCheck': True, 'key': key}
|
61 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
62 |
if not response.status_code == 200:
|
63 |
-
chatbot.append((parse_text("
|
64 |
return chatbot
|
65 |
chatbot.append((parse_text("是"), parse_text(str(response.content, encoding="utf-8"))))
|
66 |
return chatbot
|
@@ -69,7 +69,7 @@ def CheckFalse(chatbot, key):
|
|
69 |
data = {'AgentCheck': False, 'key': key}
|
70 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
71 |
if not response.status_code == 200:
|
72 |
-
chatbot.append((parse_text("
|
73 |
return chatbot
|
74 |
chatbot.append((parse_text("否"), parse_text(str(response.content, encoding="utf-8"))))
|
75 |
return chatbot
|
@@ -77,16 +77,25 @@ def CheckFalse(chatbot, key):
|
|
77 |
def CheckTerm(chatbot, key):
|
78 |
data = {'AgentFinish': True, 'key': key}
|
79 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
|
|
80 |
if not response.status_code == 200:
|
81 |
-
chatbot.append((parse_text(
|
82 |
-
return chatbot
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
with gr.Blocks() as demo:
|
87 |
gr.HTML("""<h1 align="center">Generative Agents测试平台</h1>""")
|
88 |
user_key = gr.Textbox(label='Key', placeholder="Input your key, press enter to apply", lines=1, max_lines=1).style(
|
89 |
container=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
chatbot = gr.Chatbot([])
|
91 |
|
92 |
with gr.Row():
|
@@ -95,11 +104,11 @@ with gr.Blocks() as demo:
|
|
95 |
with gr.Column(scale=1):
|
96 |
falseBtn = gr.Button('否')
|
97 |
with gr.Column(scale=1):
|
98 |
-
termBtn = gr.Button('
|
99 |
|
100 |
-
user_key.submit(CheckTerm, [chatbot, user_key], [chatbot])
|
101 |
trueBtn.click(CheckTrue, [chatbot, user_key], [chatbot])
|
102 |
falseBtn.click(CheckFalse, [chatbot, user_key], [chatbot])
|
103 |
-
termBtn.click(CheckTerm, [chatbot, user_key], [chatbot])
|
104 |
|
105 |
demo.queue().launch()
|
|
|
60 |
data = {'AgentCheck': True, 'key': key}
|
61 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
62 |
if not response.status_code == 200:
|
63 |
+
chatbot.append((parse_text(str(response.content, encoding="utf-8")), None))
|
64 |
return chatbot
|
65 |
chatbot.append((parse_text("是"), parse_text(str(response.content, encoding="utf-8"))))
|
66 |
return chatbot
|
|
|
69 |
data = {'AgentCheck': False, 'key': key}
|
70 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
71 |
if not response.status_code == 200:
|
72 |
+
chatbot.append((parse_text(str(response.content, encoding="utf-8")), None))
|
73 |
return chatbot
|
74 |
chatbot.append((parse_text("否"), parse_text(str(response.content, encoding="utf-8"))))
|
75 |
return chatbot
|
|
|
77 |
def CheckTerm(chatbot, key):
|
78 |
data = {'AgentFinish': True, 'key': key}
|
79 |
response=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
80 |
+
msg = str(response.content, encoding="utf-8")
|
81 |
if not response.status_code == 200:
|
82 |
+
chatbot.append((None, parse_text(msg)))
|
83 |
+
return chatbot, gr.update(value=msg), gr.update(value=msg)
|
84 |
+
response = json.loads(msg)
|
85 |
+
chatbot = [(None, parse_text(response['response']))]
|
86 |
+
return chatbot, gr.update(value=response['story']), gr.update(value=response['answer'])
|
87 |
|
88 |
with gr.Blocks() as demo:
|
89 |
gr.HTML("""<h1 align="center">Generative Agents测试平台</h1>""")
|
90 |
user_key = gr.Textbox(label='Key', placeholder="Input your key, press enter to apply", lines=1, max_lines=1).style(
|
91 |
container=False)
|
92 |
+
with gr.Row():
|
93 |
+
with gr.Column(scale=1):
|
94 |
+
story = gr.Textbox(label='Story', lines=3, max_lines=3).style(
|
95 |
+
container=False)
|
96 |
+
with gr.Column(scale=1):
|
97 |
+
answer = gr.Textbox(label='Answer', lines=3, max_lines=3).style(
|
98 |
+
container=False)
|
99 |
chatbot = gr.Chatbot([])
|
100 |
|
101 |
with gr.Row():
|
|
|
104 |
with gr.Column(scale=1):
|
105 |
falseBtn = gr.Button('否')
|
106 |
with gr.Column(scale=1):
|
107 |
+
termBtn = gr.Button('达到终止条件')
|
108 |
|
109 |
+
user_key.submit(CheckTerm, [chatbot, user_key], [chatbot, story, answer])
|
110 |
trueBtn.click(CheckTrue, [chatbot, user_key], [chatbot])
|
111 |
falseBtn.click(CheckFalse, [chatbot, user_key], [chatbot])
|
112 |
+
termBtn.click(CheckTerm, [chatbot, user_key], [chatbot, story, answer])
|
113 |
|
114 |
demo.queue().launch()
|