Skip to content

Visage API is a FastAPI service that generates images from a text prompt while preserving the identity of a reference image using face swapping. πŸš€

Notifications You must be signed in to change notification settings

SpectreSpect/visage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Visage API

Visage is a FastAPI-based application that generates images using a reference image and a text prompt. The API integrates Midjourney-style image generation with face swapping to retain the reference subject's identity in the generated output.

πŸš€ Features

  • Accepts a reference image and a text prompt
  • Generates an image based on the prompt
  • Performs face swapping to maintain the reference subject's identity
  • Returns the final face-swapped generated image
  • Logs all requests and errors for debugging

πŸ“¦ Installation

1. Clone the Repository

git clone https://github.com/SpectreSpect/visage.git
cd visage

2. Set Up a Virtual Environment (optional but recommended)

python -m venv venv
source venv/bin/activate  # On Windows, use: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Set Up Environment Variables

Create a .env file in the root directory and add:

GPTUNNEL_API_KEY=your_gptunnel_api_key
IMGBB_API_KEY=your_imgbb_api_key
DEBUG=True  # Set to False in production

πŸš€ Running the API

Start the FastAPI server:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

The API will be available at:

http://127.0.0.1:8000

πŸ“– API Endpoints

1. Health Check

GET /

Checks if the API is running.

{
  "message": "Welcome to the Visage API!"
}

2. Generate Image

POST /generate

Generates an image based on a reference image and a text prompt, then performs face swapping.

πŸ”Ή Request Parameters:

Parameter Type Required Description
prompt string βœ… Yes Text description of the desired image.
image file βœ… Yes Reference image of the person.

πŸ”Ή Example Request:

import requests

url = "http://127.0.0.1:8000/generate"
files = {"image": open("image.jpg", "rb")}
data = {"prompt": "A snowy winter landscape with a man in warm clothing."}
response = requests.post(url, files=files, data=data)

if response.status_code == 200:
    with open("output.png", "wb") as file:
        file.write(response.content)

πŸ”Ή Example Response:

  • Success (200 OK): Returns the generated face-swapped image (image/png).
  • Failure (400/500): Returns an error message.

πŸ“‚ Logging

  • Logs are saved to logs/app.log.
  • Uploaded images are stored in:
    • logs/uploads/reference/
    • logs/uploads/generated/
    • logs/uploads/face_swapped/
  • Errors are logged with detailed stack traces (if DEBUG=True).

πŸ› οΈ Technologies Used

  • FastAPI (API Framework)
  • PIL (Pillow) (Image Processing)
  • NumPy (Array Manipulation)
  • Requests (API Calls)
  • Uvicorn (ASGI Server)

πŸ“œ License

This project is licensed under the MIT License.

About

Visage API is a FastAPI service that generates images from a text prompt while preserving the identity of a reference image using face swapping. πŸš€

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages