https://github.com/coslynx/ghibli-image-ai
Transform your photos into Ghibli art using OpenAI AI tech... Created at https://coslynx.com
https://github.com/coslynx/ghibli-image-ai
ai code-generation coslynx css3 developer-tools devops docker fastapi generative-art ghibli html5 image-generation javascript machine-learning mvp openai-api python rest-api style-transfer
Last synced: 6 months ago
JSON representation
Transform your photos into Ghibli art using OpenAI AI tech... Created at https://coslynx.com
- Host: GitHub
- URL: https://github.com/coslynx/ghibli-image-ai
- Owner: coslynx
- Created: 2025-04-06T13:21:08.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-04-06T13:49:37.000Z (6 months ago)
- Last Synced: 2025-04-06T14:28:59.789Z (6 months ago)
- Topics: ai, code-generation, coslynx, css3, developer-tools, devops, docker, fastapi, generative-art, ghibli, html5, image-generation, javascript, machine-learning, mvp, openai-api, python, rest-api, style-transfer
- Language: TypeScript
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ghibli-image-aiTransforms user-uploaded images into the enchanting Studio Ghibli art style using the OpenAI DALL-E API.
Developed with the software and tools below.
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
## ๐ Table of Contents
- ๐ Overview
- ๐ฆ Features
- ๐ Structure
- ๐ป Installation
- ๐๏ธ Usage
- ๐ Hosting
- ๐ API Documentation
- ๐ License
- ๐ Authors## ๐ Overview
The `ghibli-image-ai` repository contains a Minimum Viable Product (MVP) that allows users to upload an image and receive a transformed version mimicking the distinct visual style of Studio Ghibli films. This is achieved by leveraging OpenAI's DALL-E 2 image editing capabilities via a simple web interface. The tech stack includes React (with Vite) for the frontend, Tailwind CSS for styling, TypeScript for type safety, and a Node.js backend deployed as a Vercel Serverless Function to handle communication with the OpenAI API securely.## ๐ฆ Features
| | Feature | Description |
|----|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| โ๏ธ | **Architecture** | Frontend built with React & Vite, styled with Tailwind CSS. Backend is a Node.js Vercel Serverless Function interacting with the OpenAI API. Follows a component-based UI structure with custom hooks for state management. |
| ๐ผ๏ธ | **Image Upload** | User-friendly drag-and-drop or click-to-select image uploader (`react-dropzone`) with validation for file type (PNG, JPEG, WEBP) and size (Max 4MB/5MB Frontend). |
| โจ | **AI Transformation**| Utilizes OpenAI's DALL-E 2 `images.createEdit` API endpoint to apply a "Studio Ghibli style" prompt to the uploaded image. |
| ๐ฅ๏ธ | **Result Display** | Displays the generated Ghibli-style image upon successful processing or shows clear error messages if the process fails. |
| ๐ | **Loading State** | Provides visual feedback (loading spinner) to the user while the image is being processed by the backend and OpenAI. |
| ๐ | **Security** | Handles the OpenAI API key securely on the backend (via environment variables) and implements basic input validation on both client and server. |
| ๐งช | **Testing** | Includes unit/integration tests using Vitest and React Testing Library for the core API endpoint (`api/generate.ts`) and key UI components (`ImageUploader.tsx`). |
| ๐ | **Documentation** | This README provides an overview, setup instructions, usage guide, and API details. Code includes JSDoc/TSDoc comments. |
| ๐ | **Dependencies** | Key dependencies include `react`, `react-dom`, `openai`, `axios`, `react-dropzone`, `vite`, `tailwindcss`, `typescript`, `@vercel/node`. |
| ๐งฉ | **Modularity** | Well-structured codebase with separate directories for components (`src/components`), hooks (`src/hooks`), types (`src/types`), styles (`src/styles`), API logic (`api`), and tests (`tests`). |
| ๐ | **Deployment** | Designed for easy deployment on the Vercel platform, leveraging serverless functions for the backend logic. |
| โก๏ธ | **Performance** | Frontend performance optimized by Vite. Backend performance depends on Vercel function execution and OpenAI API response times. |## ๐ Structure
```text
ghibli-image-ai/
โโโ api/
โ โโโ generate.ts # Vercel Serverless Function for OpenAI interaction
โโโ public/
โ โโโ favicon.ico # Application favicon
โโโ src/
โ โโโ components/ # Reusable React UI components
โ โ โโโ ErrorMessage.tsx
โ โ โโโ ImageDisplay.tsx
โ โ โโโ ImageUploader.tsx
โ โ โโโ LoadingSpinner.tsx
โ โโโ hooks/ # Custom React hooks
โ โ โโโ useImageGenerator.ts # Hook for managing generation state and API calls
โ โโโ styles/ # Styling files
โ โ โโโ global.css # Global CSS and Tailwind directives
โ โโโ types/ # TypeScript type definitions
โ โ โโโ api.ts # API request/response types
โ โโโ App.tsx # Main application component
โ โโโ main.tsx # Application entry point
โโโ tests/
โ โโโ api/
โ โ โโโ generate.test.ts # Tests for the API handler
โ โโโ components/
โ โโโ ImageUploader.test.tsx # Tests for the ImageUploader component
โโโ .env # Local environment variables (GITIGNORED!)
โโโ .eslintrc.cjs # ESLint configuration
โโโ .gitignore # Git ignore rules
โโโ .prettierrc # Prettier configuration
โโโ package.json # Project dependencies and scripts
โโโ postcss.config.js # PostCSS configuration (for Tailwind/Autoprefixer)
โโโ tailwind.config.js # Tailwind CSS configuration
โโโ tsconfig.json # TypeScript configuration (frontend)
โโโ tsconfig.node.json # TypeScript configuration (backend/Node.js)
โโโ vite.config.js # Vite configuration
โโโ README.md # This file
โโโ (other config files like yarn.lock or package-lock.json)
```## ๐ป Installation
> [!WARNING]
> ### ๐ง Prerequisites
> - **Node.js:** v18.0.0 or higher (check `package.json` engines)
> - **npm** or **yarn:** Package manager
> - **Vercel CLI:** Required for local development (`npm install -g vercel`)
> - **OpenAI API Key:** Obtain from [OpenAI Platform](https://platform.openai.com/)### ๐ Setup Instructions
1. **Clone the repository:**
```bash
git clone https://github.com/coslynx/ghibli-image-ai.git
cd ghibli-image-ai
```
2. **Install dependencies:**
```bash
npm install
# or
yarn install
```
3. **Configure environment variables:**
* Create a `.env` file in the root directory.
* Copy the contents from the provided `.env` file structure or create it manually.
* Add your OpenAI API key:
```env
# .env
OPENAI_API_KEY=your_openai_api_key_here
```
> [!IMPORTANT]
> Ensure the `.env` file is listed in your `.gitignore` file to prevent committing your API key.## ๐๏ธ Usage
### ๐โโ๏ธ Running the MVP Locally
1. **Start the development server:**
This command uses the Vercel CLI to run the frontend (via Vite) and the serverless function locally, mimicking the Vercel environment.
```bash
npm run dev
# or
vercel dev
```
2. **Access the application:**
* The Vercel CLI will output the local URL, typically `http://localhost:3000` for the Vercel Functions and `http://localhost:5173` (or similar) for the Vite frontend. Open the Vite frontend URL in your browser. The `vite.config.js` proxy ensures API calls from the frontend reach the local serverless function.> [!TIP]
> ### โ๏ธ Configuration
> - The primary configuration is the `OPENAI_API_KEY` in the `.env` file, required for the backend function to authenticate with OpenAI.
> - File upload constraints (size, type) are defined in `src/components/ImageUploader.tsx` (frontend validation) and `api/generate.ts` (backend validation).
> - The specific OpenAI prompt (`GHIBLI_PROMPT`) is defined in `api/generate.ts`.### โจ How it Works
1. Open the application in your web browser.
2. Use the drag-and-drop area or click to select a `.png`, `.jpg`, `.jpeg`, or `.webp` image file (max 5MB for frontend check, 4MB backend limit).
3. The application uploads the image to the backend `/api/generate` endpoint.
4. The backend function sends the image and a predefined "Ghibli style" prompt to the OpenAI DALL-E API.
5. While processing, a loading spinner is displayed.
6. If successful, the generated Ghibli-style image is displayed.
7. If an error occurs (e.g., invalid file, OpenAI issue, server error), an error message is shown.## ๐ Hosting
### ๐ Deployment Instructions (Vercel)
This project is optimized for deployment on [Vercel](https://vercel.com/).1. **Push to GitHub/GitLab/Bitbucket:** Ensure your code, including the `api` directory and all configurations, is pushed to a Git repository.
2. **Import Project on Vercel:**
* Log in to your Vercel account.
* Click "Add New..." -> "Project".
* Import the Git repository you just pushed.
3. **Configure Project Settings:**
* Vercel should automatically detect the framework preset (Vite).
* Ensure the "Root Directory" is correctly set (usually the repository root).
* The build command (`npm run build` or `yarn build`) and output directory (`dist`) should be detected automatically from `package.json` and `vite.config.js`.
4. **Set Environment Variables:**
* Navigate to your project's settings on Vercel -> "Environment Variables".
* Add the `OPENAI_API_KEY` with your actual OpenAI API key as its value. Ensure it's available for the "Production" environment (and "Preview"/"Development" if needed).
5. **Deploy:** Click the "Deploy" button. Vercel will build the frontend and deploy the serverless function.### ๐ Environment Variables (Production)
The following environment variable MUST be set in your Vercel project settings for the application to function:- `OPENAI_API_KEY`: Your secret OpenAI API key. Required by the `api/generate.ts` serverless function.
## ๐ API Documentation
### ๐ Endpoint- **`POST /api/generate`**
- **Description:** Accepts an image file upload and generates a Ghibli-styled version using OpenAI DALL-E.
- **Request:**
- **Method:** `POST`
- **Headers:** `Content-Type: multipart/form-data`
- **Body:** Form data containing a single field:
- `image`: The image file (`.png`, `.jpg`, `.jpeg`). Max size 4MB (enforced by backend).
- **Response (Success - `200 OK`):**
- **Content-Type:** `application/json`
- **Body:** `GenerateSuccessResponse`
```json
{
"imageUrl": "https://example-openai-url.com/generated-image.png"
}
```
- **Response (Error):**
- **Content-Type:** `application/json`
- **Status Codes:**
- `400 Bad Request`: Invalid input (no file, wrong type, too large, multiple files).
- `405 Method Not Allowed`: Request method was not `POST`.
- `429 Too Many Requests`: Rate limit error from OpenAI (propagated status).
- `500 Internal Server Error`: Server configuration issue (missing API key), OpenAI API failure, or other unexpected server errors.
- **Body:** `GenerateErrorResponse`
```json
{
"error": "Descriptive error message string"
}
```### ๐ Authentication
- The `/api/generate` endpoint itself does not require user authentication in this MVP.
- Authentication with the OpenAI API is handled server-side using the `OPENAI_API_KEY` environment variable within the Vercel Function. **Never expose your OpenAI API key to the frontend.**### ๐ Examples
Interaction with the API is intended through the web UI. A direct API call example using `curl`:```bash
# Replace 'path/to/your/image.png' with the actual file path
# Replace 'YOUR_DEPLOYED_URL' with the URL where the app is hosted
curl -X POST YOUR_DEPLOYED_URL/api/generate \
-F "image=@path/to/your/image.png" \
-o response.json # Save response to a file# Example Success (response.json):
# { "imageUrl": "https://oaidalleapiprodscus.blob.core.windows.net/private/..." }# Example Error (response.json):
# { "error": "Image file too large. Maximum size is 4MB." }
```> [!NOTE]
> ## ๐ License & Attribution
>
> ### ๐ License
> This Minimum Viable Product (MVP) is licensed under the [GNU AGPLv3](https://choosealicense.com/licenses/agpl-3.0/) license.
>
> ### ๐ค AI-Generated MVP
> This MVP was entirely generated using artificial intelligence through [CosLynx.com](https://coslynx.com).
>
> No human was directly involved in the coding process of the repository: ghibli-image-ai
>
> ### ๐ Contact
> For any questions or concerns regarding this AI-generated MVP, please contact CosLynx at:
> - Website: [CosLynx.com](https://coslynx.com)
> - Twitter: [@CosLynxAI](https://x.com/CosLynxAI)
๐ CosLynx.com
Create Your Custom MVP in Minutes With CosLynxAI!![]()
![]()
![]()
![]()