mkoot007 commited on
Commit
c9e5fc0
·
1 Parent(s): cf3d036

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import streamlit as st
2
  from PIL import Image
3
- import io
4
- from transformers import AutoTokenizer, AutoModelForCausalLM
5
  from easyocr import Reader
6
 
 
 
 
7
  # Load the OCR model and text explanation model
8
  ocr_reader = Reader(['en'])
9
 
@@ -37,11 +39,15 @@ uploaded_file = st.file_uploader("Upload an image:")
37
  if uploaded_file is not None:
38
  image = Image.open(uploaded_file)
39
  ocr_results = extract_text(image)
 
40
  explanation = explain_text(ocr_results, text_generator, text_tokenizer)
41
 
42
  st.markdown("**Extracted text:**")
43
  st.markdown(" ".join([res[1] for res in ocr_results]))
44
 
 
 
 
45
  st.markdown("**Explanation:**")
46
  st.markdown(explanation)
47
 
 
1
  import streamlit as st
2
  from PIL import Image
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
 
4
  from easyocr import Reader
5
 
6
+ # Initialize the image-to-text model
7
+ image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
8
+
9
  # Load the OCR model and text explanation model
10
  ocr_reader = Reader(['en'])
11
 
 
39
  if uploaded_file is not None:
40
  image = Image.open(uploaded_file)
41
  ocr_results = extract_text(image)
42
+ image_caption = image_to_text(image) # Use the image-to-text model
43
  explanation = explain_text(ocr_results, text_generator, text_tokenizer)
44
 
45
  st.markdown("**Extracted text:**")
46
  st.markdown(" ".join([res[1] for res in ocr_results]))
47
 
48
+ st.markdown("**Image Caption:**")
49
+ st.markdown(image_caption[0]['caption']) # Display the image caption
50
+
51
  st.markdown("**Explanation:**")
52
  st.markdown(explanation)
53