Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,7 +113,14 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
|
|
| 113 |
# check whether each line is non-empty
|
| 114 |
if chunk:
|
| 115 |
# decode each line as response data is in bytes
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
break
|
| 118 |
#print(json.loads(chunk.decode()[6:])['choices'][0]["delta"] ["content"])
|
| 119 |
partial_words = partial_words + \
|
|
@@ -126,7 +133,6 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
|
|
| 126 |
chatbot[-1] = (history[-2], history[-1])
|
| 127 |
# chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
| 128 |
token_counter += 1
|
| 129 |
-
print(chatbot)
|
| 130 |
# resembles {chatbot: chat, state: history}
|
| 131 |
yield chatbot, history
|
| 132 |
|
|
@@ -180,13 +186,8 @@ def compose_user(user_input):
|
|
| 180 |
def reset_textbox():
|
| 181 |
return gr.update(value='')
|
| 182 |
|
| 183 |
-
title = """<h1 align="center">
|
| 184 |
description = """<div align=center>
|
| 185 |
-
|
| 186 |
-
由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 开发
|
| 187 |
-
|
| 188 |
-
访问川虎ChatGPT的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本
|
| 189 |
-
|
| 190 |
此App使用 `gpt-3.5-turbo` 大语言模型
|
| 191 |
</div>
|
| 192 |
"""
|
|
@@ -257,7 +258,6 @@ with gr.Blocks() as demo:
|
|
| 257 |
refreshBtn.click(get_history_names, None, [uploadDropdown])
|
| 258 |
uploadBtn.click(load_chat_history, [uploadDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
demo.
|
| 263 |
-
demo.queue().launch(server_name="0.0.0.0", share=False) # 改为 share=True 可以创建公开分享链接
|
|
|
|
| 113 |
# check whether each line is non-empty
|
| 114 |
if chunk:
|
| 115 |
# decode each line as response data is in bytes
|
| 116 |
+
try:
|
| 117 |
+
if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
|
| 118 |
+
break
|
| 119 |
+
except Exception as e:
|
| 120 |
+
chatbot.pop()
|
| 121 |
+
chatbot.append((history[-1], f"☹️发生了错误\n返回值:{response.text}\n异常:{e}"))
|
| 122 |
+
history.pop()
|
| 123 |
+
yield chatbot, history
|
| 124 |
break
|
| 125 |
#print(json.loads(chunk.decode()[6:])['choices'][0]["delta"] ["content"])
|
| 126 |
partial_words = partial_words + \
|
|
|
|
| 133 |
chatbot[-1] = (history[-2], history[-1])
|
| 134 |
# chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
| 135 |
token_counter += 1
|
|
|
|
| 136 |
# resembles {chatbot: chat, state: history}
|
| 137 |
yield chatbot, history
|
| 138 |
|
|
|
|
| 186 |
def reset_textbox():
|
| 187 |
return gr.update(value='')
|
| 188 |
|
| 189 |
+
title = """<h1 align="center">ChatGPT 🚀</h1>"""
|
| 190 |
description = """<div align=center>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
此App使用 `gpt-3.5-turbo` 大语言模型
|
| 192 |
</div>
|
| 193 |
"""
|
|
|
|
| 258 |
refreshBtn.click(get_history_names, None, [uploadDropdown])
|
| 259 |
uploadBtn.click(load_chat_history, [uploadDropdown], [saveFileName, systemPromptTxt, history, chatbot], show_progress=True)
|
| 260 |
|
| 261 |
+
|
| 262 |
+
demo.title = "ChatGPT 🚀"
|
| 263 |
+
demo.queue().launch(server_name = "0.0.0.0", share=False) # 改为 share=True 可以创建公开分享链接
|
|
|