-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtml_templates.py
More file actions
61 lines (60 loc) · 1.62 KB
/
html_templates.py
File metadata and controls
61 lines (60 loc) · 1.62 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
import os
import base64
css = '''
<style>
.chat-message {
padding: 1.5rem; border-radius: 0.5rem; margin-bottom: 1rem; display: flex
}
.chat-message.user {
background-color: #2b313e
}
.chat-message.bot {
background-color: #475063
}
.chat-message .avatar {
width: 78px;
height: 78px;
flex-shrink: 0;
}
.chat-message .avatar img {
max-width: 78px;
max-height: 78px;
border-radius: 50%;
object-fit: cover;
}
.chat-message .message {
width: 100%;
padding: 0 1.5rem;
color: #fff;
}
'''
def get_base64_image(image_path):
with open(image_path, "rb") as img_file:
return "data:image/jpeg;base64," + base64.b64encode(img_file.read()).decode()
def get_bot_template(MSG):
image_src = get_base64_image("icons/New_AI_Avatar.jpeg")
bot_template = f'''
<div class="chat-message bot">
<div class="avatar">
<img src="{image_src}" style="max-height: 78px; max-width: 78px; border-radius: 50%; object-fit: cover;">
</div>
<div class="message">{MSG}</div>
</div>
'''
return bot_template
def get_user_template(MSG):
# if os.path.exists("image.txt"):
# with open("image.txt", "r") as f:
# img_src = f.read()
# else:
# img_src = "https://i.ibb.co/rdZC7LZ/Photo-logo-1.png"
image_src = get_base64_image("icons/New_User_Avatar.png")
user_template = f'''
<div class="chat-message user">
<div class="avatar">
<img src="{image_src}" width="350" alt="Grab Vector Graphic Person Icon | imagebasket" /></a>
</div>
<div class="message">{MSG}</div>
</div>
'''
return user_template