Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import pytesseract
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
pytesseract.pytesseract.tesseract_cmd = shutil.which("tesseract") or None
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
st.write(text)
|
| 27 |
-
else:
|
| 28 |
-
st.warning("Please upload an image file to extract text.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import pytesseract
|
| 4 |
+
import io
|
| 5 |
|
| 6 |
+
def perform_ocr(image):
|
| 7 |
+
try:
|
| 8 |
+
text = pytesseract.image_to_string(image)
|
| 9 |
+
return text
|
| 10 |
+
except Exception as e:
|
| 11 |
+
return f"An error occurred: {str(e)}"
|
| 12 |
|
| 13 |
+
def main():
|
| 14 |
+
st.title("Image to Text Converter")
|
| 15 |
+
st.write("Upload an image and get the extracted text!")
|
| 16 |
|
| 17 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
| 18 |
|
| 19 |
+
if uploaded_file is not None:
|
| 20 |
+
image = Image.open(uploaded_file)
|
| 21 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 22 |
+
st.write("")
|
| 23 |
+
st.write("Extracting text...")
|
| 24 |
+
text = perform_ocr(image)
|
| 25 |
+
st.write("Extracted Text:")
|
| 26 |
+
st.write(text)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
main()
|
|
|
|
|
|
|
|
|