File size: 7,089 Bytes
aaf7f58 ba71aba aaf7f58 |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
import streamlit as st
import meta
import fitz
import requests
from bs4 import BeautifulSoup
from best_seller import get_items
from pharmap_url import get_link_mapped
from summarize import get_summary_app
from results_utils import get_brief, ReadPDFFile, PopulateDict
from utils import load_image_from_local, local_css, pure_comma_separation, remote_css
from examples import CATEGORY_LIST, LINK_LIST, STUDY_LIST, FILE_LIST
with open("bestseller.html", "r") as f:
html_content = f.read()
# html_content[:500]
def main():
st.set_page_config(
page_title="Tracer",
page_icon="👻",
layout="wide",
initial_sidebar_state="expanded"
)
remote_css("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&family=Poppins:wght@600&display=swap")
local_css("asset/css/style.css")
col1, col2 = st.columns([5, 5])
with col2:
# st.image(load_image_from_local("asset/images/main_logo.png"), width=300)
# st.markdown("Discover --> Extract --> Sense --> Decide --> Render", unsafe_allow_html=True)
st.image(load_image_from_local("asset/images/task_theme.png"), width=500)
with st.expander("Design & Development", expanded=True):
st.markdown(meta.SIDEBAR_INFO, unsafe_allow_html=True)
with st.expander("What does Tracer do?", expanded=True):
st.markdown(meta.STORY, unsafe_allow_html=True)
st.markdown(meta.CONCEPT_INFO, unsafe_allow_html=True)
st.image(load_image_from_local("asset/images/side_bar.png"), width=600)
with col1:
st.markdown(meta.HEADER_INFO, unsafe_allow_html=True)
st.markdown(meta.CHEF_INFO, unsafe_allow_html=True)
# st.write('<style>div.row-widget.stRadio > div{flex-direction:row;justify-content: center;} </style>',
# unsafe_allow_html=True)
#
# st.write('<style>div.st-bf{flex-direction:column;} div.st-ag{font-weight:bold;padding-left:2px;}</style>',
# unsafe_allow_html=True)
choose = st.radio("Choose Task", ("Get Best Sellers - Amazon",
"Get Therapy Area Mapped for Given Disease/s",
"Generate Summary for Clinical Trials",
"Generate Financial Brief for given 10-Q file"))
if choose == 'Get Best Sellers - Amazon':
content = BeautifulSoup(html_content, "html.parser")
mydivs = content.find_all("a", {"class": "a-link-normal"})
bs = get_items(mydivs)
prompts = list(CATEGORY_LIST.keys()) + ["Custom"]
prompt = st.selectbox(
'Examples (select from this list)',
prompts,
# index=len(prompts) - 1,
index=0,
)
if prompt == "Custom":
prompt_box = ""
else:
prompt_box = CATEGORY_LIST[prompt]
items = st.text_area(
'Selected Best Seller Category: ',
prompt_box,
)
# items = pure_comma_separation(items, return_list=False)
entered_items = st.empty()
result_button = st.button('Get Best Selling Items!')
st.markdown(
"<hr />",
unsafe_allow_html=True
)
if result_button:
with st.spinner("Getting the best sellers"):
st.write(items)
st.write(bs[items])
if choose == 'Get Therapy Area Mapped for Given Disease/s':
prompts = list(LINK_LIST.keys()) + ["Custom"]
prompt = st.selectbox(
'Examples (select from this list)',
prompts,
# index=len(prompts) - 1,
index=0
)
if prompt == "Custom":
prompt_box = ""
else:
prompt_box = LINK_LIST[prompt]
items = st.text_area(
'Selected Sample Webpage Link: ',
prompt_box,
)
# items = pure_comma_separation(items, return_list=False)
entered_items = st.empty()
result_button = st.button('Get Therapy Areas!')
st.markdown(
"<hr />",
unsafe_allow_html=True
)
if result_button:
get_link_mapped(items)
if choose == 'Generate Summary for Clinical Trials':
prompts = list(STUDY_LIST.keys()) + ["Custom"]
prompt = st.selectbox(
'Examples (select from this list)',
prompts,
# index=len(prompts) - 1,
index=0
)
if prompt == "Custom":
prompt_box = ""
else:
prompt_box = STUDY_LIST[prompt]
items = st.text_area(
'Selected Sample Study ID (Clinical Trial.Gov): ',
prompt_box,
)
# items = pure_comma_separation(items, return_list=False)
# st.write(items)
entered_items = st.empty()
result_button = st.button('Get Summary!')
st.markdown(
"<hr />",
unsafe_allow_html=True
)
if result_button:
headline_output, summary_output = get_summary_app(items)
# headline = f"""
# <p class="story-box font-body">{headline_output}</p>
# """
# summary = f"""
# <p class="story-box font-body">{summary_output}</p>
# """
# st.markdown(summary, unsafe_allow_html=True)
# st.write(headline_output)
st.write(summary_output)
if choose == 'Generate Financial Brief for given 10-Q file':
prompts = list(FILE_LIST.keys()) + ["Custom"]
prompt = st.selectbox(
'Examples (select from this list)',
prompts,
# index=len(prompts) - 1,
index=0
)
if prompt == "Custom":
file = st.file_uploader("Choose a file")
uploaded_file = open(file, 'rb')
doc = fitz.open(uploaded_file)
result_button = st.button('Get Earnings Brief!')
st.markdown(
"<hr />",
unsafe_allow_html=True
)
print("before custom result button")
if result_button and uploaded_file is not None:
with st.spinner("Generating Brief..."):
DictText = {}
Extracttext = ReadPDFFile(doc, 19, "(Dollars in millions except per share amounts)", "")
DictText = PopulateDict(Extracttext, DictText)
Extracttext = ReadPDFFile(doc, 20, "Overview (continued)",
"Results may not sum due to rounding")
DictText = PopulateDict(Extracttext, DictText)
Extracttext = ReadPDFFile(doc, 21, "(Dollars in millions)", "Three months ended")
DictText = PopulateDict(Extracttext, DictText)
# st.write(DictText)
st.write(get_brief(DictText))
else:
prompt_box = FILE_LIST[prompt]
items = st.text_area(
'Selected File Name: ',
prompt_box,
)
# items = pure_comma_separation(items, return_list=False)
# st.write(items)
entered_items = st.empty()
result_button = st.button('Get Earnings Brief!')
st.markdown(
"<hr />",
unsafe_allow_html=True
)
if result_button:
uploaded_file = open("asset/data/TF-Q1'22-10Q.pdf", 'rb')
doc = fitz.open(uploaded_file)
with st.spinner("Generating Brief..."):
DictText = {}
Extracttext = ReadPDFFile(doc, 19, "(Dollars in millions except per share amounts)", "")
DictText = PopulateDict(Extracttext, DictText)
Extracttext = ReadPDFFile(doc, 20, "Overview (continued)",
"Results may not sum due to rounding")
DictText = PopulateDict(Extracttext, DictText)
Extracttext = ReadPDFFile(doc, 21, "(Dollars in millions)", "Three months ended")
DictText = PopulateDict(Extracttext, DictText)
# st.write(DictText)
st.write(get_brief(DictText))
if __name__ == '__main__':
main() |