Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -357,7 +357,7 @@ MODEL_OPTIONS = [
|
|
| 357 |
]
|
| 358 |
|
| 359 |
with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
| 360 |
-
# We
|
| 361 |
session_state = gr.State({})
|
| 362 |
|
| 363 |
# ─── Welcome Screen ─────────────────────────────────────────────
|
|
@@ -407,9 +407,17 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
| 407 |
label="Vision-Language Model"
|
| 408 |
)
|
| 409 |
extract_btn = gr.Button("Extract")
|
| 410 |
-
preview_text = gr.Textbox(
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
extract_btn.click(
|
| 415 |
fn=extract_data_from_pdfs,
|
|
@@ -422,10 +430,10 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
| 422 |
vlm_dd
|
| 423 |
],
|
| 424 |
outputs=[
|
| 425 |
-
session_state,
|
| 426 |
-
preview_text,
|
| 427 |
-
preview_img,
|
| 428 |
-
preview_html
|
| 429 |
]
|
| 430 |
)
|
| 431 |
|
|
@@ -434,7 +442,7 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
| 434 |
with gr.Row():
|
| 435 |
with gr.Column(scale=3):
|
| 436 |
chat = gr.Chatbot(type="messages", label="Chat")
|
| 437 |
-
msg
|
| 438 |
placeholder="Ask about your PDF...",
|
| 439 |
label="Your question"
|
| 440 |
)
|
|
@@ -447,13 +455,13 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
| 447 |
)
|
| 448 |
num_ctx = gr.Slider(1, 20, value=3, label="Text Contexts")
|
| 449 |
img_ctx = gr.Slider(1, 10, value=2, label="Image Contexts")
|
| 450 |
-
temp
|
| 451 |
max_tok = gr.Slider(10, 1000, step=10, value=200, label="Max Tokens")
|
| 452 |
|
| 453 |
send.click(
|
| 454 |
fn=conversation,
|
| 455 |
inputs=[
|
| 456 |
-
session_state, #
|
| 457 |
msg,
|
| 458 |
num_ctx,
|
| 459 |
img_ctx,
|
|
@@ -464,7 +472,7 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
|
| 464 |
],
|
| 465 |
outputs=[
|
| 466 |
chat,
|
| 467 |
-
gr.Dataframe(),
|
| 468 |
gr.Gallery(label="Relevant Images", rows=2, value=[])
|
| 469 |
]
|
| 470 |
)
|
|
|
|
| 357 |
]
|
| 358 |
|
| 359 |
with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
|
| 360 |
+
# We only need a single State to track whether extraction has happened
|
| 361 |
session_state = gr.State({})
|
| 362 |
|
| 363 |
# ─── Welcome Screen ─────────────────────────────────────────────
|
|
|
|
| 407 |
label="Vision-Language Model"
|
| 408 |
)
|
| 409 |
extract_btn = gr.Button("Extract")
|
| 410 |
+
preview_text = gr.Textbox(
|
| 411 |
+
lines=10,
|
| 412 |
+
label="Sample Text",
|
| 413 |
+
interactive=False
|
| 414 |
+
)
|
| 415 |
+
preview_img = gr.Gallery(
|
| 416 |
+
label="Sample Images",
|
| 417 |
+
rows=2,
|
| 418 |
+
value=[]
|
| 419 |
+
)
|
| 420 |
+
preview_html = gr.HTML()
|
| 421 |
|
| 422 |
extract_btn.click(
|
| 423 |
fn=extract_data_from_pdfs,
|
|
|
|
| 430 |
vlm_dd
|
| 431 |
],
|
| 432 |
outputs=[
|
| 433 |
+
session_state, # updates processed flag
|
| 434 |
+
preview_text, # shows sample text
|
| 435 |
+
preview_img, # shows sample images
|
| 436 |
+
preview_html # shows “Done!” message
|
| 437 |
]
|
| 438 |
)
|
| 439 |
|
|
|
|
| 442 |
with gr.Row():
|
| 443 |
with gr.Column(scale=3):
|
| 444 |
chat = gr.Chatbot(type="messages", label="Chat")
|
| 445 |
+
msg = gr.Textbox(
|
| 446 |
placeholder="Ask about your PDF...",
|
| 447 |
label="Your question"
|
| 448 |
)
|
|
|
|
| 455 |
)
|
| 456 |
num_ctx = gr.Slider(1, 20, value=3, label="Text Contexts")
|
| 457 |
img_ctx = gr.Slider(1, 10, value=2, label="Image Contexts")
|
| 458 |
+
temp = gr.Slider(0.1, 1.0, step=0.1, value=0.4, label="Temperature")
|
| 459 |
max_tok = gr.Slider(10, 1000, step=10, value=200, label="Max Tokens")
|
| 460 |
|
| 461 |
send.click(
|
| 462 |
fn=conversation,
|
| 463 |
inputs=[
|
| 464 |
+
session_state, # drives conversation
|
| 465 |
msg,
|
| 466 |
num_ctx,
|
| 467 |
img_ctx,
|
|
|
|
| 472 |
],
|
| 473 |
outputs=[
|
| 474 |
chat,
|
| 475 |
+
gr.Dataframe(), # returns the retrieved docs
|
| 476 |
gr.Gallery(label="Relevant Images", rows=2, value=[])
|
| 477 |
]
|
| 478 |
)
|