|
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() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=0, |
|
|
|
) |
|
|
|
if prompt == "Custom": |
|
prompt_box = "" |
|
else: |
|
prompt_box = CATEGORY_LIST[prompt] |
|
|
|
items = st.text_area( |
|
'Selected Best Seller Category: ', |
|
prompt_box, |
|
|
|
) |
|
|
|
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=0 |
|
) |
|
|
|
if prompt == "Custom": |
|
prompt_box = "" |
|
else: |
|
prompt_box = LINK_LIST[prompt] |
|
|
|
items = st.text_area( |
|
'Selected Sample Webpage Link: ', |
|
prompt_box, |
|
) |
|
|
|
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=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, |
|
) |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=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(get_brief(DictText)) |
|
|
|
else: |
|
prompt_box = FILE_LIST[prompt] |
|
|
|
items = st.text_area( |
|
'Selected File Name: ', |
|
prompt_box, |
|
) |
|
|
|
|
|
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(get_brief(DictText)) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |