Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This repository illustrates how to use the Hotpot.ai API. Our API provides Stable Diffusion, image generator, text-to-image generator, background removal, image upscaler, photo restoration, and picture colorization.

License

NotificationsYou must be signed in to change notification settings

HotpotDesign/api-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 

Repository files navigation

Stable Diffusion API

Hotpot.ai offers aStable Diffusion API with three flavors: (1) budget (2) standard and (3) premium.

Art Maker

// Set URL to monitor.consturl='https://hotpot-temporary-images.s3.us-east-2.amazonaws.com/520.txt';pollAndRenderUrl(url);functionpollAndRenderUrl(url){// Set how often to poll@url. If set lower than 70000, your account will incur S3 charges.constpollDuration=70000;// Create an interval to check@url every @pollDuration milliseconds.constinterval=setInterval(async()=>{constresponse=awaitfetch(url,{method:'GET',cache:'no-cache',redirect:'follow'});// File exists at@url?if(response.status===200){// If here, file exists so do something with it.// Clear@interval and stop polling.clearInterval(interval);}},pollDuration);}

Background Remover

The examples below illustrate how to invoke theBackground Remover API in different languages.

Curl

curl -H'Authorization: API_KEY_HERE' \     -F'image=@/full/path/to/image.jpg' \     -o'/full/path/to/image-nobg.jpg' \     https://api.hotpot.ai/remove-background

Node

Install theform-data library first:

yarn add form-data
'use strict';constfs=require('fs');consthttps=require('https');constFormData=require('form-data');constform=newFormData();// change to a full file path of the image you want to transformform.append('image',fs.createReadStream('/full/path/to/image.jpg'));constcustomHeaders={'Authorization':'API_KEY_HERE'}// setting a correct MIME type and (multipart/form-data) a boundary for the payloadconstheaders={...form.getHeaders(), ...customHeaders}constoptions={method:'POST',hostname:'api.hotpot.ai',port:443,path:'/remove-background',headers:headers,encoding:null,};constrequest=https.request(options,response=>{constbody=[];response.on('data',chunk=>{body.push(Buffer.from(chunk));})response.on('end',()=>{// change to a full file path where you want to save the resulting imagefs.writeFileSync('/full/path/to/image-nobg.jpg',Buffer.concat(body),'binary');request.end();})});request.on('error',error=>{console.error(error);});form.pipe(request);

Python

Install therequests library first:

pip3 install requests
importrequestsheaders= {'Authorization':'API_KEY_HERE',}# change to a full file path of the image you want to transformbody= {'image':open('/full/path/to/image.jpg','rb'),}response=requests.post('https://api.hotpot.ai/remove-background',headers=headers,files=body)# change to a full file path where you want to save the resulting imagewithopen('/full/path/to/image-nobg.jpg','wb')asfile:file.write(response.content)

PHP

<?php$ch =curl_init();// change to a full file path of the image you want to transform$body = ['image' =>newCurlFile('/full/path/to/image.jpg')];curl_setopt($ch,CURLOPT_URL,'https://api.hotpot.ai/remove-background');curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$body);$headers =array('Authorization: API_KEY_HERE');curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);$response =curl_exec($ch);curl_close($ch);// change to a full file path where you want to save the resulting imagefile_put_contents('/full/path/to/image-nobg.jpg',$response);

C# Flurl.Http

Install theFlurl.Http library first:

dotnet add package Flurl.Http
usingvarmemoryStream=newMemoryStream(data);varrequest=await"https://api.hotpot.ai/remove-background".WithHeader("Authorization","API_KEY_HERE")// change to a full file path of the image you want to transform.PostMultipartAsync(builder=>builder.AddFile("image","/full/path/to/image.jpg"));varresponse=awaitrequest.GetBytesAsync();// change to a full file path where you want to save the resulting imageawaitFile.WriteAllBytesAsync("/full/path/to/image-nobg.jpg",response);

C# System.Net.Http

Note: theAdd function requires three parameters. Otherwise the binary data will be incorrectly sent as a string.

usingSystem;usingSystem.IO;usingSystem.Net.Http;usingSystem.Threading.Tasks;classProgram{publicstaticasyncTaskMain(string[]args){varclient=newHttpClient();client.DefaultRequestHeaders.Add("Authorization","API KEY HERE");varform=newMultipartFormDataContent();varimage=newByteArrayContent(File.ReadAllBytes("bg.jpg"));form.Add(image,"image","bg.jpg");varresponse=awaitclient.PostAsync("https://api.hotpot.ai/remove-background",form);varresult=awaitresponse.Content.ReadAsByteArrayAsync();System.IO.File.WriteAllBytes("nobg.jpg",result);}}

About

This repository illustrates how to use the Hotpot.ai API. Our API provides Stable Diffusion, image generator, text-to-image generator, background removal, image upscaler, photo restoration, and picture colorization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp