Spaces:
Runtime error
Runtime error
mkw18
commited on
Commit
•
5fa2c5d
1
Parent(s):
1fdbadb
fix filepath
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ def showInput(input, chatbot):
|
|
63 |
return chatbot
|
64 |
|
65 |
|
66 |
-
def predict(input, chatbot, messages):
|
67 |
chatbot.append((parse_text(input), ""))
|
68 |
messages.append({"role": 'user', "content": input})
|
69 |
# completion = openai.ChatCompletion.create(
|
@@ -76,7 +76,7 @@ def predict(input, chatbot, messages):
|
|
76 |
# messages.append({"role": "assistant", "content": response})
|
77 |
# data = {'predict': messages}
|
78 |
# requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
79 |
-
data = {'predict': messages, '
|
80 |
response=str(requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content, encoding="utf-8")
|
81 |
chatbot[-1] = (parse_text(input), parse_text(response))
|
82 |
messages.append({"role": "assistant", "content": response})
|
@@ -88,27 +88,24 @@ def reset_user_input():
|
|
88 |
|
89 |
|
90 |
def reset_state():
|
91 |
-
global filepath
|
92 |
data = {'refresh': ''}
|
93 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
94 |
data = json.loads(str(data, encoding="utf-8"))
|
95 |
chatbot = data['chatbot']
|
96 |
messages = data['messages']
|
97 |
answer = data['answer']
|
98 |
-
|
99 |
-
return chatbot, messages, gr.update(value=""), gr.update(value="Show Answer"), answer
|
100 |
|
101 |
|
102 |
-
def show_hide_answer(answer):
|
103 |
-
global show_ans
|
104 |
if show_ans:
|
105 |
show_ans = False
|
106 |
return gr.update(value=""), gr.update(value="Show Answer")
|
107 |
else:
|
108 |
show_ans = True
|
109 |
-
return gr.update(value=answer), gr.update(value="Hide Answer")
|
110 |
|
111 |
-
show_ans = False
|
112 |
|
113 |
with gr.Blocks() as demo:
|
114 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
@@ -117,9 +114,9 @@ with gr.Blocks() as demo:
|
|
117 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
118 |
data = json.loads(str(data, encoding="utf-8"))
|
119 |
chatbot = gr.Chatbot(data['chatbot'])
|
120 |
-
global filepath
|
121 |
answer = gr.State(data['answer'])
|
122 |
-
|
|
|
123 |
with gr.Row():
|
124 |
with gr.Column(scale=4):
|
125 |
with gr.Column(scale=12):
|
@@ -140,8 +137,8 @@ with gr.Blocks() as demo:
|
|
140 |
show_progress=True)
|
141 |
submitBtn.click(reset_user_input, [], [user_input])
|
142 |
|
143 |
-
emptyBtn.click(reset_state, outputs=[chatbot, messages, answer_output, answerBtn, answer], show_progress=True)
|
144 |
|
145 |
-
answerBtn.click(show_hide_answer, [answer], outputs=[answer_output, answerBtn])
|
146 |
|
147 |
demo.queue().launch()
|
|
|
63 |
return chatbot
|
64 |
|
65 |
|
66 |
+
def predict(input, chatbot, messages, idx):
|
67 |
chatbot.append((parse_text(input), ""))
|
68 |
messages.append({"role": 'user', "content": input})
|
69 |
# completion = openai.ChatCompletion.create(
|
|
|
76 |
# messages.append({"role": "assistant", "content": response})
|
77 |
# data = {'predict': messages}
|
78 |
# requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
79 |
+
data = {'predict': messages, 'idx': idx}
|
80 |
response=str(requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content, encoding="utf-8")
|
81 |
chatbot[-1] = (parse_text(input), parse_text(response))
|
82 |
messages.append({"role": "assistant", "content": response})
|
|
|
88 |
|
89 |
|
90 |
def reset_state():
|
|
|
91 |
data = {'refresh': ''}
|
92 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
93 |
data = json.loads(str(data, encoding="utf-8"))
|
94 |
chatbot = data['chatbot']
|
95 |
messages = data['messages']
|
96 |
answer = data['answer']
|
97 |
+
idx = data['idx']
|
98 |
+
return chatbot, messages, gr.update(value=""), gr.update(value="Show Answer"), answer, idx
|
99 |
|
100 |
|
101 |
+
def show_hide_answer(answer, show_ans):
|
|
|
102 |
if show_ans:
|
103 |
show_ans = False
|
104 |
return gr.update(value=""), gr.update(value="Show Answer")
|
105 |
else:
|
106 |
show_ans = True
|
107 |
+
return gr.update(value=answer), gr.update(value="Hide Answer"), show_ans
|
108 |
|
|
|
109 |
|
110 |
with gr.Blocks() as demo:
|
111 |
gr.HTML("""<h1 align="center">海龟汤</h1>""")
|
|
|
114 |
data=requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
|
115 |
data = json.loads(str(data, encoding="utf-8"))
|
116 |
chatbot = gr.Chatbot(data['chatbot'])
|
|
|
117 |
answer = gr.State(data['answer'])
|
118 |
+
idx = gr.State(data['idx'])
|
119 |
+
show_ans = gr.State(False)
|
120 |
with gr.Row():
|
121 |
with gr.Column(scale=4):
|
122 |
with gr.Column(scale=12):
|
|
|
137 |
show_progress=True)
|
138 |
submitBtn.click(reset_user_input, [], [user_input])
|
139 |
|
140 |
+
emptyBtn.click(reset_state, outputs=[chatbot, messages, answer_output, answerBtn, answer, idx], show_progress=True)
|
141 |
|
142 |
+
answerBtn.click(show_hide_answer, [answer, show_ans], outputs=[answer_output, answerBtn, show_ans])
|
143 |
|
144 |
demo.queue().launch()
|