Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huggingface API #238

Open
branaway opened this issue May 25, 2024 · 2 comments
Open

huggingface API #238

branaway opened this issue May 25, 2024 · 2 comments

Comments

@branaway
Copy link

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
Copy link
Member

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

@branaway
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants