maaz21 commited on
Commit
21d9b3a
·
verified ·
1 Parent(s): ef0458a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -1,16 +1,15 @@
1
  import streamlit as st
2
- import pytesseract
3
  from PIL import Image
4
- import io
5
-
6
- # Set the correct path for Tesseract
7
- pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
8
 
9
  # Set the page title and icon
10
  st.set_page_config(page_title="Image to Text Converter", page_icon="🖼️", layout="centered")
11
 
12
  st.title("🖼️ Image to Text Converter")
13
- st.markdown("Extract text from images using OCR technology!")
 
 
 
14
 
15
  # Upload Image
16
  uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
@@ -22,11 +21,12 @@ if uploaded_file is not None:
22
 
23
  # Convert Image to Text
24
  with st.spinner("Extracting text..."):
25
- text = pytesseract.image_to_string(image)
 
26
 
27
  # Display Extracted Text
28
  st.subheader("Extracted Text")
29
- st.text_area("", text, height=200)
30
 
31
  st.markdown("---")
32
- st.markdown("💡 Developed with ❤️ using Streamlit and Tesseract OCR")
 
1
  import streamlit as st
2
+ import easyocr
3
  from PIL import Image
 
 
 
 
4
 
5
  # Set the page title and icon
6
  st.set_page_config(page_title="Image to Text Converter", page_icon="🖼️", layout="centered")
7
 
8
  st.title("🖼️ Image to Text Converter")
9
+ st.markdown("Extract text from images using AI-powered OCR!")
10
+
11
+ # Initialize OCR Reader
12
+ reader = easyocr.Reader(["en"]) # You can add more languages like ["en", "fr"]
13
 
14
  # Upload Image
15
  uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
 
21
 
22
  # Convert Image to Text
23
  with st.spinner("Extracting text..."):
24
+ text_results = reader.readtext(image)
25
+ extracted_text = "\n".join([text[1] for text in text_results])
26
 
27
  # Display Extracted Text
28
  st.subheader("Extracted Text")
29
+ st.text_area("", extracted_text, height=200)
30
 
31
  st.markdown("---")
32
+ st.markdown("💡 Developed with ❤️ using Streamlit and EasyOCR")