RishuD7 commited on
Commit
a2f5019
·
1 Parent(s): 56810e9

added function to convert image to RGB

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -16,12 +16,13 @@ def TrOCR_predict(pixel_values, processor, model):
16
  return predicted_text
17
 
18
 
19
- df = pd.DataFrame()
20
  uploaded_file = st.file_uploader("Choose a file")
21
  if uploaded_file is not None:
22
  content = uploaded_file.read()
23
  st.image(uploaded_file)
24
  image = Image.open(uploaded_file)
 
 
25
  pixel_values = processor(images=image, return_tensors="pt").pixel_values
26
  predicted_text = TrOCR_predict(pixel_values, processor, model)[0]
27
  texts = predicted_text
 
16
  return predicted_text
17
 
18
 
 
19
  uploaded_file = st.file_uploader("Choose a file")
20
  if uploaded_file is not None:
21
  content = uploaded_file.read()
22
  st.image(uploaded_file)
23
  image = Image.open(uploaded_file)
24
+ if image.mode != "RGB": # Convert the image to RGB
25
+ image = image.convert("RGB")
26
  pixel_values = processor(images=image, return_tensors="pt").pixel_values
27
  predicted_text = TrOCR_predict(pixel_values, processor, model)[0]
28
  texts = predicted_text