Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -174,12 +174,14 @@ def extract_data_from_pdfs(
|
|
174 |
|
175 |
# 2) Vision–language model
|
176 |
proc = LlavaNextProcessor.from_pretrained(vlm_choice)
|
177 |
-
vis = (
|
178 |
-
|
179 |
-
|
|
|
|
|
180 |
|
181 |
-
# 3) Monkey
|
182 |
-
def describe(img):
|
183 |
torch.cuda.empty_cache(); gc.collect()
|
184 |
prompt = "[INST] <image>\nDescribe the image in a sentence [/INST]"
|
185 |
inp = proc(prompt, img, return_tensors="pt").to("cuda")
|
@@ -206,15 +208,14 @@ def extract_data_from_pdfs(
|
|
206 |
images.extend(imgs)
|
207 |
names.extend([os.path.basename(path)] * len(imgs))
|
208 |
|
209 |
-
# 5) Build
|
210 |
progress(0.6, "Indexing in vector DB…")
|
211 |
-
client = get_vectordb(all_text, images, names)
|
212 |
-
|
213 |
global CURRENT_VDB
|
214 |
CURRENT_VDB = get_vectordb(all_text, images, names)
|
215 |
|
|
|
216 |
session["processed"] = True
|
217 |
-
sample = images[:4] if include_images=="Include Images" else []
|
218 |
return (
|
219 |
session,
|
220 |
all_text[:2000] + "...",
|
|
|
174 |
|
175 |
# 2) Vision–language model
|
176 |
proc = LlavaNextProcessor.from_pretrained(vlm_choice)
|
177 |
+
vis = (
|
178 |
+
LlavaNextForConditionalGeneration
|
179 |
+
.from_pretrained(vlm_choice, torch_dtype=torch.float16, low_cpu_mem_usage=True)
|
180 |
+
.to("cuda")
|
181 |
+
)
|
182 |
|
183 |
+
# 3) Monkey‐patch caption fn
|
184 |
+
def describe(img: Image.Image) -> str:
|
185 |
torch.cuda.empty_cache(); gc.collect()
|
186 |
prompt = "[INST] <image>\nDescribe the image in a sentence [/INST]"
|
187 |
inp = proc(prompt, img, return_tensors="pt").to("cuda")
|
|
|
208 |
images.extend(imgs)
|
209 |
names.extend([os.path.basename(path)] * len(imgs))
|
210 |
|
211 |
+
# 5) Build the in‐memory vector DB once
|
212 |
progress(0.6, "Indexing in vector DB…")
|
|
|
|
|
213 |
global CURRENT_VDB
|
214 |
CURRENT_VDB = get_vectordb(all_text, images, names)
|
215 |
|
216 |
+
# 6) Mark session and return UI outputs
|
217 |
session["processed"] = True
|
218 |
+
sample = images[:4] if include_images == "Include Images" else []
|
219 |
return (
|
220 |
session,
|
221 |
all_text[:2000] + "...",
|