File size: 2,684 Bytes
96dad0a
353edf3
96dad0a
 
353edf3
 
 
 
637ab98
353edf3
ef2f1a5
353edf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df844ea
353edf3
 
 
a531f4b
 
353edf3
 
 
 
 
a531f4b
353edf3
a531f4b
353edf3
 
 
a531f4b
353edf3
 
 
 
 
 
 
d8143c9
4adc02d
d8143c9
353edf3
d8143c9
353edf3
 
 
ef2f1a5
353edf3
 
ef2f1a5
353edf3
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
from src.buildgraph import run_workflow
import time

st.set_page_config(page_title="LawGPT")
col1, col2, col3 = st.columns([1,4,1])
with col2:
    st.image("assets/Black Bold Initial AI Business Logo.jpg")

st.markdown(
    """
    <style>
    .stApp, .ea3mdgi6{
      background-color:#000000;
    }
    div.stButton > button:first-child {
        background-color: #ffd0d0;
    }
    div.stButton > button:active {
        # background-color: #ff6262;
    }
    div[data-testid="stStatusWidget"] div button {
        display: none;
    }
    .reportview-container {
        margin-top: -2em;
    }
    #MainMenu {visibility: hidden;}
    .stDeployButton {display:none;}
    footer {visibility: hidden;}
    #stDecoration {display:none;}
    button[title="View fullscreen"]{
        visibility: hidden;
    }
    button:first-child{
        background-color : transparent !important;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

st.title("AI Chatbot")

# Initialize chat history and thread_id
if "messages" not in st.session_state:
    st.session_state.messages = []
if "thread_id" not in st.session_state:
    st.session_state.thread_id = "streamlit_thread"

config = {"recursion_limit": 8, "configurable": {"thread_id": st.session_state.thread_id}}

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message['role']):
        st.markdown(message['content'])

# React to user input
if prompt := st.chat_input("What is your question?"):
    # Display user message in chat message container
    st.chat_message("user").markdown(prompt)
    user_message = {"role": "user", "content": prompt}
    # Add user message to chat history
    st.session_state.messages.append(user_message)

    response = run_workflow(prompt, config)
    response_content = response.get("generation", "I'm sorry, I couldn't generate a response.")

    
    # Display assistant response in chat message container
    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        full_response = "⚠️ **_Note: Information provided may be inaccurate._** \n\n\n"
        for char in response_content:
            full_response += char
            
            time.sleep(0.03)
            message_placeholder.markdown(full_response + "|")
        message_placeholder.markdown(full_response)
        print(full_response)
    
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": full_response})

def reset_conversation():
    st.session_state.messages = []

st.button('Reset All Chat 🗑️', on_click=reset_conversation)