WinningChat / app.py
JasonData's picture
Update app.py
ce9b9fa verified
import gradio as gr
import re
import time
import requests
flightFileLink = 'https://winningchatbot.s3.ap-southeast-1.amazonaws.com/SG-AD-S003'
tripFileLink= 'https://winningchatbot.s3.ap-southeast-1.amazonaws.com/SG-HR-W013'
def chat(message, history):
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)
result = requests.get(f"https://5nzypzim7yvdq2jqbodhwnxpy40glpse.lambda-url.ap-southeast-1.on.aws/?message={message}").json()
print(result)
reply = result['text']
files = result['files']
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), reply)
reply = re.sub(r'\【\d+\:\d+\†source\】', '', reply)
if 'file-akk9CVNRjnmc3vNk3sV203lN' in files:
reply = reply+ f"\n\n【信息源: SG-AD-S003 韦立新加坡-出差订票和住宿管理方案-修订20240129.pdf】\n({flightFileLink})"
if 'file-sHwZmYpPK67lsMX4uflSZXD1' in files:
reply = reply+ f"\n\n【信息源: SG-AD-S004 SG-HR-W013 出差制度】\n({tripFileLink})"
return reply
gr.ChatInterface(
fn=chat,
chatbot= gr.Chatbot(),
textbox= gr.Textbox(placeholder="开始聊天", container=False, scale=7),
multimodal = False,
title="韦立 HR 聊天机器人 (GPT)",
description="目前所搜集的数据可回答关于韦立的出差订票,住宿管理方案,和出差制度方面问题。",
# theme="soft",
examples=["副董事长应该订哪一类机票?", "青岛的负责订票人员是谁?", "在新加坡能订哪些酒店?"],
cache_examples = False,
autofocus = True,
retry_btn = None,
undo_btn = None,
clear_btn = None,
).queue().launch()