-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
74 lines (58 loc) · 2.32 KB
/
app.py
File metadata and controls
74 lines (58 loc) · 2.32 KB
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
import streamlit as st
from core import chatbot
from langchain_core.messages import HumanMessage
st.set_page_config(page_title="Aiswarya’s AI Assistant", page_icon="🤖", layout="wide")
# Custom CSS for wider layout and better styling
st.markdown("""
<style>
.main {
max-width: 1000px;
margin: 0 auto;
padding: 0rem;
}
.title {
font-size: 34px;
font-weight: bold;
text-align: center;
color: #FF4B4B;
}
.subtitle {
font-size: 20px;
text-align: center;
color: #bbbbbb;
}
</style>
""", unsafe_allow_html=True)
st.markdown('<div class="title">Aiswarya’s AI Assistant 🤖</div>', unsafe_allow_html=True)
st.markdown('<div class="subtitle">Ask anything about Aiswarya Baby’s profile, skills, projects, or experience</div>', unsafe_allow_html=True)
st.markdown("---")
# st.session_state -> dict ->
CONFIG = {'configurable': {'thread_id': 'thread-1'}}
if 'message_history' not in st.session_state:
st.session_state['message_history'] = []
# loading the conversation history
for msg in st.session_state['message_history']:
with st.chat_message(msg['role']):
st.text(msg['content'])
user_input = st.chat_input('Type here')
if user_input:
# first add the message to message_history
st.session_state['message_history'].append({'role': 'user', 'content': user_input})
with st.chat_message('user'):
st.text(user_input)
# response = chatbot.invoke({'messages': [HumanMessage(content=user_input)]}, config=CONFIG)
# ai_message = response['messages'][-1].content
# # first add the message to message_history
# st.session_state['message_history'].append({'role': 'assistant', 'content': ai_message})
# with st.chat_message('assistant'):
# st.text(ai_message)
# Streaming
with st.chat_message('assistant'):
ai_message = st.write_stream(
message_chunk.content for message_chunk, metadata in chatbot.stream(
{'messages': [HumanMessage(content=user_input)]},
config= {'configurable': {'thread_id': 'thread-1'}},
stream_mode= 'messages'
)
)
st.session_state['message_history'].append({'role': 'assistant', 'content': ai_message})