Spaces:
Sleeping
Sleeping
Update app.py
Browse files# Bind events AFTER components exist
pdf_input.upload(
load_pdf,
inputs=[pdf_input, state],
outputs=[pdf_status, state, file_selector]
)
remove_button.click(
remove_pdf,
inputs=[file_selector, state],
outputs=[pdf_status, state, file_selector]
)
ask_button.click(
answer_question,
inputs=[question, state],
outputs=answer
)
clear_button.click(lambda: "", outputs=question)
if __name__ == "__main__":
demo.launch(
css=".clear-btn button { height: 100%; min-height: 52px; }"
)
app.py
CHANGED
|
@@ -215,29 +215,59 @@ with gr.Blocks(title="PDF Q&A Chatbot") as demo:
|
|
| 215 |
})
|
| 216 |
|
| 217 |
with gr.Row():
|
|
|
|
| 218 |
with gr.Column(scale=1):
|
| 219 |
pdf_input = gr.Files(label="Upload PDF(s)", file_types=[".pdf"])
|
| 220 |
pdf_status = gr.Textbox(label="Status", interactive=False)
|
| 221 |
|
| 222 |
-
file_selector = gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
remove_button = gr.Button("Remove Selected PDF")
|
| 224 |
|
|
|
|
| 225 |
with gr.Column(scale=2):
|
| 226 |
with gr.Row():
|
| 227 |
-
question = gr.Textbox(
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
answer = gr.Textbox(label="Answer", lines=8)
|
| 231 |
ask_button = gr.Button("Ask")
|
| 232 |
|
| 233 |
# Bind events AFTER components exist
|
| 234 |
-
pdf_input.upload(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
| 238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
|
|
|
| 240 |
|
| 241 |
|
| 242 |
if __name__ == "__main__":
|
| 243 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
| 215 |
})
|
| 216 |
|
| 217 |
with gr.Row():
|
| 218 |
+
# LEFT COLUMN — PDF upload + removal
|
| 219 |
with gr.Column(scale=1):
|
| 220 |
pdf_input = gr.Files(label="Upload PDF(s)", file_types=[".pdf"])
|
| 221 |
pdf_status = gr.Textbox(label="Status", interactive=False)
|
| 222 |
|
| 223 |
+
file_selector = gr.Dropdown(
|
| 224 |
+
label="Remove a PDF",
|
| 225 |
+
choices=[],
|
| 226 |
+
interactive=True
|
| 227 |
+
)
|
| 228 |
remove_button = gr.Button("Remove Selected PDF")
|
| 229 |
|
| 230 |
+
# RIGHT COLUMN — question + clear + answer
|
| 231 |
with gr.Column(scale=2):
|
| 232 |
with gr.Row():
|
| 233 |
+
question = gr.Textbox(
|
| 234 |
+
label="Your question",
|
| 235 |
+
lines=2,
|
| 236 |
+
scale=3
|
| 237 |
+
)
|
| 238 |
+
clear_button = gr.Button(
|
| 239 |
+
"Clear",
|
| 240 |
+
scale=1,
|
| 241 |
+
min_width=80,
|
| 242 |
+
elem_classes="clear-btn"
|
| 243 |
+
)
|
| 244 |
|
| 245 |
answer = gr.Textbox(label="Answer", lines=8)
|
| 246 |
ask_button = gr.Button("Ask")
|
| 247 |
|
| 248 |
# Bind events AFTER components exist
|
| 249 |
+
pdf_input.upload(
|
| 250 |
+
load_pdf,
|
| 251 |
+
inputs=[pdf_input, state],
|
| 252 |
+
outputs=[pdf_status, state, file_selector]
|
| 253 |
+
)
|
| 254 |
|
| 255 |
+
remove_button.click(
|
| 256 |
+
remove_pdf,
|
| 257 |
+
inputs=[file_selector, state],
|
| 258 |
+
outputs=[pdf_status, state, file_selector]
|
| 259 |
+
)
|
| 260 |
|
| 261 |
+
ask_button.click(
|
| 262 |
+
answer_question,
|
| 263 |
+
inputs=[question, state],
|
| 264 |
+
outputs=answer
|
| 265 |
+
)
|
| 266 |
|
| 267 |
+
clear_button.click(lambda: "", outputs=question)
|
| 268 |
|
| 269 |
|
| 270 |
if __name__ == "__main__":
|
| 271 |
+
demo.launch(
|
| 272 |
+
css=".clear-btn button { height: 100%; min-height: 52px; }"
|
| 273 |
+
)
|