Ankur Goyal commited on
Commit ·
d229b67
1
Parent(s): 225fcc2
Adding Examples
Browse files3 unmodified lines45678953 unmodified lines6364656667686970717224 unmodified lines9798991001011021031041051061071081091101111121 unmodified line1141151161171181191201211221231241251263 unmodified linesfrom PIL import ImageDrawimport streamlit as stst.set_page_config(layout="wide")53 unmodified linesif "document" not in st.session_state:st.session_state["document"] = Noneinput_col, model_col = st.columns([2, 1])with input_col:input_type = st.radio("Pick an input type", ["Upload", "URL"], horizontal=True)with model_col:model_type = st.radio("Pick a model", list(CHECKPOINTS.keys()), horizontal=True)24 unmodified linesst.session_state.document = documentif input_type == "Upload":file = st.file_uploader("Upload a PDF or Image document", key="file_input", on_change=load_file_cb)elif input_type == "URL":# url = st.text_input("URL", "", on_change=load_url_callback, key="url_input")url = st.text_input("URL", "", key="url_input", on_change=load_url_cb)question = st.text_input("QUESTION", "")document = st.session_state.documentloading_placeholder = st.empty()1 unmodified linecol1, col2 = st.columns(2)image = document.previewcolors = ["blue", "red", "green"]if document is not None and question is not None and len(question) > 0:col2.header(f"Answers ({model_type})")with col2:answers_placeholder = st.empty()answers_loading_placeholder = st.empty()with answers_loading_placeholder:# Run this (one-time) expensive operation outside of the processing3 unmodified lines4567891053 unmodified lines64656667686970717273747576777824 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641 unmodified line1661671681691701711721731741751761771783 unmodified linesfrom PIL import ImageDrawimport streamlit as stfrom st_clickable_images import clickable_imagesst.set_page_config(layout="wide")53 unmodified linesif "document" not in st.session_state:st.session_state["document"] = Noneif "last_clicked" not in st.session_state:st.session_state["last_clicked"] = Noneinput_col, model_col = st.columns(2)with input_col:input_type = st.radio("Pick an input type", ["Upload", "URL", "Examples"], horizontal=True)with model_col:model_type = st.radio("Pick a model", list(CHECKPOINTS.keys()), horizontal=True)24 unmodified linesst.session_state.document = documentexamples = [("https://templates.invoicehome.com/invoice-template-us-neat-750px.png","What is the invoice number?",),("https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg","What is the purchase amount?",),("https://www.accountingcoach.com/wp-content/uploads/2013/10/income-statement-example@2x.png","What are net sales for 2020?",),]imgs_clicked = []if input_type == "Upload":file = st.file_uploader("Upload a PDF or Image document", key="file_input", on_change=load_file_cb)elif input_type == "URL":url = st.text_input("URL", "", key="url_input", on_change=load_url_cb)elif input_type == "Examples":example_cols = st.columns(len(examples))for (i, (path, question)) in enumerate(examples):with example_cols[i]:imgs_clicked.append(clickable_images([path],div_style={"display": "flex","justify-content": "center","flex-wrap": "wrap","cursor": "pointer",},img_style={"margin": "5px", "height": "200px"},))st.markdown(f"<p style='text-align: center'>{question}</p>",unsafe_allow_html=True,)print(imgs_clicked)imgs_clicked = [-1] * len(imgs_clicked)# clicked = clickable_images(# [x[0] for x in examples],# titles=[x[1] for x in examples],# div_style={"display": "flex", "justify-content": "center", "flex-wrap": "wrap"},# img_style={"margin": "5px", "height": "200px"},# )## st.markdown(f"Image #{clicked} clicked" if clicked > -1 else "No image clicked")question = st.text_input("QUESTION", "", key="question")document = st.session_state.documentloading_placeholder = st.empty()1 unmodified linecol1, col2 = st.columns(2)image = document.previewquestion = st.session_state.questioncolors = ["blue", "red", "green"]if document is not None and question is not None and len(question) > 0:col2.header(f"Answers ({model_type})")with col2:answers_placeholder = st.container()answers_loading_placeholder = st.container()with answers_loading_placeholder:# Run this (one-time) expensive operation outside of the processing
app.py+61-9