|
import os |
|
import streamlit as st |
|
import chatbot as demo_chat |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
from langchain.schema import ( |
|
HumanMessage, |
|
SystemMessage, |
|
) |
|
from langchain_community.chat_models.huggingface import ChatHuggingFace |
|
|
|
st.title("Hi, I am Chatbot Philio :mermaid:") |
|
st.write("I am your hotel booking assistant for today.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model = demo_chat.load_model() |
|
token = os.getenv('HUGGINGFACEHUB_API_TOKEN') |
|
|
|
chat_model = ChatHuggingFace(llm=model, token=token) |
|
print(chat_model.model_id) |
|
|
|
|
|
with st.container(): |
|
st.markdown('<div class="scrollable-div">', unsafe_allow_html=True) |
|
|
|
if 'memory' not in st.session_state: |
|
st.session_state.memory = demo_chat.demo_miny_memory(chat_model) |
|
|
|
|
|
if 'chat_history' not in st.session_state: |
|
st.session_state.chat_history = [ ] |
|
|
|
if 'model' not in st.session_state: |
|
st.write("Model added in state.") |
|
st.session_state.model = model |
|
|
|
|
|
for message in st.session_state.chat_history: |
|
with st.chat_message(message["role"]): |
|
st.write(message["content"]) |
|
|
|
chat_model._to_chat_prompt(st.session_state.chat_history) |
|
|
|
|
|
input_text = st.chat_input(placeholder="Here you can chat with our hotel booking model.") |
|
|
|
if input_text: |
|
with st.chat_message("user"): |
|
st.write(input_text) |
|
st.session_state.chat_history.append({"role" : "user", "content" : input_text}) |
|
|
|
chat_response = demo_chat.demo_chain(input_text=input_text, memory=st.session_state.memory, model= chat_model) |
|
first_answer = chat_response.split("Human")[0] |
|
|
|
with st.chat_message("assistant"): |
|
st.write(first_answer) |
|
st.session_state.chat_history.append({"role": "assistant", "content": first_answer}) |
|
st.markdown('</div>', unsafe_allow_html=True) |