Prakh24s commited on
Commit
fbfec82
1 Parent(s): 1a004cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
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(image_path):
11
- # Load the image directly from the path
12
- image = Image.open(image_path).convert('RGB')
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