npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ai-generate-and-pinata-host

v1.1.1

Published

> Smart solution for hosting AI generated images

Downloads

18

Readme

ai-generate-and-pinata-host

Smart solution for hosting AI generated images

Why

  • Offers popular integrated AI image generation options from Hugging Face, OpenAI, and Cloudflare.
  • Automatically hosts generated images on Pinata’s Web3 platform, returning a usable URL immediately.
  • Solves the hosting problem for developers who need to quickly store and access AI-generated images.
  • Flexible, decentralized hosting without the need for centralized storage services.

Why not

  • Requires setting up Pinata API keys for hosting, which adds a bit of configuration overhead.
  • You may need to manage API rate limits depending on the image generation tool used (e.g., OpenAI, Hugging Face).

Prerequisite

  • A valid Pinata account with access to API keys for file hosting.
  • API keys or access tokens from Hugging Face, OpenAI, Cloudflare, or any supported AI image generation service.

Install

npm install ai-generate-and-pinata-host@latest

Config

Make sure you have your .env file populated with the mandatory and optional keys.

Here is the boilerplate of how your .env should look like :

# Mandatory configuration
# Pinata API Configuration
PINATA_GATEWAY_DOMAIN=beige-effective-bison-926.mypinata.cloud
PINATA_GATEWAY_PATH=https://beige-effective-bison-926.mypinata.cloud/ipfs
PINATA_JWT_KEY=<secret>

# 1 Mandatory, 2 Optional (you can choose which AI you are gonna use, and populate those keys here .)

# Cloudflare API Configuration
CLOUDFLARE_API_KEY=<secret>
CLOUDFLARE_ACCOUNT_ID=90fc83070e95f461645dd2ed67ef202d
CLOUDFLARE_IMAGE_MODEL=@cf/stabilityai/stable-diffusion-xl-base-1.0

# Hugging Face API Configuration
HUGGING_FACE_ACCESS_TOKEN=<secret>

#Open AI API Configuration
OPEN_AI_API_KEY=<secret>

Usage

import { generateCloudflareHostedUrl, generateHuggingFaceHostedUrl, generateOpenAIHostedUrl } from "ai-generate-and-pinata-host";

let result = {}

let prompt = `Witch running a marathon with a dog and horse`;

const openAiData = await generateOpenAIHostedUrl({prompt});
result.openAiUrl = openAiData.pinataUrl;

console.log("Open AI generated image uploaded, here is the URL : " + result.openAiUrl);

const cloudflareData = await generateCloudflareHostedUrl({prompt});
result.cloudflareUrl = cloudflareData.pinataUrl;

console.log("Cloudflare AI worker generated image uploaded, here is the URL : " + result.cloudflareUrl);


const huggingfaceData = await generateHuggingFaceHostedUrl({prompt});
result.huggingfaceUrl = huggingfaceData.pinataUrl;

console.log("Huggingface AI generated image uploaded, here is the URL : " + result.huggingfaceUrl);


console.log("Here is the output : ")
console.log(result);

Output

┌──(kali㉿kali)-[~/ai-generate-and-pinata-host]
└─$ node app.js
Open AI generated image uploaded, here is the URL : https://beige-effective-bison-926.mypinata.cloud/ipfs/bafybeiabxkxhljzhlpadr3yebbmwkp2dqcv7ntdjo7rvc2mgawonosmogi

Cloudflare AI worker generated image uploaded, here is the URL : https://beige-effective-bison-926.mypinata.cloud/ipfs/bafybeiglgvjxalzf4ch5mdhsqsyz2u2m737f6lpkran2j6ejoim4ni6yd4

Huggingface AI generated image uploaded, here is the URL : https://beige-effective-bison-926.mypinata.cloud/ipfs/bafkreih7xdlfqz7ltgvarxmclvezby3dv4mhf4hex7zw76hlceobfyn3fy

Here is the output : 
{
  openAiUrl: 'https://beige-effective-bison-926.mypinata.cloud/ipfs/bafybeiabxkxhljzhlpadr3yebbmwkp2dqcv7ntdjo7rvc2mgawonosmogi',
  cloudflareUrl: 'https://beige-effective-bison-926.mypinata.cloud/ipfs/bafybeiglgvjxalzf4ch5mdhsqsyz2u2m737f6lpkran2j6ejoim4ni6yd4',
  huggingfaceUrl: 'https://beige-effective-bison-926.mypinata.cloud/ipfs/bafkreih7xdlfqz7ltgvarxmclvezby3dv4mhf4hex7zw76hlceobfyn3fy'
}