Spaces:
Sleeping
Sleeping
import streamlit as st | |
from utils import Recommender | |
import pandas as pd | |
from transformers import RobertaModel | |
st.title("Quotes RecSys") | |
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}) | |