Spaces:
Runtime error
Runtime error
Commit ยท
2ab48f0
1
Parent(s): 8403dde
Add existing PDF ID chat option
Browse files- gradio_app.py +16 -0
gradio_app.py
CHANGED
|
@@ -117,6 +117,11 @@ with gr.Blocks(title="PageIndex RAG Chatbot", theme=gr.themes.Soft()) as demo:
|
|
| 117 |
upload_btn = gr.Button("Upload PDF")
|
| 118 |
upload_status = gr.Textbox(label="Status", interactive=False)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
gr.Markdown("### ๐๏ธ Delete PDF")
|
| 121 |
delete_input = gr.Textbox(label="PDF ID to Delete")
|
| 122 |
delete_btn = gr.Button("Delete PDF")
|
|
@@ -136,12 +141,23 @@ with gr.Blocks(title="PageIndex RAG Chatbot", theme=gr.themes.Soft()) as demo:
|
|
| 136 |
)
|
| 137 |
|
| 138 |
# Event handling
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
upload_btn.click(
|
| 140 |
fn=upload_pdf_file,
|
| 141 |
inputs=[pdf_input],
|
| 142 |
outputs=[upload_status, pdf_id_state]
|
| 143 |
)
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
delete_btn.click(
|
| 146 |
fn=delete_pdf,
|
| 147 |
inputs=[delete_input],
|
|
|
|
| 117 |
upload_btn = gr.Button("Upload PDF")
|
| 118 |
upload_status = gr.Textbox(label="Status", interactive=False)
|
| 119 |
|
| 120 |
+
gr.Markdown("### ๐ Use Existing Document")
|
| 121 |
+
existing_pdf_id = gr.Textbox(label="Existing PDF ID", placeholder="Enter existing PDF ID to chat", max_lines=1)
|
| 122 |
+
use_existing_btn = gr.Button("Use Existing PDF")
|
| 123 |
+
use_existing_status = gr.Textbox(label="Status", interactive=False)
|
| 124 |
+
|
| 125 |
gr.Markdown("### ๐๏ธ Delete PDF")
|
| 126 |
delete_input = gr.Textbox(label="PDF ID to Delete")
|
| 127 |
delete_btn = gr.Button("Delete PDF")
|
|
|
|
| 141 |
)
|
| 142 |
|
| 143 |
# Event handling
|
| 144 |
+
def use_existing_pdf(pdf_id):
|
| 145 |
+
if not pdf_id or not pdf_id.strip():
|
| 146 |
+
return "Please enter a valid PDF ID", None
|
| 147 |
+
return f"Set to use existing PDF ID: {pdf_id}", pdf_id.strip()
|
| 148 |
+
|
| 149 |
upload_btn.click(
|
| 150 |
fn=upload_pdf_file,
|
| 151 |
inputs=[pdf_input],
|
| 152 |
outputs=[upload_status, pdf_id_state]
|
| 153 |
)
|
| 154 |
|
| 155 |
+
use_existing_btn.click(
|
| 156 |
+
fn=use_existing_pdf,
|
| 157 |
+
inputs=[existing_pdf_id],
|
| 158 |
+
outputs=[use_existing_status, pdf_id_state]
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
delete_btn.click(
|
| 162 |
fn=delete_pdf,
|
| 163 |
inputs=[delete_input],
|