import streamlit as st from streamlit.components.v1 import components import json from dataclasses import dataclass from typing import Literal from utils import Agent agent = Agent() @dataclass class Message: origin: Literal["human", "ai"] message: str confidence:int def load_css(): with open('./static/style.css') as fp: css = f"" st.markdown(css, unsafe_allow_html=True) def initialize_session_state(): if "history" not in st.session_state: st.session_state.history = [] def on_click_call_back(): human_prompt = st.session_state.human_prompt agent_response, confidence = agent.agent_response(human_prompt) st.session_state.history.append(Message(origin='human', message=human_prompt, confidence=None)) st.session_state.history.append(Message(origin='ai', message=agent_response, confidence=confidence)) st.title("Shopping agent Demo 🤖") load_css() initialize_session_state() chat_placeholder = st.container() prompt_placeholder = st.form(key="chat-form ") with chat_placeholder: for chat in st.session_state.history: msg = f"""
{chat.message}{f'CONFIDENCE : {chat.confidence*100 :0.2f}%' if chat.confidence else ''}
""" st.markdown(msg, unsafe_allow_html=True) with prompt_placeholder: cols_1, cols_2 = st.columns((6,1)) with cols_1: st.text_input(label="Chat", value="Hello bot", label_visibility="collapsed", key="human_prompt") with cols_2: st.form_submit_button(label="Submit", type="primary", on_click=on_click_call_back) # components.html(""" # # """, # height=0, # width=0, # )