Skip to content

fal-ai/edit-anything-app

Repository files navigation

edit anything with fal serverless

This is a reference implementation of a Next.js and fal-serverless, to demonstrate how ML models running on serverless GPUs can be used within a web application using Next.js. You can also see a video about it here.

You can see a live demo on editanything.ai. In case you want to run the project yourself, follow the instructions below.

Getting started

Prerequisites

  • Python >=3.8
  • Node.js >= 18.0

Install fal-serverless and authenticate

pip install fal-serverless

After installation is complete, you can authenticate:

fal-serverless auth login

Install next.js dependencies

npm install

Generate authentication keys and set them as environment variables

Generate a secret key for key-based authentication

fal-serverless key generate

Set the generated key ID and secret as environment variables:

export FAL_KEY_ID="your-key-id" FAL_KEY_SECRET="your-key-secret"

Set the Google Cloud Storage bucket name as a secret

The serverless function writes it's results to a GCS bucket.

fal-serverless secrets set GCLOUD_BUCKET_NAME "your-bucket-name"

Set Google Cloud Service Account secret

The web endpoint uses Google Cloud Storage for saving the inference results. So it needs access to a service account json. You can provide it to fal-serverless like this:

fal-serverless secrets set GCLOUD_SA_JSON "$(cat path-to-my-service-account.json)"

Deploy the edit_image and make_masks as web endpoints

fal-serverless function serve serverless/app.py app --alias edit_anything_app

And set the provided URL as an environment variable:

export MASK_FUNCTION_URL=`your_app_endpoint_url`/masks EDIT_FUNCTION_URL=`your_app_endpoint_url`/edit

You can also set these in .env.local file:

FAL_KEY_ID=key_id_value
FAL_KEY_SECRET=key_secret_value
MASK_FUNCTION_URL=mask_endpoint_url
EDIT_FUNCTION_URL=edit_endpoint_url

Start the local dev server

npm run dev

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Make sure you read our Code of Conduct
  2. Fork the project and clone your fork
  3. Setup the local environment with npm install
  4. Create a feature branch (git checkout -b feature/add-cool-thing) or a bugfix branch (git checkout -b fix/smash-that-bug)
  5. Commit the changes (git commit -m 'feat(client): added a cool thing') - use conventional commits
  6. Push to the branch (git push --set-upstream origin feature/add-cool-thing)
  7. Open a Pull Request

Check the good first issue queue, your contribution will be welcome!

License

Distributed under the Apache-2.0 License. See LICENSE for more information.