Spaces:
Running
Running
pranavinani
commited on
Commit
·
78c0b3e
1
Parent(s):
f65f042
modified the ui elements
Browse files
app.py
CHANGED
|
@@ -615,6 +615,27 @@ def create_book_gallery():
|
|
| 615 |
|
| 616 |
return gallery_data, book_names
|
| 617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
# Create Gradio interface
|
| 619 |
def create_interface():
|
| 620 |
"""Create the Gradio interface"""
|
|
@@ -785,6 +806,13 @@ def create_interface():
|
|
| 785 |
outputs=[doc_status, book_title_display, author_display, query_section]
|
| 786 |
)
|
| 787 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
# PDF upload event handler
|
| 789 |
if 'process_pdf_btn' in locals():
|
| 790 |
process_pdf_btn.click(
|
|
|
|
| 615 |
|
| 616 |
return gallery_data, book_names
|
| 617 |
|
| 618 |
+
def handle_gallery_selection(evt: gr.SelectData):
|
| 619 |
+
"""Handle book selection from gallery click"""
|
| 620 |
+
if evt.index is None:
|
| 621 |
+
return "None"
|
| 622 |
+
|
| 623 |
+
# Get available books to map gallery index to book name
|
| 624 |
+
available_books = get_available_books()
|
| 625 |
+
|
| 626 |
+
# Filter books that have valid thumbnails (same as in create_book_gallery)
|
| 627 |
+
valid_books = []
|
| 628 |
+
for book in available_books:
|
| 629 |
+
if book['thumbnail'] and os.path.exists(book['thumbnail']):
|
| 630 |
+
valid_books.append(book)
|
| 631 |
+
|
| 632 |
+
# Check if the selected index is valid
|
| 633 |
+
if 0 <= evt.index < len(valid_books):
|
| 634 |
+
selected_book = valid_books[evt.index]
|
| 635 |
+
return selected_book['name']
|
| 636 |
+
|
| 637 |
+
return "None"
|
| 638 |
+
|
| 639 |
# Create Gradio interface
|
| 640 |
def create_interface():
|
| 641 |
"""Create the Gradio interface"""
|
|
|
|
| 806 |
outputs=[doc_status, book_title_display, author_display, query_section]
|
| 807 |
)
|
| 808 |
|
| 809 |
+
# Gallery selection event handler
|
| 810 |
+
if 'book_gallery' in locals():
|
| 811 |
+
book_gallery.select(
|
| 812 |
+
handle_gallery_selection,
|
| 813 |
+
outputs=[book_dropdown]
|
| 814 |
+
)
|
| 815 |
+
|
| 816 |
# PDF upload event handler
|
| 817 |
if 'process_pdf_btn' in locals():
|
| 818 |
process_pdf_btn.click(
|