Spaces:
Runtime error
Runtime error
Gabriel C
commited on
Commit
β’
b598eba
1
Parent(s):
59426e0
Update app.py
Browse files
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(
|
25 |
-
|
26 |
return_tensors="pt").to('cuda')
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
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
|