Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,9 @@ model_id = "Salesforce/blip-image-captioning-base"
|
|
7 |
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
8 |
processor = BlipProcessor.from_pretrained(model_id)
|
9 |
|
10 |
-
def generate_caption(
|
11 |
-
#
|
12 |
-
image = Image.
|
13 |
|
14 |
# Process the image to generate tensor inputs
|
15 |
inputs = processor(image, return_tensors="pt")
|
@@ -20,6 +20,7 @@ def generate_caption(image_path):
|
|
20 |
# Decode and return the generated caption
|
21 |
return processor.decode(out[0], skip_special_tokens=True)
|
22 |
|
|
|
23 |
# Gradio interface setup to accept image input and produce text output
|
24 |
iface = gr.Interface(generate_caption, inputs="image", outputs="text")
|
25 |
|
|
|
7 |
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
8 |
processor = BlipProcessor.from_pretrained(model_id)
|
9 |
|
10 |
+
def generate_caption(image_array):
|
11 |
+
# Convert numpy array to PIL Image
|
12 |
+
image = Image.fromarray(image_array.astype('uint8')).convert('RGB')
|
13 |
|
14 |
# Process the image to generate tensor inputs
|
15 |
inputs = processor(image, return_tensors="pt")
|
|
|
20 |
# Decode and return the generated caption
|
21 |
return processor.decode(out[0], skip_special_tokens=True)
|
22 |
|
23 |
+
|
24 |
# Gradio interface setup to accept image input and produce text output
|
25 |
iface = gr.Interface(generate_caption, inputs="image", outputs="text")
|
26 |
|