Skip to content

Latest commit

 

History

History
128 lines (92 loc) · 3.21 KB

README.md

File metadata and controls

128 lines (92 loc) · 3.21 KB

SocioCaption API

This is a Flask web application that generates social media captions, descriptions, and tags for an image description using the GPT-4 language model. The application exposes several endpoints for different functionalities.

Prerequisites

  • Python 3.10
  • Flask
  • g4f - uses DeepAI api wrapper

Installation

  1. Clone the repository:

    git clone https://github.com/WhoIsJayD/Socio-Caption-Api
  2. Navigate to the project directory:

    cd Socio-Caption-Api
  3. Install the required dependencies:

    pip install -r requirements.txt
  4. Update the g4f if necessary. You can check here for the latest version.

  5. Start the application:

    python wsgi.py

    The application will run on http://0.0.0.0:8000 by default.

Endpoints

/

  • Method: GET
  • Description: Home endpoint that renders the index.html template.

/captions

  • Method: GET, POST
  • Description: Generates social media captions for an image description.
  • Query Parameters:
    • image_description (required): The description of the image.
  • Response:
    • Content-Type: application/json
    • Body:
      {
        "captions": [
          "Caption 1",
          "Caption 2",
          ...
        ]
      }

/description

  • Method: GET, POST
  • Description: Generates a single text description for an image.
  • Query Parameters:
    • image_description (required): The description of the image.
  • Response:
    • Content-Type: application/json
    • Body:
      {
        "description": "Generated description"
      }

/tags

  • Method: GET, POST
  • Description: Generates social media tags for an image description.
  • Query Parameters:
    • image_description (required): The description of the image.
  • Response:
    • Content-Type: application/json
    • Body:
      {
        "tags": [
          "tag1",
          "tag2",
          ...
        ]
      }

Error Handling

The application handles two types of errors: 400 Bad Request and 500 Internal Server Error.

  • 400 Bad Request: Occurs when a required query parameter is missing or invalid. The error message is returned in the response body as JSON.
  • 500 Internal Server Error: Occurs when there is an error generating captions, descriptions, or tags. The error message is returned in the response body as JSON.

Invalid Paths

If an invalid path is requested, the application redirects the user back to the home endpoint (/).

Logging

The application logs all debug-level messages to a log file. The log file is created in the static/logs directory with the name format MM_DD_YYYY_HH-MM-SS_app.log, where MM_DD_YYYY_HH-MM-SS represents the current date and time when the application started.

Running the Application

To run the application, execute the following command:

python wsgi.py

By default, the application runs in debug mode, which enables auto-reloading on code changes. You can access the application in your web browser at http://localhost:5000.

License

This project is licensed under the MIT License.