Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
2 |
from PIL import Image
|
|
|
|
|
|
|
3 |
|
4 |
def generate_caption(image_path):
|
5 |
image = Image.open(image_path)
|
6 |
-
processor =
|
7 |
-
model =
|
8 |
inputs = processor(image, return_tensors="pt")
|
9 |
output = model.generate(**inputs)
|
10 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
|
|
1 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
2 |
from PIL import Image
|
3 |
+
# Load model directly
|
4 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
5 |
+
|
6 |
|
7 |
def generate_caption(image_path):
|
8 |
image = Image.open(image_path)
|
9 |
+
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
10 |
+
model = AutoModelForImageTextToText.from_pretrained("Salesforce/blip-image-captioning-base")
|
11 |
inputs = processor(image, return_tensors="pt")
|
12 |
output = model.generate(**inputs)
|
13 |
caption = processor.decode(output[0], skip_special_tokens=True)
|