saakshigupta commited on
Commit
5113374
·
verified ·
1 Parent(s): 19d5db6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -427,12 +427,13 @@ def generate_gradcam_caption(image, processor, model, max_length=60):
427
  Generate a detailed analysis of GradCAM visualization using the fine-tuned BLIP model
428
  """
429
  try:
430
- # Check for available GPU
 
 
 
431
  device = "cuda" if torch.cuda.is_available() else "cpu"
432
  model = model.to(device)
433
-
434
- # Process image with BLIP
435
- inputs = processor(image, return_tensors="pt").to(device)
436
 
437
  # Generate caption
438
  with torch.no_grad():
 
427
  Generate a detailed analysis of GradCAM visualization using the fine-tuned BLIP model
428
  """
429
  try:
430
+ # Process image first
431
+ inputs = processor(image, return_tensors="pt")
432
+
433
+ # Check for available GPU and move model and inputs
434
  device = "cuda" if torch.cuda.is_available() else "cpu"
435
  model = model.to(device)
436
+ inputs = {k: v.to(device) if hasattr(v, 'to') else v for k, v in inputs.items()}
 
 
437
 
438
  # Generate caption
439
  with torch.no_grad():