orangewong commited on
Commit
0f9d18a
·
verified ·
1 Parent(s): 94a08bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -37,15 +37,26 @@ def predict(message, history):
37
  ):
38
  yield response.strip()
39
 
40
- # 创建Gradio界面
41
- demo = gr.ChatInterface(
42
- predict,
43
- title="Zhi-writing-dsr1-14",
44
- description="这是一个基于Zhi-writing-dsr1-14的文章生成器。",
45
- examples=["以鲁迅口吻写一篇500字关于桔了个仔的散文", "用知乎常见的表达方式讲讲什么是AI?", "告诉我一个我大概率不知道的人生哲理"],
46
- theme=gr.themes.Soft(),
47
- streaming=True
48
- )
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  if __name__ == "__main__":
51
  demo.launch(share=True)
 
37
  ):
38
  yield response.strip()
39
 
40
+
41
+
42
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
43
+ gr.Markdown("# Zhi-writing-dsr1-14")
44
+ gr.Markdown("这是一个基于Zhi-writing-dsr1-14的文章生成器")
45
+
46
+ chatbot = gr.Chatbot()
47
+ msg = gr.Textbox(label="输入消息")
48
+ clear = gr.Button("清除对话")
49
+
50
+ def respond(message, chat_history):
51
+ bot_message = ""
52
+ for response in predict(message, chat_history):
53
+ bot_message = response
54
+ chat_history.append((message, bot_message))
55
+ yield chat_history
56
+ return "", chat_history
57
+
58
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
59
+ clear.click(lambda: None, None, chatbot, queue=False)
60
 
61
  if __name__ == "__main__":
62
  demo.launch(share=True)