aifeifei798 commited on
Commit
65853cc
1 Parent(s): cbacb88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -56,12 +56,20 @@ def run_example(image):
56
  image = image.convert("RGB")
57
 
58
  inputs = processor(text=prompt, images=image, return_tensors="pt")
 
 
 
 
59
  generated_ids = model.generate(
60
  input_ids=inputs["input_ids"],
61
  pixel_values=inputs["pixel_values"],
62
  max_new_tokens=1024,
63
  num_beams=3
64
  )
 
 
 
 
65
  generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
66
  parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
67
  return modify_caption(parsed_answer["<DESCRIPTION>"])
 
56
  image = image.convert("RGB")
57
 
58
  inputs = processor(text=prompt, images=image, return_tensors="pt")
59
+
60
+ # Move inputs to GPU
61
+ inputs = {key: value.to("cuda:0") for key, value in inputs.items()}
62
+
63
  generated_ids = model.generate(
64
  input_ids=inputs["input_ids"],
65
  pixel_values=inputs["pixel_values"],
66
  max_new_tokens=1024,
67
  num_beams=3
68
  )
69
+
70
+ # Move generated_ids to CPU for decoding
71
+ generated_ids = generated_ids.to("cpu")
72
+
73
  generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
74
  parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
75
  return modify_caption(parsed_answer["<DESCRIPTION>"])