multimodalart HF Staff commited on
Commit
5b816dc
·
verified ·
1 Parent(s): 1119475

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -156,13 +156,9 @@ def read_image_style(image: Image.Image):
156
  ids = inputs["input_ids"][0].tolist()
157
  starts = [i for i, t in enumerate(ids) if t == 151644] # <|im_start|>
158
  begin = starts[1] + 3 # strip system turn + "<|im_start|>user\n"
159
- out = pipe.text_encoder(
160
- input_ids=inputs["input_ids"],
161
- attention_mask=inputs["attention_mask"],
162
- pixel_values=inputs["pixel_values"].to(torch.bfloat16),
163
- image_grid_thw=inputs["image_grid_thw"],
164
- output_hidden_states=True,
165
- )
166
  hs = torch.stack([out.hidden_states[i] for i in pipe.text_encoder_select_layers], dim=2)[:, begin:]
167
  if hs.shape[1] != TOKENS:
168
  raise gr.Error(f"Expected {TOKENS} tokens from the picture, got {hs.shape[1]}.")
 
156
  ids = inputs["input_ids"][0].tolist()
157
  starts = [i for i, t in enumerate(ids) if t == 151644] # <|im_start|>
158
  begin = starts[1] + 3 # strip system turn + "<|im_start|>user\n"
159
+ enc_inputs = dict(inputs)
160
+ enc_inputs["pixel_values"] = enc_inputs["pixel_values"].to(torch.bfloat16)
161
+ out = pipe.text_encoder(**enc_inputs, output_hidden_states=True)
 
 
 
 
162
  hs = torch.stack([out.hidden_states[i] for i in pipe.text_encoder_select_layers], dim=2)[:, begin:]
163
  if hs.shape[1] != TOKENS:
164
  raise gr.Error(f"Expected {TOKENS} tokens from the picture, got {hs.shape[1]}.")