Spaces:
Sleeping
Sleeping
File size: 1,411 Bytes
2872c06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
from streamlit_chat import message
import requests
API_URL = "https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill"
API_TOKEN = "YOUR API TOKEN HERE"
headers = {"Authorization": f"Bearer {API_TOKEN}"}
st.header("🤖Yunwoong's BlenderBot (Demo)")
st.markdown("[Be Original](https://yunwoong.tistory.com/)")
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
with st.form('form', clear_on_submit=True):
user_input = st.text_input('You: ', '', key='input')
submitted = st.form_submit_button('Send')
if submitted and user_input:
output = query({
"inputs": {
"past_user_inputs": st.session_state.past,
"generated_responses": st.session_state.generated,
"text": user_input,
},
"parameters": {"repetition_penalty": 1.33},
})
st.session_state.past.append(user_input)
st.session_state.generated.append(output["generated_text"])
if st.session_state['generated']:
for i in range(len(st.session_state['generated'])-1, -1, -1):
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
message(st.session_state["generated"][i], key=str(i))
|