vidhanm commited on
Commit
a4644a0
·
1 Parent(s): aecdd6d

nonetype error

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -29,12 +29,10 @@ else:
29
  print(f"Using device: {device}")
30
 
31
  # --- Configuration for model components ---
32
- # The main model ID for weights and overall config
33
  model_id_for_weights = "lusxvr/nanoVLM-222M"
34
- # The ID for the vision backbone's image processor configuration
35
  image_processor_id = "openai/clip-vit-base-patch32"
36
- # The ID for the tokenizer (can be the main model ID if it provides specific tokenizer files)
37
- tokenizer_id = "lusxvr/nanoVLM-222M" # Or directly "gpt2" if preferred, but model_id is usually safer
38
 
39
  image_processor = None
40
  tokenizer = None
@@ -49,7 +47,7 @@ if VisionLanguageModel:
49
  print(f"Attempting to load GPT2TokenizerFast from: {tokenizer_id}")
50
  tokenizer = GPT2TokenizerFast.from_pretrained(tokenizer_id, trust_remote_code=True)
51
  if tokenizer.pad_token is None:
52
- tokenizer.pad_token = tokenizer.eos_token
53
  print("Set tokenizer pad_token to eos_token.")
54
  print("GPT2TokenizerFast loaded.")
55
 
@@ -64,7 +62,7 @@ if VisionLanguageModel:
64
  except Exception as e:
65
  print(f"Error loading model or processor components: {e}")
66
  import traceback
67
- traceback.print_exc() # Print full traceback
68
  image_processor = None
69
  tokenizer = None
70
  model = None
@@ -140,7 +138,6 @@ def generate_text_for_image(image_input, prompt_input):
140
 
141
  description = "Interactive demo for lusxvr/nanoVLM-222M."
142
  example_image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
143
- # gradio_cache_dir = os.environ.get("GRADIO_TEMP_DIR", "/tmp/gradio_tmp") # Not used for now
144
 
145
  iface = gr.Interface(
146
  fn=generate_text_for_image,
@@ -155,8 +152,7 @@ iface = gr.Interface(
155
  [example_image_url, "a photo of a"],
156
  [example_image_url, "Describe the image in detail."],
157
  ],
158
- cache_examples=True, # This might cause issues if Gradio version is old. Remove if needed.
159
- # examples_cache_folder=gradio_cache_dir, # Removed due to potential Gradio version issue
160
  allow_flagging="never"
161
  )
162
 
 
29
  print(f"Using device: {device}")
30
 
31
  # --- Configuration for model components ---
 
32
  model_id_for_weights = "lusxvr/nanoVLM-222M"
 
33
  image_processor_id = "openai/clip-vit-base-patch32"
34
+ # Load the tokenizer from its original source to ensure all files are present
35
+ tokenizer_id = "gpt2" # Changed from "lusxvr/nanoVLM-222M"
36
 
37
  image_processor = None
38
  tokenizer = None
 
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 # Important for GPT-2
51
  print("Set tokenizer pad_token to eos_token.")
52
  print("GPT2TokenizerFast loaded.")
53
 
 
62
  except Exception as e:
63
  print(f"Error loading model or processor components: {e}")
64
  import traceback
65
+ traceback.print_exc()
66
  image_processor = None
67
  tokenizer = None
68
  model = None
 
138
 
139
  description = "Interactive demo for lusxvr/nanoVLM-222M."
140
  example_image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
 
141
 
142
  iface = gr.Interface(
143
  fn=generate_text_for_image,
 
152
  [example_image_url, "a photo of a"],
153
  [example_image_url, "Describe the image in detail."],
154
  ],
155
+ # cache_examples=True, # Temporarily commented out to ensure Gradio starts with minimal config
 
156
  allow_flagging="never"
157
  )
158