Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
| 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."
|