Gabriel C commited on
Commit
b598eba
β€’
1 Parent(s): 59426e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -21,18 +21,13 @@ def generate_caption(image):
21
  Generate a poem from an image.
22
  """
23
  # Process the image and the prompt
24
- inputs = processor(texts=["Write a poem about this picture"],
25
- images=[image],
26
  return_tensors="pt").to('cuda')
27
- # Generate the output
28
- with torch.inference_mode():
29
- output = model.generate(
30
- **inputs,
31
- max_new_tokens=128,
32
- )
33
- prompt_len = inputs["input_ids"].shape[1]
34
- decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
35
- return decoded_text
36
 
37
 
38
  # Define the Gradio interface
 
21
  Generate a poem from an image.
22
  """
23
  # Process the image and the prompt
24
+ inputs = processor("[INST] <image>\nWrite a poem about this picture [/INST]",
25
+ image,
26
  return_tensors="pt").to('cuda')
27
+ # autoregressively complete prompt
28
+ output = model.generate(**inputs, max_new_tokens=200)
29
+
30
+ return processor.decode(output[0], skip_special_tokens=True)
 
 
 
 
 
31
 
32
 
33
  # Define the Gradio interface