File size: 1,126 Bytes
50bcd75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68858a7
50bcd75
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from utils import Recommender
import pandas as pd
from transformers import RobertaModel

st.title("Quotes RecSys")

@st.cache_resource
def get_recommender():
    return Recommender(pd.read_csv('data/quotes.csv'),
                "cardiffnlp/twitter-roberta-base-emotion-multilabel-latest",
                base_model=RobertaModel, ckpt="models/twitter.pt")


recommender = get_recommender()

if "messages" not in st.session_state:
    st.session_state.messages = []

for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

if prompt := st.chat_input("How was your day?"):
    st.session_state.messages.append({"role": "user", "content": prompt})
    with st.chat_message("user"):
        st.markdown(prompt)

    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        quote, author = recommender.recommend(prompt)
        full_response = f"> {quote}\n\n _{author}_"
        message_placeholder.markdown(full_response)
    st.session_state.messages.append({"role": "assistant", "content": full_response})