Spaces:
Build error
Build error
Download app.py from TrueInfoLabsNew/OCR: direct link, hf CLI and curl.
- Browser
- Download file 817 Bytes
-
https://huggingface.co/spaces/TrueInfoLabsNew/OCR/resolve/main/app.py
- Command line
-
hf download hf://spaces/TrueInfoLabsNew/OCR/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TrueInfoLabsNew/OCR/resolve/main/app.py
817 Bytes
| import streamlit as st | |
| from PIL import Image | |
| import pytesseract | |
| pytesseract.pytesseract.tesseract_cmd = "/opt/homebrew/bin/tesseract" | |
| def extract_text(image): | |
| try: | |
| text = pytesseract.image_to_string(image, lang='eng',config='--psm 1') | |
| return text | |
| except Exception as e: | |
| return str(e) | |
| def main(): | |
| st.title("Text Extraction from Image in English and Tamil") | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file) | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| text = extract_text(image) | |
| st.success("Text extracted successfully!") | |
| st.header("Extracted Text:") | |
| st.write(text) | |
| if __name__ == "__main__": | |
| main() | |