Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,24 @@
|
|
1 |
-
import
|
|
|
2 |
import gradio as gr
|
3 |
from pdf2image import convert_from_path
|
4 |
from byaldi import RAGMultiModalModel
|
5 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
6 |
from qwen_vl_utils import process_vision_info
|
7 |
import torch
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Install flash-attn if not already installed
|
11 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
@@ -16,7 +29,7 @@ model = Qwen2VLForConditionalGeneration.from_pretrained("Qwen/Qwen2-VL-2B-Instru
|
|
16 |
trust_remote_code=True, torch_dtype=torch.bfloat16).cuda().eval()
|
17 |
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", trust_remote_code=True)
|
18 |
|
19 |
-
@spaces.GPU()
|
20 |
def process_pdf_and_query(pdf_file, user_query):
|
21 |
# Convert the PDF to images
|
22 |
images = convert_from_path(pdf_file.name) # pdf_file.name gives the file path
|
|
|
1 |
+
import subprocess
|
2 |
+
import os
|
3 |
import gradio as gr
|
4 |
from pdf2image import convert_from_path
|
5 |
from byaldi import RAGMultiModalModel
|
6 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
7 |
from qwen_vl_utils import process_vision_info
|
8 |
import torch
|
9 |
+
|
10 |
+
# Run the commands from setup.sh to install poppler-utils
|
11 |
+
def install_poppler():
|
12 |
+
try:
|
13 |
+
subprocess.run(["pdfinfo"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
14 |
+
except FileNotFoundError:
|
15 |
+
print("Poppler not found. Installing...")
|
16 |
+
# Run the setup commands
|
17 |
+
subprocess.run("apt-get update", shell=True)
|
18 |
+
subprocess.run("apt-get install -y poppler-utils", shell=True)
|
19 |
+
|
20 |
+
# Call the Poppler installation check
|
21 |
+
install_poppler()
|
22 |
|
23 |
# Install flash-attn if not already installed
|
24 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
|
|
29 |
trust_remote_code=True, torch_dtype=torch.bfloat16).cuda().eval()
|
30 |
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", trust_remote_code=True)
|
31 |
|
32 |
+
@gr.spaces.GPU()
|
33 |
def process_pdf_and_query(pdf_file, user_query):
|
34 |
# Convert the PDF to images
|
35 |
images = convert_from_path(pdf_file.name) # pdf_file.name gives the file path
|