Spaces:
Running
Running
vidhanm
commited on
Commit
·
3253deb
1
Parent(s):
a4644a0
trying to fix typerror
Browse files
app.py
CHANGED
@@ -31,8 +31,7 @@ print(f"Using device: {device}")
|
|
31 |
# --- Configuration for model components ---
|
32 |
model_id_for_weights = "lusxvr/nanoVLM-222M"
|
33 |
image_processor_id = "openai/clip-vit-base-patch32"
|
34 |
-
|
35 |
-
tokenizer_id = "gpt2" # Changed from "lusxvr/nanoVLM-222M"
|
36 |
|
37 |
image_processor = None
|
38 |
tokenizer = None
|
@@ -41,20 +40,21 @@ model = None
|
|
41 |
if VisionLanguageModel:
|
42 |
try:
|
43 |
print(f"Attempting to load CLIPImageProcessor from: {image_processor_id}")
|
|
|
44 |
image_processor = CLIPImageProcessor.from_pretrained(image_processor_id, trust_remote_code=True)
|
45 |
print("CLIPImageProcessor loaded.")
|
46 |
|
47 |
print(f"Attempting to load GPT2TokenizerFast from: {tokenizer_id}")
|
48 |
tokenizer = GPT2TokenizerFast.from_pretrained(tokenizer_id, trust_remote_code=True)
|
49 |
if tokenizer.pad_token is None:
|
50 |
-
tokenizer.pad_token = tokenizer.eos_token
|
51 |
print("Set tokenizer pad_token to eos_token.")
|
52 |
print("GPT2TokenizerFast loaded.")
|
53 |
|
54 |
print(f"Attempting to load model weights from {model_id_for_weights} using VisionLanguageModel.from_pretrained")
|
|
|
55 |
model = VisionLanguageModel.from_pretrained(
|
56 |
-
model_id_for_weights
|
57 |
-
trust_remote_code=True
|
58 |
).to(device)
|
59 |
print("Model loaded successfully.")
|
60 |
model.eval()
|
@@ -69,6 +69,7 @@ if VisionLanguageModel:
|
|
69 |
else:
|
70 |
print("Custom VisionLanguageModel class not imported, cannot load model.")
|
71 |
|
|
|
72 |
def prepare_inputs(text_list, image_input, image_processor_instance, tokenizer_instance, device_to_use):
|
73 |
if image_processor_instance is None or tokenizer_instance is None:
|
74 |
raise ValueError("Image processor or tokenizer not initialized.")
|
@@ -152,7 +153,7 @@ iface = gr.Interface(
|
|
152 |
[example_image_url, "a photo of a"],
|
153 |
[example_image_url, "Describe the image in detail."],
|
154 |
],
|
155 |
-
# cache_examples=True, #
|
156 |
allow_flagging="never"
|
157 |
)
|
158 |
|
|
|
31 |
# --- Configuration for model components ---
|
32 |
model_id_for_weights = "lusxvr/nanoVLM-222M"
|
33 |
image_processor_id = "openai/clip-vit-base-patch32"
|
34 |
+
tokenizer_id = "gpt2"
|
|
|
35 |
|
36 |
image_processor = None
|
37 |
tokenizer = None
|
|
|
40 |
if VisionLanguageModel:
|
41 |
try:
|
42 |
print(f"Attempting to load CLIPImageProcessor from: {image_processor_id}")
|
43 |
+
# trust_remote_code for HF's classes is fine if they support it.
|
44 |
image_processor = CLIPImageProcessor.from_pretrained(image_processor_id, trust_remote_code=True)
|
45 |
print("CLIPImageProcessor loaded.")
|
46 |
|
47 |
print(f"Attempting to load GPT2TokenizerFast from: {tokenizer_id}")
|
48 |
tokenizer = GPT2TokenizerFast.from_pretrained(tokenizer_id, trust_remote_code=True)
|
49 |
if tokenizer.pad_token is None:
|
50 |
+
tokenizer.pad_token = tokenizer.eos_token
|
51 |
print("Set tokenizer pad_token to eos_token.")
|
52 |
print("GPT2TokenizerFast loaded.")
|
53 |
|
54 |
print(f"Attempting to load model weights from {model_id_for_weights} using VisionLanguageModel.from_pretrained")
|
55 |
+
# Removed trust_remote_code=True as the custom VisionLanguageModel.from_pretrained doesn't expect it.
|
56 |
model = VisionLanguageModel.from_pretrained(
|
57 |
+
model_id_for_weights
|
|
|
58 |
).to(device)
|
59 |
print("Model loaded successfully.")
|
60 |
model.eval()
|
|
|
69 |
else:
|
70 |
print("Custom VisionLanguageModel class not imported, cannot load model.")
|
71 |
|
72 |
+
# ... (rest of the app.py remains the same) ...
|
73 |
def prepare_inputs(text_list, image_input, image_processor_instance, tokenizer_instance, device_to_use):
|
74 |
if image_processor_instance is None or tokenizer_instance is None:
|
75 |
raise ValueError("Image processor or tokenizer not initialized.")
|
|
|
153 |
[example_image_url, "a photo of a"],
|
154 |
[example_image_url, "Describe the image in detail."],
|
155 |
],
|
156 |
+
# cache_examples=True, # Keep commented out for now
|
157 |
allow_flagging="never"
|
158 |
)
|
159 |
|