foxtrot126 commited on
Commit
e472a2b
·
verified ·
1 Parent(s): fc2eb0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -14,16 +14,19 @@ device = infer_device()
14
  def process_image(image, prompt):
15
  # Process the image and prompt using the processor
16
  inputs = processor(image, text=prompt, return_tensors="pt").to(device, torch.float16)
17
-
18
  try:
19
  # Generate output from the model
20
  output = model.generate(**inputs, max_new_tokens=10)
21
-
22
  # Decode and return the output
23
  decoded_output = processor.batch_decode(output, skip_special_tokens=True)[0].strip()
24
-
25
  # Return the answer (exclude the prompt part from output)
26
- return decoded_output[len(prompt):]
 
 
 
27
  except IndexError as e:
28
  print(f"IndexError: {e}")
29
  return "An error occurred during processing."
 
14
  def process_image(image, prompt):
15
  # Process the image and prompt using the processor
16
  inputs = processor(image, text=prompt, return_tensors="pt").to(device, torch.float16)
17
+
18
  try:
19
  # Generate output from the model
20
  output = model.generate(**inputs, max_new_tokens=10)
21
+
22
  # Decode and return the output
23
  decoded_output = processor.batch_decode(output, skip_special_tokens=True)[0].strip()
24
+
25
  # Return the answer (exclude the prompt part from output)
26
+ # The model's output often includes the prompt, so we remove it.
27
+ if decoded_output.startswith(prompt):
28
+ return decoded_output[len(prompt):].strip()
29
+ return decoded_output
30
  except IndexError as e:
31
  print(f"IndexError: {e}")
32
  return "An error occurred during processing."