Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
import requests
|
3 |
from PIL import Image
|
4 |
from transformers import AutoProcessor, BlipForConditionalGeneration
|
@@ -7,9 +6,19 @@ from transformers import AutoProcessor, BlipForConditionalGeneration
|
|
7 |
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
8 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
9 |
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
from PIL import Image
|
3 |
from transformers import AutoProcessor, BlipForConditionalGeneration
|
|
|
6 |
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
7 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
8 |
|
9 |
+
# Load your image, DON'T FORGET TO WRITE YOUR IMAGE NAME
|
10 |
+
img_path = "YOUR IMAGE NAME.jpeg"
|
11 |
+
# convert it into an RGB format
|
12 |
+
image = Image.open(img_path).convert('RGB')
|
13 |
|
14 |
+
# You do not need a question for image captioning
|
15 |
+
text = "the image of"
|
16 |
+
inputs = processor(images=image, text=text, return_tensors="pt")
|
17 |
|
18 |
+
# Generate a caption for the image
|
19 |
+
outputs = model.generate(**inputs, max_length=50)
|
20 |
+
|
21 |
+
# Decode the generated tokens to text
|
22 |
+
caption = processor.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
# Print the caption
|
24 |
+
print(caption)
|