Spaces:
Runtime error
Runtime error
Ankur Goyal
commited on
Commit
·
b3797a3
1
Parent(s):
e38e364
Add basic error message if URL fails to download
Browse files
app.py
CHANGED
|
@@ -90,6 +90,7 @@ question_files = {
|
|
| 90 |
|
| 91 |
|
| 92 |
def process_path(path):
|
|
|
|
| 93 |
if path:
|
| 94 |
try:
|
| 95 |
document = load_document(path)
|
|
@@ -100,14 +101,16 @@ def process_path(path):
|
|
| 100 |
gr.update(visible=False, value=None),
|
| 101 |
gr.update(visible=False, value=None),
|
| 102 |
)
|
| 103 |
-
except Exception:
|
| 104 |
traceback.print_exc()
|
|
|
|
| 105 |
return (
|
| 106 |
None,
|
| 107 |
gr.update(visible=False, value=None),
|
| 108 |
gr.update(visible=False),
|
| 109 |
gr.update(visible=False, value=None),
|
| 110 |
gr.update(visible=False, value=None),
|
|
|
|
| 111 |
)
|
| 112 |
|
| 113 |
|
|
@@ -121,6 +124,7 @@ def process_upload(file):
|
|
| 121 |
gr.update(visible=False),
|
| 122 |
gr.update(visible=False, value=None),
|
| 123 |
gr.update(visible=False, value=None),
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
|
|
@@ -265,6 +269,10 @@ gradio-app h2, .gradio-app h2 {
|
|
| 265 |
border-color: #777;
|
| 266 |
font-size: 18px;
|
| 267 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
"""
|
| 269 |
|
| 270 |
with gr.Blocks(css=CSS) as demo:
|
|
@@ -290,14 +298,23 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 290 |
)
|
| 291 |
image = gr.Gallery(visible=False)
|
| 292 |
with gr.Row(equal_height=True):
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
gr.Markdown("— or —")
|
| 302 |
upload = gr.File(label=None, interactive=True, elem_id="short-upload-box")
|
| 303 |
gr.Examples(
|
|
@@ -341,6 +358,7 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 341 |
None,
|
| 342 |
None,
|
| 343 |
None,
|
|
|
|
| 344 |
None,
|
| 345 |
),
|
| 346 |
inputs=clear_button,
|
|
@@ -353,6 +371,7 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 353 |
example_image,
|
| 354 |
upload,
|
| 355 |
url,
|
|
|
|
| 356 |
question,
|
| 357 |
],
|
| 358 |
)
|
|
@@ -360,12 +379,12 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 360 |
upload.change(
|
| 361 |
fn=process_upload,
|
| 362 |
inputs=[upload],
|
| 363 |
-
outputs=[document, image, img_clear_button, output, output_text],
|
| 364 |
)
|
| 365 |
submit.click(
|
| 366 |
fn=process_path,
|
| 367 |
inputs=[url],
|
| 368 |
-
outputs=[document, image, img_clear_button, output, output_text],
|
| 369 |
)
|
| 370 |
|
| 371 |
question.submit(
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
def process_path(path):
|
| 93 |
+
error = None
|
| 94 |
if path:
|
| 95 |
try:
|
| 96 |
document = load_document(path)
|
|
|
|
| 101 |
gr.update(visible=False, value=None),
|
| 102 |
gr.update(visible=False, value=None),
|
| 103 |
)
|
| 104 |
+
except Exception as e:
|
| 105 |
traceback.print_exc()
|
| 106 |
+
error = str(e)
|
| 107 |
return (
|
| 108 |
None,
|
| 109 |
gr.update(visible=False, value=None),
|
| 110 |
gr.update(visible=False),
|
| 111 |
gr.update(visible=False, value=None),
|
| 112 |
gr.update(visible=False, value=None),
|
| 113 |
+
gr.update(visible=True, value=error) if error is not None else None,
|
| 114 |
)
|
| 115 |
|
| 116 |
|
|
|
|
| 124 |
gr.update(visible=False),
|
| 125 |
gr.update(visible=False, value=None),
|
| 126 |
gr.update(visible=False, value=None),
|
| 127 |
+
None,
|
| 128 |
)
|
| 129 |
|
| 130 |
|
|
|
|
| 269 |
border-color: #777;
|
| 270 |
font-size: 18px;
|
| 271 |
}
|
| 272 |
+
|
| 273 |
+
#url-error input {
|
| 274 |
+
color: red;
|
| 275 |
+
}
|
| 276 |
"""
|
| 277 |
|
| 278 |
with gr.Blocks(css=CSS) as demo:
|
|
|
|
| 298 |
)
|
| 299 |
image = gr.Gallery(visible=False)
|
| 300 |
with gr.Row(equal_height=True):
|
| 301 |
+
with gr.Column():
|
| 302 |
+
with gr.Row():
|
| 303 |
+
url = gr.Textbox(
|
| 304 |
+
show_label=False,
|
| 305 |
+
placeholder="URL",
|
| 306 |
+
lines=1,
|
| 307 |
+
max_lines=1,
|
| 308 |
+
elem_id="url-textbox",
|
| 309 |
+
)
|
| 310 |
+
submit = gr.Button("Get")
|
| 311 |
+
url_error = gr.Textbox(
|
| 312 |
+
visible=False,
|
| 313 |
+
elem_id="url-error",
|
| 314 |
+
max_lines=1,
|
| 315 |
+
interactive=False,
|
| 316 |
+
label="Error",
|
| 317 |
+
)
|
| 318 |
gr.Markdown("— or —")
|
| 319 |
upload = gr.File(label=None, interactive=True, elem_id="short-upload-box")
|
| 320 |
gr.Examples(
|
|
|
|
| 358 |
None,
|
| 359 |
None,
|
| 360 |
None,
|
| 361 |
+
gr.update(visible=False, value=None),
|
| 362 |
None,
|
| 363 |
),
|
| 364 |
inputs=clear_button,
|
|
|
|
| 371 |
example_image,
|
| 372 |
upload,
|
| 373 |
url,
|
| 374 |
+
url_error,
|
| 375 |
question,
|
| 376 |
],
|
| 377 |
)
|
|
|
|
| 379 |
upload.change(
|
| 380 |
fn=process_upload,
|
| 381 |
inputs=[upload],
|
| 382 |
+
outputs=[document, image, img_clear_button, output, output_text, url_error],
|
| 383 |
)
|
| 384 |
submit.click(
|
| 385 |
fn=process_path,
|
| 386 |
inputs=[url],
|
| 387 |
+
outputs=[document, image, img_clear_button, output, output_text, url_error],
|
| 388 |
)
|
| 389 |
|
| 390 |
question.submit(
|