Skip to content

A powerful AI-powered image processing API that lets you enhance images, generate new ones from text, remove backgrounds, and generate text - all through simple HTTP endpoints.

Notifications You must be signed in to change notification settings

hode2002/ai-huggingface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Image Processing API

Node.js Hugging Face
TypeScript Express.js Node.js Docker Swagger

What is this?

A powerful AI-powered image processing API that lets you enhance images, generate new ones from text, remove backgrounds, and generate text - all through simple HTTP endpoints.

Features

πŸ–ΌοΈ Image Enhancement

Transform your images with AI-powered upscaling and enhancement.

🎨 Image Generation

Create stunning images from text descriptions using advanced AI models.

βœ‚οΈ Background Removal

Automatically remove backgrounds from any image.

πŸ“ Text Generation

Generate text content based on your prompts.

Getting Started

Prerequisites

  • Node.js v14+
  • Docker (optional)

Quick Start

# Clone and setup
git clone https://github.com/hode2002/ai-huggingface.git
cd ai-huggingface
npm install

# Configure
cp .env.example .env

# Start the server
npm run dev

API Reference

Base URL

http://localhost:3002

Endpoints

Enhance Image

POST /enhance

// Request
{
  "image": "https://example.com/image.jpg",
  "size": "2x"  // Optional: "2x" | "4x" | "8x"
}

// Response
{
  "success": true,
  "data": {
    "enhancedImageUrl": "https://..."
  }
}

Generate Image

POST /generate?model=fluxDev

// Request
{
  "prompt": "A beautiful sunset over mountains",
  "negative_prompt": "blurry, low quality",  // Optional
  "num_inference_steps": 50,                 // Optional
  "guidance_scale": 7.5                      // Optional
}

// Response
{
  "success": true,
  "data": {
    "generatedImageUrl": "https://..."
  }
}

Remove Background

POST /remove-background

// Request
{
  "imageUrl": "https://example.com/image.jpg"
}

// Response
{
  "success": true,
  "data": {
    "imageUrl": "https://..."
  }
}

Generate Text

POST /text

// Request
{
  "prompt": "Write a story about a magical forest",
  "maxLength": 100  // Optional
}

// Response
{
  "success": true,
  "data": {
    "prompt": "Generated text..."
  }
}

Usage Examples

TypeScript

// Enhance an image
const enhanceImage = async (imageUrl: string) => {
  const response = await fetch('http://localhost:3002/enhance', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ image: imageUrl, size: '2x' })
  });
  return response.json();
};

// Generate an image
const generateImage = async (prompt: string) => {
  const response = await fetch('http://localhost:3002/generate?model=fluxDev', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      prompt,
      negative_prompt: 'blurry, low quality',
      num_inference_steps: 50,
      guidance_scale: 7.5
    })
  });
  return response.json();
};

JavaScript

// Remove background
const removeBackground = async (imageUrl) => {
  const response = await fetch('http://localhost:3002/remove-background', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ imageUrl })
  });
  return response.json();
};

// Generate text
const generateText = async (prompt) => {
  const response = await fetch('http://localhost:3002/text', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prompt, maxLength: 100 })
  });
  return response.json();
};

Development

Project Structure

src/
β”œβ”€β”€ controllers/     # API route handlers
β”œβ”€β”€ services/       # Business logic
β”œβ”€β”€ interfaces/     # TypeScript interfaces
β”œβ”€β”€ types/         # Type definitions
β”œβ”€β”€ config/        # Configuration
└── server.ts      # Entry point

About

A powerful AI-powered image processing API that lets you enhance images, generate new ones from text, remove backgrounds, and generate text - all through simple HTTP endpoints.

Topics

Resources

Stars

Watchers

Forks