Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ processor = ColQwen2Processor.from_pretrained("manu/colqwen2-v1.0-alpha")
|
|
| 25 |
|
| 26 |
def search(query: str, ds, images, k):
|
| 27 |
if not ds:
|
| 28 |
-
return
|
| 29 |
|
| 30 |
k = min(k, len(ds))
|
| 31 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
@@ -46,11 +46,11 @@ def search(query: str, ds, images, k):
|
|
| 46 |
for idx in top_k_indices:
|
| 47 |
results.append((images[idx], f"Page {idx}"))
|
| 48 |
|
| 49 |
-
return results
|
| 50 |
|
| 51 |
def index(files, ds):
|
| 52 |
if not files:
|
| 53 |
-
return
|
| 54 |
|
| 55 |
print("Converting files")
|
| 56 |
images = convert_files(files)
|
|
@@ -117,8 +117,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 117 |
convert_button.click(index, inputs=[file, embeds], outputs=[message, embeds, imgs])
|
| 118 |
search_button = gr.Button("🔍 Search", variant="primary")
|
| 119 |
output_gallery = gr.Gallery(label="Retrieved Documents", height=600, show_label=True)
|
|
|
|
| 120 |
|
| 121 |
-
search_button.click(search, inputs=[query, embeds, imgs, k], outputs=[output_gallery])
|
| 122 |
|
| 123 |
if __name__ == "__main__":
|
| 124 |
demo.queue(max_size=10).launch(debug=True)
|
|
|
|
| 25 |
|
| 26 |
def search(query: str, ds, images, k):
|
| 27 |
if not ds:
|
| 28 |
+
return None, "No documents have been indexed. Please upload and index documents first."
|
| 29 |
|
| 30 |
k = min(k, len(ds))
|
| 31 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 46 |
for idx in top_k_indices:
|
| 47 |
results.append((images[idx], f"Page {idx}"))
|
| 48 |
|
| 49 |
+
return results, ""
|
| 50 |
|
| 51 |
def index(files, ds):
|
| 52 |
if not files:
|
| 53 |
+
return "No files uploaded. Please upload PDF files to index.", ds, []
|
| 54 |
|
| 55 |
print("Converting files")
|
| 56 |
images = convert_files(files)
|
|
|
|
| 117 |
convert_button.click(index, inputs=[file, embeds], outputs=[message, embeds, imgs])
|
| 118 |
search_button = gr.Button("🔍 Search", variant="primary")
|
| 119 |
output_gallery = gr.Gallery(label="Retrieved Documents", height=600, show_label=True)
|
| 120 |
+
error_output = gr.Textbox(label="Error Message")
|
| 121 |
|
| 122 |
+
search_button.click(search, inputs=[query, embeds, imgs, k], outputs=[output_gallery, error_output])
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
| 125 |
demo.queue(max_size=10).launch(debug=True)
|