-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_st_chat.py
83 lines (68 loc) · 2.31 KB
/
sample_st_chat.py
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
# streamlit basic code:
import streamlit as st
import pandas as pd
import numpy as np
# ---------------------------------------------------------------------------------------
# Required Classes:
# ---------------------------------------------------------------------------------------
class media:
def __init__(self, type=None, path=None):
self.type = type
self.path = path
if not type:
self.isAvailable = False
else:
self.isAvailable = True
def get_media(self):
if self.type == 'image':
a, b = st.columns([0.8, 9.2])
with a:
st.write("")
with b:
st.image(self.path, width=450)
elif self.type == 'audio':
return st.audio(self.path)
elif self.type == 'video':
return st.video(self.path)
else:
return None
if 'messages' not in st.session_state:
st.session_state.messages = [
{
"role": "Bot",
"content": "Hello 👋, How may I help you?",
"media": media()
},
{
"role": "User",
"content": "This is my query",
"media": media("image", "./assets/visualization.png")},
{
"role": "Bot",
"content": "Just google it 😁",
"media": media()},
{
"role": "User",
"content": "Timepass media content:",
"media": media("image", "https://plus.unsplash.com/premium_photo-1664474619075-644dd191935f")
}
]
st.subheader(':blue[GenAI Assistant Local] ✨', divider='rainbow')
inp = st.chat_input('Your message')
# st.write(st.session_state.messages)
if inp:
st.session_state.messages.append(
{"role": "User", "content": inp, "media": media()})
st.session_state.messages.append(
{"role": "Bot", "content": f"Same: {inp} 😹", "media": media()})
# with st.chat_message("user"):
# st.write("Hello 👋")
for message in st.session_state.messages:
if message['role'].lower() == 'user':
with st.chat_message("user", avatar='🕵️'):
st.write(message['content'])
else:
with st.chat_message("ai"):
st.write(message['content'])
if message['media'].isAvailable:
message['media'].get_media()