This API provides several endpoints to extract text from images using OpenAI's GPT-4 with Vision model and generate an image of a store menu using OpenAI's DALL-E model. Additionally, it offers an endpoint to create variations of input images.
Before running the Flask API, make sure you have the following installed:
- Python 3.x
- pip (Python package installer)
- Docker (optional)
-
Clone this repository to your local machine:
git clone https://github.com/YounoussaBen/OpenAI_OCR.git cd OpenAI_OCR
-
Create a virtual environment named
env
:python3 -m venv env
-
Activate the virtual environment:
source env/bin/activate
-
Install dependencies using pip within the virtual environment:
pip install -r requirements.txt
-
Set up your environment variables:
Create a
.env
file in the root directory of your project and add the following:OPENAI_API_KEY=your_openai_api_key_here
You can run the Flask server using either Python directly or Gunicorn. Additionally, there's a script available to simplify the process.
To run the Flask server with Python, execute the following command:
python app.py
The server will start running on http://localhost:5000 by default.
You can also run the Flask server with Gunicorn. Use the provided run.sh
script:
./run.sh
The server will start running with Gunicorn on http://localhost:5000 by default.
Alternatively, you can run the Flask server using Docker:
docker build -t my-flask-app .
docker run -p 5000:5000 my-flask-app
- URL:
/extract_text
- Method: POST
- Request Body:
image
(file): An image file to extract text from.
- Response: Returns a JSON object with the extracted text or an error.
Example Request:
curl -X POST http://localhost:5000/extract_text -F "image=@path_to_your_image.jpg"
Example Response:
{
"extracted_text": "The extracted text will be here."
}
- URL:
/generate_menu_image
- Method: POST
- Request Body:
products
(list): A list of products, where each product is a dictionary with aname
andprice
key.description
(string): A description of the shop.
- Response: Returns a JSON object with the URL of the generated menu image or an error.
Example Request:
{
"products": [
{"name": "Coffee", "price": 2.5},
{"name": "Sandwich", "price": 5.0},
{"name": "Salad", "price": 7.0},
{"name": "Juice", "price": 3.5}
],
"description": "A charming little bakery known for its fresh bread and pastries."
}
Example Response:
{
"image_url": "URL_of_the_generated_image"
}
- URL:
/create_image_variation
- Method: POST
- Request Body:
image
(file): An image file for which a variation is to be created.
- Response: Returns a JSON object with the URL of the generated variation image or an error.
Example Request:
curl -X POST http://localhost:5000/create_image_variation -F "image=@path_to_your_image.jpg"
Example Response:
{
"image_url": "URL_of_the_generated_variation_image"
}
Contributions are welcome! If you find any issues or want to add new features, feel free to open a pull request.
This project is licensed under the MIT License.