Use images to extract text from it using FastAPI
A FastAPI microservice for extracting text from images.It is deployed at https://imagetotext-042d.onrender.com/.
The normal home page with some changes and response as an HTML template .
Endpoint:https://imagetotext-042d.onrender.com/
This endpoint takes a photo as input and provides the extracted text as results.
Endpoint: https://imagetotext-042d.onrender.com/
This endpoint is used for validation testing using pytest. It echoes back the uploaded image for validation purposes.
Endpoint: https://imagetotext-042d.onrender.com/img-echo
The API endpoints are documented using Swagger UI. You can explore and test the endpoints by visiting https://imagetotext-042d.onrender.com/docs.
To run this microservice locally for development or testing, you can follow these steps:
git clone https://github.com/raaz252/ImageToText.git
cd ImageToTextThis pytest suite is designed to test a FastAPI microservice that converts images to text. The microservice is expected to handle file uploads, perform OCR (Optical Character Recognition), and provide echo functionality for image validation.
To run these tests, you need to have Python and pytest installed. You can install the required dependencies using pip:
pip install -r requirements.txtThe tests are designed to work with the provided FastAPI application located in app.main. The BASE_DIR variable is expected to point to the base directory of your project, and the TestClient class from fastapi.testclient is used for simulating HTTP requests.
test_invalid_file_upload_errorThis test checks for error handling when an invalid file is uploaded. It sends a POST request to the root endpoint ("/") without a valid file. It expects a response status code of 422 and "application/json" in the response headers.
test_prediction_uploadThis test uploads images from the "images" folder and checks the microservice's prediction functionality. It iterates through the image files in the "images" folder and attempts to open each image. For valid images, it sends a POST request to the root endpoint ("/") with the image file. It checks if the response status code is 200 and the JSON response contains two keys. For invalid images, it sends a POST request and checks for a 400 status code.
test_echo_uploadThis test validates the image echo functionality. It uploads images from the "images" folder to the "/img-echo" endpoint. It verifies that the response status code is 200. It compares the uploaded image with the echoed image to ensure they are identical.