|
import os |
|
import streamlit as st |
|
import chatbot as demo_chat |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
st.title("Hi, I am Chatbot Philio :woman:") |
|
st.write("I am your hotel booking assistant. Feel free to start chatting with me.") |
|
|
|
scrollable_div_style = """ |
|
<style> |
|
.scrollable-div { |
|
height: 200px; /* Adjust the height as needed */ |
|
overflow-y: auto; /* Enable vertical scrolling */ |
|
padding: 5px; |
|
border: 1px solid #ccc; /* Optional: adds a border around the div */ |
|
border-radius: 5px; /* Optional: rounds the corners of the border */ |
|
} |
|
</style> |
|
""" |
|
|
|
def render_chat_history(chat_history): |
|
|
|
for message in chat_history: |
|
if(message["role"]!= "system"): |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system_content = """ |
|
You are an AI having conversation with a human. Below is an instruction that describes a task. |
|
Write a response that appropriately completes the request. |
|
Reply with the most helpful and logic answer. During the conversation you need to ask the user |
|
the following questions to complete the hotel booking task. |
|
|
|
1) Where would you like to stay and when? |
|
2) How many people are staying in the room? |
|
3) Do you prefer any ammenities like breakfast included or gym? |
|
4) What is your name, your email address and phone number? |
|
|
|
Make sure you receive a logical answer from the user from every question to complete the hotel |
|
booking process. |
|
""" |
|
|
|
if 'chat_history' not in st.session_state: |
|
st.session_state.chat_history = [ |
|
{ |
|
"role": "system", |
|
"content": system_content, |
|
}, |
|
{"role": "ai", "content": "Hello, how can I help you today?"}, |
|
] |
|
|
|
|
|
|
|
|
|
st.markdown('<div class="scrollable-div">', unsafe_allow_html=True) |
|
render_chat_history(st.session_state.chat_history) |
|
|
|
|
|
if input_text := st.chat_input(placeholder="Here you can chat with our hotel booking model."): |
|
|
|
with st.chat_message("user"): |
|
st.markdown(input_text) |
|
st.session_state.chat_history.append({"role" : "human", "content" : input_text}) |
|
|
|
with st.spinner("Generating response..."): |
|
first_answer = demo_chat.demo_chain(input_text = input_text, history = st.session_state.chat_history) |
|
|
|
with st.chat_message("assistant"): |
|
st.markdown(first_answer) |
|
st.session_state.chat_history.append({"role": "ai", "content": first_answer}) |
|
st.markdown('</div>', unsafe_allow_html=True) |