Spaces:
Runtime error
Runtime error
resolving issues
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from PIL import Image
|
|
3 |
import torch
|
4 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, AutoModelForImageToText
|
5 |
from colpali_engine.models import ColPali, ColPaliProcessor
|
|
|
6 |
import os
|
7 |
|
8 |
# Set device for computation
|
@@ -11,26 +12,29 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
11 |
# Get Hugging Face token from environment variables
|
12 |
hf_token = os.getenv('HF_TOKEN')
|
13 |
|
14 |
-
#
|
|
|
|
|
|
|
15 |
try:
|
16 |
-
processor_img_to_text = AutoProcessor.from_pretrained("google/paligemma-3b-mix-448"
|
17 |
-
model_img_to_text = AutoModelForImageToText.from_pretrained("google/paligemma-3b-mix-448"
|
18 |
except Exception as e:
|
19 |
st.error(f"Error loading image-to-text model: {e}")
|
20 |
st.stop()
|
21 |
|
22 |
# Load ColPali model with Hugging Face token
|
23 |
try:
|
24 |
-
model_colpali = ColPali.from_pretrained("vidore/colpali-v1.2", torch_dtype=torch.bfloat16
|
25 |
-
processor_colpali = ColPaliProcessor.from_pretrained("google/paligemma-3b-mix-448"
|
26 |
except Exception as e:
|
27 |
st.error(f"Error loading ColPali model or processor: {e}")
|
28 |
st.stop()
|
29 |
|
30 |
-
# Load Qwen model
|
31 |
try:
|
32 |
-
model_qwen = Qwen2VLForConditionalGeneration.from_pretrained("Qwen/Qwen2-VL-7B-Instruct"
|
33 |
-
processor_qwen = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct"
|
34 |
except Exception as e:
|
35 |
st.error(f"Error loading Qwen model or processor: {e}")
|
36 |
st.stop()
|
|
|
3 |
import torch
|
4 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, AutoModelForImageToText
|
5 |
from colpali_engine.models import ColPali, ColPaliProcessor
|
6 |
+
from huggingface_hub import login
|
7 |
import os
|
8 |
|
9 |
# Set device for computation
|
|
|
12 |
# Get Hugging Face token from environment variables
|
13 |
hf_token = os.getenv('HF_TOKEN')
|
14 |
|
15 |
+
# Log in to Hugging Face Hub (this will authenticate globally)
|
16 |
+
login(token=hf_token)
|
17 |
+
|
18 |
+
# Load the processor and image-to-text model directly
|
19 |
try:
|
20 |
+
processor_img_to_text = AutoProcessor.from_pretrained("google/paligemma-3b-mix-448")
|
21 |
+
model_img_to_text = AutoModelForImageToText.from_pretrained("google/paligemma-3b-mix-448").to(device)
|
22 |
except Exception as e:
|
23 |
st.error(f"Error loading image-to-text model: {e}")
|
24 |
st.stop()
|
25 |
|
26 |
# Load ColPali model with Hugging Face token
|
27 |
try:
|
28 |
+
model_colpali = ColPali.from_pretrained("vidore/colpali-v1.2", torch_dtype=torch.bfloat16).to(device)
|
29 |
+
processor_colpali = ColPaliProcessor.from_pretrained("google/paligemma-3b-mix-448")
|
30 |
except Exception as e:
|
31 |
st.error(f"Error loading ColPali model or processor: {e}")
|
32 |
st.stop()
|
33 |
|
34 |
+
# Load Qwen model
|
35 |
try:
|
36 |
+
model_qwen = Qwen2VLForConditionalGeneration.from_pretrained("Qwen/Qwen2-VL-7B-Instruct").to(device)
|
37 |
+
processor_qwen = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")
|
38 |
except Exception as e:
|
39 |
st.error(f"Error loading Qwen model or processor: {e}")
|
40 |
st.stop()
|