Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
import time
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
flightFileLink = 'https://winningchatbot.s3.ap-southeast-1.amazonaws.com/SG-AD-S003'
|
| 7 |
+
tripFileLink= 'https://winningchatbot.s3.ap-southeast-1.amazonaws.com/SG-HR-W013'
|
| 8 |
+
|
| 9 |
+
def chat(message, history):
|
| 10 |
+
|
| 11 |
+
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)
|
| 12 |
+
|
| 13 |
+
result = requests.get(f"https://5nzypzim7yvdq2jqbodhwnxpy40glpse.lambda-url.ap-southeast-1.on.aws/?message={message}").json()
|
| 14 |
+
print(result)
|
| 15 |
+
reply = result['text']
|
| 16 |
+
files = result['files']
|
| 17 |
+
|
| 18 |
+
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), reply)
|
| 19 |
+
|
| 20 |
+
reply = re.sub(r'\【\d+\:\d+\†source\】', '', reply)
|
| 21 |
+
|
| 22 |
+
if 'file-akk9CVNRjnmc3vNk3sV203lN' in files:
|
| 23 |
+
reply = reply+ f"\n\n【信息源: SG-AD-S003 韦立新加坡-出差订票和住宿管理方案-修订20240129.pdf】\n({flightFileLink})"
|
| 24 |
+
if 'file-sHwZmYpPK67lsMX4uflSZXD1' in files:
|
| 25 |
+
reply = reply+ f"\n\n【信息源: SG-AD-S004 SG-HR-W013 出差制度】\n({tripFileLink})"
|
| 26 |
+
|
| 27 |
+
return reply
|
| 28 |
+
|
| 29 |
+
gr.ChatInterface(
|
| 30 |
+
fn=chat,
|
| 31 |
+
chatbot= gr.Chatbot(),
|
| 32 |
+
textbox= gr.Textbox(placeholder="开始聊天", container=False, scale=7),
|
| 33 |
+
multimodal = False,
|
| 34 |
+
title="韦立 HR 聊天机器人 (GPT)",
|
| 35 |
+
description="目前所搜集的数据可回答关于韦立的出差订票,住宿管理方案,和出差制度方面问题。",
|
| 36 |
+
# theme="soft",
|
| 37 |
+
examples=["副董事长应该订哪一类机票?", "青岛的负责订票人员是谁?", "在新加坡能订哪些酒店?"],
|
| 38 |
+
cache_examples = False,
|
| 39 |
+
autofocus = True,
|
| 40 |
+
retry_btn = None,
|
| 41 |
+
undo_btn = None,
|
| 42 |
+
clear_btn = None,
|
| 43 |
+
).queue().launch(server_port=8080)
|