sourabhbargi11 commited on
Commit
0959b2d
·
verified ·
1 Parent(s): 9522bcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -52,11 +52,21 @@ def image_preprocess(image):
52
 
53
  def generate_caption(processor, model, device, image):
54
  inputs = image_processor (image, return_tensors='pt').to(device)
55
- out = model.generate(**inputs, max_new_tokens=20)
56
- caption = processor.decode(out[0], skip_special_tokens=True)
57
- #caption="im here "
 
 
 
 
 
 
 
 
 
58
  return caption
59
 
 
60
  def main():
61
  set_page_config()
62
  st.header("Caption an Image :camera:")
 
52
 
53
  def generate_caption(processor, model, device, image):
54
  inputs = image_processor (image, return_tensors='pt').to(device)
55
+ model.eval()
56
+ # Generate caption
57
+ with torch.no_grad():
58
+ output = model.generate(
59
+ pixel_values=inputs ,
60
+ max_length=1000, # Adjust the maximum length of the generated caption as needed
61
+ num_beams=4, # Adjust the number of beams for beam search decoding
62
+ early_stopping=True # Enable early stopping to stop generation when all beams finished
63
+ )
64
+
65
+ # Decode the generated caption
66
+ caption = tokenizer.decode(output[0], skip_special_tokens=True)
67
  return caption
68
 
69
+
70
  def main():
71
  set_page_config()
72
  st.header("Caption an Image :camera:")