KalooAI commited on
Commit
2c7e565
·
verified ·
1 Parent(s): 40024c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -203,30 +203,35 @@ def answer_question(question, state):
203
  # GRADIO UI
204
  # ============================================================
205
 
206
- with gr.Blocks(
207
- title="PDF Q&A Chatbot",
208
- css=".clear-btn button { height: 100%; min-height: 52px; }"
209
- ) as demo:
210
-
211
- gr.Markdown("## 📄 PDF Q&A Chatbot\nUpload a PDF and ask questions about its content.")
212
 
213
- state = gr.State({"chunks": [], "index": None, 'pdf_count':0})
 
 
 
 
 
214
 
215
  with gr.Row():
216
  with gr.Column(scale=1):
217
  pdf_input = gr.Files(label="Upload PDF(s)", file_types=[".pdf"])
218
  pdf_status = gr.Textbox(label="Status", interactive=False)
219
 
 
 
 
220
  with gr.Column(scale=2):
221
  with gr.Row():
222
- question = gr.Textbox(label="Your question", lines=2, scale =4)
223
  clear_button = gr.Button("Clear", scale=1, min_width=80, elem_classes="clear-btn")
224
-
225
  answer = gr.Textbox(label="Answer", lines=8)
226
  ask_button = gr.Button("Ask")
227
-
228
 
229
- pdf_input.upload(load_pdf, inputs=[pdf_input, state], outputs=[pdf_status, state, file_selector])
 
230
 
231
  ask_button.click(answer_question, inputs=[question, state], outputs=answer)
232
  clear_button.click(lambda: "", outputs=question)
 
203
  # GRADIO UI
204
  # ============================================================
205
 
206
+ with gr.Blocks(title="PDF Q&A Chatbot") as demo:
207
+
208
+ gr.Markdown("## 📄 PDF Q&A Chatbot\nUpload PDFs and ask questions about their content.")
 
 
 
209
 
210
+ state = gr.State({
211
+ "chunks": [],
212
+ "index": None,
213
+ "pdf_count": 0,
214
+ "files": {}
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(label="Remove a PDF", choices=[], interactive=True)
223
+ remove_button = gr.Button("Remove Selected PDF")
224
+
225
  with gr.Column(scale=2):
226
  with gr.Row():
227
+ question = gr.Textbox(label="Your question", lines=2, scale=3)
228
  clear_button = gr.Button("Clear", scale=1, min_width=80, elem_classes="clear-btn")
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(load_pdf, inputs=[pdf_input, state], outputs=[pdf_status, state,
235
 
236
  ask_button.click(answer_question, inputs=[question, state], outputs=answer)
237
  clear_button.click(lambda: "", outputs=question)