mohAhmad commited on
Commit
139e2a4
1 Parent(s): 6799494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  from transformers import AutoProcessor, VisionEncoderDecoderModel
3
- import requests
4
  from PIL import Image
5
  import torch
6
 
@@ -23,12 +22,15 @@ if uploaded_file is not None:
23
  image = Image.open(uploaded_file).convert("RGB")
24
  st.image(image, caption="Uploaded Image", use_column_width=True)
25
 
26
- # Preprocessing image
27
  pixel_values = processor(images=image, return_tensors="pt").pixel_values
28
 
29
- # Generate caption
30
  generated_ids = model.generate(pixel_values)
 
 
31
  generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
32
 
 
33
  st.write("Generated Caption: ")
34
  st.success(generated_text)
 
1
  import streamlit as st
2
  from transformers import AutoProcessor, VisionEncoderDecoderModel
 
3
  from PIL import Image
4
  import torch
5
 
 
22
  image = Image.open(uploaded_file).convert("RGB")
23
  st.image(image, caption="Uploaded Image", use_column_width=True)
24
 
25
+ # Preprocess the image
26
  pixel_values = processor(images=image, return_tensors="pt").pixel_values
27
 
28
+ # Generate caption (inference)
29
  generated_ids = model.generate(pixel_values)
30
+
31
+ # Decode the generated caption
32
  generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
33
 
34
+ # Display the generated caption
35
  st.write("Generated Caption: ")
36
  st.success(generated_text)