Ankur Goyal commited on
Commit ·
87ad231
1
Parent(s): ab36703
Add loading placeholder
Browse files55 unmodified lines565758596061626341 unmodified lines10510610710810911011111211311411511611711811912012112212312455 unmodified linesif "document" not in st.session_state:st.session_state["document"] = Noneinput_type = st.radio("Pick an input type", ["Upload", "URL"], horizontal=True)def load_file_cb():if st.session_state.file_input is None:41 unmodified linescolors = ["blue", "red", "green"]if document is not None and question is not None and len(question) > 0:col2.header("Answers")predictions = run_pipeline(question=question, document=document, top_k=1)word_boxes = lift_word_boxes(document)image = image.copy()draw = ImageDraw.Draw(image)for i, p in enumerate(ensure_list(predictions)):col2.markdown(f"#### { p['answer'] }: ({round(p['score'] * 100, 1)}%)")x1, y1, x2, y2 = normalize_bbox(expand_bbox(word_boxes[p["start"] : p["end"] + 1]),image.width,image.height,)draw.rectangle(((x1, y1), (x2, y2)), outline=colors[i])if document is not None:col1.image(image, use_column_width='auto')55 unmodified lines5657585960616263646566676841 unmodified lines11011111211311411511611711811912012112212312412512612712812913013113213313413555 unmodified linesif "document" not in st.session_state:st.session_state["document"] = Noneinput_col, model_col = st.columns(2)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", ["Upload", "URL"], horizontal=True)def load_file_cb():if st.session_state.file_input is None:41 unmodified linescolors = ["blue", "red", "green"]if document is not None and question is not None and len(question) > 0:col2.header("Answers")with col2:answers_placeholder = st.empty()answers_loading_placeholder = st.empty()with answers_loading_placeholder:with st.spinner("Processing question..."):predictions = run_pipeline(question=question, document=document, top_k=1)with answers_placeholder:word_boxes = lift_word_boxes(document)image = image.copy()draw = ImageDraw.Draw(image)for i, p in enumerate(ensure_list(predictions)):col2.markdown(f"#### { p['answer'] }: ({round(p['score'] * 100, 1)}%)")x1, y1, x2, y2 = normalize_bbox(expand_bbox(word_boxes[p["start"] : p["end"] + 1]),image.width,image.height,)draw.rectangle(((x1, y1), (x2, y2)), outline=colors[i])if document is not None:col1.image(image, use_column_width='auto')
app.py+26-15