-
Notifications
You must be signed in to change notification settings - Fork 95
/
render.py
73 lines (64 loc) · 2.57 KB
/
render.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
import streamlit as st
import re
bot_msg_container_html_template = '''
<div style='background-color: #FFFFFF; padding: 10px; border-radius: 5px; margin-bottom: 10px; display: flex'>
<div style="width: 20%; display: flex; justify-content: center">
<img src="https://yt3.googleusercontent.com/ixwBtVrollE0Z5nA5YPHrnkKQoK09Evbe4gWCvJlleB2rFERDz3m2Jynhc3sGBE-EnzbH6ov=s176-c-k-c0x00ffffff-no-rj" style="max-height: 50px; max-width: 50px; border-radius: 50%;">
</div>
<div style="width: 80%;">
$MSG
</div>
</div>
'''
user_msg_container_html_template = '''
<div style='background-color: #FFFFFF; padding: 10px; border-radius: 5px; margin-bottom: 10px; display: flex'>
<div style="width: 78%">
$MSG
</div>
<div style="width: 20%; margin-left: auto; display: flex; justify-content: center;">
<img src="https://yt3.googleusercontent.com/w3Hwj4_weJ_tx9z79ffwCmaAU3eHPuJ5nvk_QDmNyxcbNdTaBBAIxenUXGybyUjLE4ktVKqyEA=s176-c-k-c0x00ffffff-no-rj" style="max-width: 50px; max-height: 50px; float: right; border-radius: 50%;">
</div>
</div>
'''
def render_article_preview(docs, tickers):
message = f"<h5>Here are relevant articles for {tickers} that may answer your question. </h5>"
message += "<div>"
for d in docs:
elipse = " ".join(d[2].split(" ")[:140])
message += f"<br><a href='{d[1]}'>{d[0]}</a></br>"
message += f"<p>{elipse} ...</p>"
message += "<br>"
message += "</div>"
return message
def render_earnings_summary(ticker, summary):
transcript_title = summary["transcript_title"]
message = f"<h5>Here is summary for {ticker} {transcript_title} </h5>"
message += "<div>"
body = re.sub(r'^-', r'* ', summary["summary"])
body = re.sub(r'\$', r'\\$', body)
message += f"<p>{body}</p>"
message += "</div>"
return message
def render_stock_question(answer, articles):
message = "<div>"
message += f"{answer} <br>"
message += "Sources: "
for a in articles:
message += f"<a href='{a[1]}'>{a[0]}</a><br>"
message += "</div>"
return message
def render_chat(**kwargs):
"""
Handles is_user
"""
if kwargs["is_user"]:
st.write(
user_msg_container_html_template.replace("$MSG", kwargs["message"]),
unsafe_allow_html=True)
else:
st.write(
bot_msg_container_html_template.replace("$MSG", kwargs["message"]),
unsafe_allow_html=True)
if "figs" in kwargs:
for f in kwargs["figs"]:
st.plotly_chart(f, use_container_width=True)