Spaces:
Runtime error
Runtime error
import requests | |
import json | |
API_KEY="4d95a8e9615d73939d5f0b8997bc4614eaf96f854a5ab503f5d781e1c5521c73" | |
url = "https://api.tigerbot.com/v1/chat/completions" | |
headers = { | |
'Authorization': 'Bearer ' + API_KEY | |
} | |
payload = { | |
"model": "tigerbot-13b-chat", | |
"query": "", | |
"session":[], | |
"internet": True | |
} | |
def getAnsBytiger(t): | |
payload['query'] = t | |
response = requests.post(url, headers=headers, json=payload) | |
res = response.json() | |
res = res["result"] | |
payload['session'].append({"human": t, "assistant": res}) | |
return res | |
if 'prompts' not in st.session_state: | |
st.session_state['prompts'] = [] | |
if 'generated' not in st.session_state: | |
st.session_state['generated'] = [] | |
if 'past' not in st.session_state: | |
st.session_state['past'] = [] | |
def end_click(): | |
st.session_state['prompts'] = [] | |
st.session_state['past'] = [] | |
st.session_state['generated'] = [] | |
st.session_state['user'] = "" | |
def chat_click(): | |
if st.session_state['user'] != '': | |
chat_input = st.session_state['user'] | |
output = getAnsBytiger(chat_input) | |
st.session_state['past'].append(chat_input) | |
st.session_state['generated'].append(output) | |
st.session_state['prompts'].append(output) | |
st.session_state['user'] = "" | |
st.image("./logo.jpg", use_column_width='auto') | |
st.title("珠宝贝专属聊天机器人") | |
user_input = st.text_input("输入:", key="user") | |
chat_button = st.button("发送", on_click=chat_click) | |
end_button = st.button("新聊天", on_click=end_click) | |
if st.session_state['generated']: | |
for i in range(0, len(st.session_state['generated']), 1): | |
message(st.session_state['past'][i], is_user=True) | |
message(st.session_state['generated'][i], key=str(i)) |