Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,13 @@ translation_model_name = "Helsinki-NLP/opus-mt-en-es"
|
|
11 |
translator_model = MarianMTModel.from_pretrained(translation_model_name)
|
12 |
translator_tokenizer = MarianTokenizer.from_pretrained(translation_model_name)
|
13 |
|
|
|
|
|
14 |
def generate_caption(image):
|
|
|
|
|
|
|
|
|
15 |
# Generate caption from image
|
16 |
inputs = processor(images=image, return_tensors="pt", padding=True) # Added padding=True
|
17 |
out = model.generate(**inputs)
|
|
|
11 |
translator_model = MarianMTModel.from_pretrained(translation_model_name)
|
12 |
translator_tokenizer = MarianTokenizer.from_pretrained(translation_model_name)
|
13 |
|
14 |
+
from PIL import Image
|
15 |
+
|
16 |
def generate_caption(image):
|
17 |
+
# Ensure the image is in PIL format (Gradio should handle this, but let's explicitly ensure it)
|
18 |
+
if isinstance(image, Image.Image) is False:
|
19 |
+
image = Image.open(image)
|
20 |
+
|
21 |
# Generate caption from image
|
22 |
inputs = processor(images=image, return_tensors="pt", padding=True) # Added padding=True
|
23 |
out = model.generate(**inputs)
|