instantX-research / InstantID

InstantID: Zero-shot Identity-Preserving Generation in Seconds 🔥
https://instantid.github.io/
Apache License 2.0
11.05k stars 805 forks source link

huggingface API #238

Open branaway opened 5 months ago

branaway commented 5 months ago

According to the the sample code in 'Use via API' link down at the bottom of the huggingface app page, I kept getting error:

{
  type: 'status',
  endpoint: '/generate_image',
  fn_index: 2,
  time: 2024-05-25T17:50:27.405Z,
  queue: true,
  message: null,
  stage: 'error',
  code: undefined,
  success: false
}

Here is the source code to invoke the endpoint:

import { Client } from "@gradio/client";
import path from 'path'
import fs from 'fs/promises'

// const response_0 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png");
// const exampleImage = await response_0.blob();

// const response_1 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png");
// const exampleImage2 = await response_1.blob();

 // Read the image file from the local file system
 const imagePath = path.join(process.cwd(), 'imgs/users/OIP.HtnbVUj5aYlTxYh8-eV2eQHaJ3.jpeg');
 const imageBuffer = await fs.readFile(imagePath);
const userImg = new Blob([imageBuffer]);

 // Repeat for the second image if necessary
 const imagePath2 = path.join(process.cwd(), 'imgs/styles/1ac930a169eab44e709b78f7009cc98b.jpeg');
 const imageBuffer2 = await fs.readFile(imagePath2);
 const refImg = new Blob([imageBuffer2]);

const app = await Client.connect("https://instantx-instantid.hf.space/--replicas/5s9fg/");

try {
    const result = await app.predict("/generate_image", [
        userImg,    // blob in 'Upload a photo of your face' Image component
        refImg,     // blob in 'Upload a reference pose image (Optional)' Image component       
        "a nice photo", // string  in 'Prompt' Textbox component        
        "", // string  in 'Negative Prompt' Textbox component       
        "(No style)", // string  in 'Style template' Dropdown component     
        30, // number (numeric value between 1 and 100) in 'Number of sample steps' Slider component        
        0.6, // number (numeric value between 0 and 1.5) in 'IdentityNet strength (for fidelity)' Slider component      
        0.3, // number (numeric value between 0 and 1.5) in 'Image adapter strength (for detail)' Slider component      
        0.4, // number (numeric value between 0 and 1.5) in 'Pose strength' Slider component        
        0.4, // number (numeric value between 0 and 1.5) in 'Canny strength' Slider component       
        0.4, // number (numeric value between 0 and 1.5) in 'Depth strength' Slider component       
        ["pose", 'canny'], // undefined  in 'Controlnet' Checkboxgroup component        
        5, // number (numeric value between 0.1 and 20.0) in 'Guidance scale' Slider component      
        42, // number (numeric value between 0 and 2147483647) in 'Seed' Slider component       
        "EulerDiscreteScheduler", // string  in 'Schedulers' Dropdown component     
        false, // boolean  in 'Enable Fast Inference with LCM' Checkbox component       
        false, // boolean  in 'Enhance non-face region' Checkbox component
    ]);

    console.log(result.data);
}
catch (e) {

    console.error('error;', e)
}
haofanwang commented 5 months ago

The API is turned to closed, thus you cannot call it directly.

branaway commented 5 months ago

Can you make it a paid service? I'm ok with a paid plan.