Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,11 @@ from pdf2image import convert_from_path
|
|
7 |
from PIL import Image
|
8 |
from torch.utils.data import DataLoader
|
9 |
from tqdm import tqdm
|
|
|
10 |
|
|
|
|
|
|
|
11 |
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
12 |
|
13 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
@@ -21,6 +25,9 @@ model = ColQwen2.from_pretrained(
|
|
21 |
processor = ColQwen2Processor.from_pretrained("manu/colqwen2-v1.0-alpha")
|
22 |
|
23 |
def search(query: str, ds, images, k):
|
|
|
|
|
|
|
24 |
k = min(k, len(ds))
|
25 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
26 |
if device != model.device:
|
|
|
7 |
from PIL import Image
|
8 |
from torch.utils.data import DataLoader
|
9 |
from tqdm import tqdm
|
10 |
+
import os
|
11 |
|
12 |
+
if not os.path.exists('/tmp/gradio'):
|
13 |
+
os.makedirs('/tmp/gradio')
|
14 |
+
|
15 |
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
16 |
|
17 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
25 |
processor = ColQwen2Processor.from_pretrained("manu/colqwen2-v1.0-alpha")
|
26 |
|
27 |
def search(query: str, ds, images, k):
|
28 |
+
if not ds:
|
29 |
+
return gr.Error("No documents have been indexed. Please upload and index documents first.")
|
30 |
+
|
31 |
k = min(k, len(ds))
|
32 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
33 |
if device != model.device:
|