Spaces:
Runtime error
Runtime error
Download app.py from typesdigital/ExtractTextfromImage: direct link, hf CLI and curl.
- Browser
- Download file 604 Bytes
-
https://huggingface.co/spaces/typesdigital/ExtractTextfromImage/resolve/main/app.py
- Command line
-
hf download hf://spaces/typesdigital/ExtractTextfromImage/app.py
-
curl -L -o app.py https://huggingface.co/spaces/typesdigital/ExtractTextfromImage/resolve/main/app.py
604 Bytes
| # app.py | |
| import gradio as gr | |
| from PIL import Image | |
| import pytesseract | |
| import numpy as np | |
| def extract_text_from_image(image): | |
| try: | |
| # Convert the PIL image to a NumPy array | |
| image_array = np.array(image) | |
| # Use Tesseract to extract text | |
| text = pytesseract.image_to_string(Image.fromarray(image_array)) | |
| return text | |
| except Exception as e: | |
| return str(e) | |
| iface = gr.Interface( | |
| fn=extract_text_from_image, | |
| inputs=gr.Image(type="pil", label="Upload an image"), | |
| outputs="text", | |
| live=True, | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |