Spaces:
Build error
Build error
Ilia Tambovtsev commited on
Commit ·
3db0398
1
Parent(s): eb1873f
feat: implement gradio interface with adjustments to prerendered elements
Browse files- src/webapp/app.py +70 -47
src/webapp/app.py
CHANGED
|
@@ -178,57 +178,80 @@ class RagInterface:
|
|
| 178 |
return new_results
|
| 179 |
|
| 180 |
# Wire up the search function
|
| 181 |
-
search_btn.click(
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
)
|
| 186 |
|
| 187 |
# Results container
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
#
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
# display_results(results)
|
| 231 |
-
app.launch(**kwargs)
|
| 232 |
|
| 233 |
|
| 234 |
def run_app(store: ChromaSlideStore, **kwargs):
|
|
|
|
| 178 |
return new_results
|
| 179 |
|
| 180 |
# Wire up the search function
|
| 181 |
+
# search_btn.click(
|
| 182 |
+
# fn=update_results,
|
| 183 |
+
# inputs={query, n_pres, n_pages, max_distance, results},
|
| 184 |
+
# outputs=results
|
| 185 |
+
# )
|
| 186 |
|
| 187 |
# Results container
|
| 188 |
+
result_components = []
|
| 189 |
+
n_results = 10
|
| 190 |
+
for i in range(n_results):
|
| 191 |
+
with gr.Group() as g:
|
| 192 |
+
with gr.Tabs():
|
| 193 |
+
# Create 3 identical result tabs
|
| 194 |
+
with gr.Tab(f"Result {i+1}"):
|
| 195 |
+
with gr.Column():
|
| 196 |
+
# PDF viewer
|
| 197 |
+
pdf = PDF(
|
| 198 |
+
# value=str(pdf_path),
|
| 199 |
+
# Pages are 0-based in store but 1-based in PDFvalue=result
|
| 200 |
+
# starting_page=page + 1,
|
| 201 |
+
label="Presentation",
|
| 202 |
+
height=self.output_height,
|
| 203 |
+
interactive=False,
|
| 204 |
+
container=False,
|
| 205 |
+
visible=True,
|
| 206 |
+
)
|
| 207 |
+
certainty = gr.Markdown() # value="#### very certain"
|
| 208 |
+
# result_tab = [pdf, certainty]
|
| 209 |
+
|
| 210 |
+
with gr.Tab(f"Details"):
|
| 211 |
+
# Results text
|
| 212 |
+
with gr.Column(variant="panel"):
|
| 213 |
+
details_text = gr.Markdown(
|
| 214 |
+
# value=text,
|
| 215 |
+
label="Search Results",
|
| 216 |
+
height=self.output_height,
|
| 217 |
+
visible=True,
|
| 218 |
+
)
|
| 219 |
+
details_tab = [details_text]
|
| 220 |
+
result_components.extend([g, pdf, certainty, details_text])
|
| 221 |
+
|
| 222 |
+
def fill_components(inputs):
|
| 223 |
+
new_results = self.store.search_query_presentations(
|
| 224 |
+
query=inputs[query],
|
| 225 |
+
n_results=inputs[n_pres],
|
| 226 |
+
max_distance=inputs[max_distance],
|
| 227 |
+
n_slides_per_presentation=inputs[n_pages],
|
| 228 |
+
)
|
| 229 |
+
outputs = []
|
| 230 |
+
for i in range(10):
|
| 231 |
+
if i < len(new_results):
|
| 232 |
+
r = new_results[i]
|
| 233 |
+
text, pdf_path, page = format_presentation_results(r)
|
| 234 |
+
visible = True
|
| 235 |
+
pdf = PDF(value=str(pdf_path), starting_page=page+1)
|
| 236 |
+
certainty = gr.Markdown(value="## GOOD")
|
| 237 |
+
description = gr.Markdown(value=text)
|
| 238 |
+
else:
|
| 239 |
+
visible = False
|
| 240 |
+
pdf = PDF(visible=False)
|
| 241 |
+
certainty = gr.Markdown(visible=False)
|
| 242 |
+
description = gr.Markdown(visible=False)
|
| 243 |
+
outputs.extend([pdf, certainty, description])
|
| 244 |
+
|
| 245 |
+
return outputs
|
| 246 |
|
| 247 |
+
# Wire up the search function
|
| 248 |
+
search_btn.click(
|
| 249 |
+
fn=fill_components,
|
| 250 |
+
inputs={query, n_pres, n_pages, max_distance, results},
|
| 251 |
+
outputs=result_components
|
| 252 |
+
)
|
| 253 |
# display_results(results)
|
| 254 |
+
app.launch(ssr_mode=False, **kwargs)
|
| 255 |
|
| 256 |
|
| 257 |
def run_app(store: ChromaSlideStore, **kwargs):
|