Ankur Goyal commited on
Commit
87ad231
1 Parent(s): ab36703

Add loading placeholder

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -56,8 +56,13 @@ st.markdown("# DocQuery: Query Documents w/ NLP")
56
  if "document" not in st.session_state:
57
  st.session_state["document"] = None
58
 
59
- input_type = st.radio("Pick an input type", ["Upload", "URL"], horizontal=True)
60
 
 
 
 
 
 
61
 
62
  def load_file_cb():
63
  if st.session_state.file_input is None:
@@ -105,20 +110,26 @@ if document is not None:
105
  colors = ["blue", "red", "green"]
106
  if document is not None and question is not None and len(question) > 0:
107
  col2.header("Answers")
108
-
109
- predictions = run_pipeline(question=question, document=document, top_k=1)
110
-
111
- word_boxes = lift_word_boxes(document)
112
- image = image.copy()
113
- draw = ImageDraw.Draw(image)
114
- for i, p in enumerate(ensure_list(predictions)):
115
- col2.markdown(f"#### { p['answer'] }: ({round(p['score'] * 100, 1)}%)")
116
- x1, y1, x2, y2 = normalize_bbox(
117
- expand_bbox(word_boxes[p["start"] : p["end"] + 1]),
118
- image.width,
119
- image.height,
120
- )
121
- draw.rectangle(((x1, y1), (x2, y2)), outline=colors[i])
 
 
 
 
 
 
122
 
123
  if document is not None:
124
  col1.image(image, use_column_width='auto')
 
56
  if "document" not in st.session_state:
57
  st.session_state["document"] = None
58
 
59
+ input_col, model_col = st.columns(2)
60
 
61
+ with input_col:
62
+ input_type = st.radio("Pick an input type", ["Upload", "URL"], horizontal=True)
63
+
64
+ with model_col:
65
+ model_type = st.radio("Pick a model", ["Upload", "URL"], horizontal=True)
66
 
67
  def load_file_cb():
68
  if st.session_state.file_input is None:
 
110
  colors = ["blue", "red", "green"]
111
  if document is not None and question is not None and len(question) > 0:
112
  col2.header("Answers")
113
+ with col2:
114
+ answers_placeholder = st.empty()
115
+ answers_loading_placeholder = st.empty()
116
+
117
+ with answers_loading_placeholder:
118
+ with st.spinner("Processing question..."):
119
+ predictions = run_pipeline(question=question, document=document, top_k=1)
120
+
121
+ with answers_placeholder:
122
+ word_boxes = lift_word_boxes(document)
123
+ image = image.copy()
124
+ draw = ImageDraw.Draw(image)
125
+ for i, p in enumerate(ensure_list(predictions)):
126
+ col2.markdown(f"#### { p['answer'] }: ({round(p['score'] * 100, 1)}%)")
127
+ x1, y1, x2, y2 = normalize_bbox(
128
+ expand_bbox(word_boxes[p["start"] : p["end"] + 1]),
129
+ image.width,
130
+ image.height,
131
+ )
132
+ draw.rectangle(((x1, y1), (x2, y2)), outline=colors[i])
133
 
134
  if document is not None:
135
  col1.image(image, use_column_width='auto')