isom5240 commited on
Commit
e2e071b
·
verified ·
1 Parent(s): 369bb30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -5,13 +5,10 @@ from PIL import Image
5
  import io
6
 
7
  # function part
8
- def generate_image_caption(image_file):
9
  """Generates a caption for the given image using a pre-trained model."""
10
  img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
11
-
12
- # Read the image file
13
- image = Image.open(image_file)
14
-
15
  # Generate caption
16
  result = img2caption(image)
17
  return result[0]['generated_text']
@@ -32,11 +29,12 @@ def main():
32
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
33
 
34
  if uploaded_image is not None:
35
- st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
 
36
 
37
  # Stage 1: Image to Text
38
  st.text('Processing img2text...')
39
- image_caption = generate_image_caption(uploaded_image)
40
  st.write(image_caption)
41
 
42
  if __name__ == "__main__":
 
5
  import io
6
 
7
  # function part
8
+ def generate_image_caption(image):
9
  """Generates a caption for the given image using a pre-trained model."""
10
  img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
11
+
 
 
 
12
  # Generate caption
13
  result = img2caption(image)
14
  return result[0]['generated_text']
 
29
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
30
 
31
  if uploaded_image is not None:
32
+ image = Image.open(uploaded_file).convert("RGB")
33
+ st.image(image, caption="Uploaded Image", use_column_width=True)
34
 
35
  # Stage 1: Image to Text
36
  st.text('Processing img2text...')
37
+ image_caption = generate_image_caption(image)
38
  st.write(image_caption)
39
 
40
  if __name__ == "__main__":