Spaces:
Build error
Build error
Ankur Goyal
commited on
Commit
•
87ad231
1
Parent(s):
ab36703
Add loading placeholder
Browse files
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 |
-
|
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 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
)
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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')
|