How to Set up Fooocus with API Configuration on AWS - Developer Guide

How to Set up Fooocus with API Configuration on AWS - Developer Guide

Welcome to the Fooocus 2.0 Setup Guide, your key to unlocking the full potential of our AI-powered image creation tool. In this step-by-step guide, we'll walk you through the seamless installation process.

Prerequisites:

Before you begin, ensure you have the following prerequisites in place:

Launching the AMI

Step 1: Find and Select 'Fooocus 2.0' AMI

  1. Log in to your AWS Management Console.
  2. Navigate to the "Fooocus 2.0" in  AWS Marketplace.

Step 2:  Initial Setup & Configuration

  1. Click the "Continue to Subscribe" button.
  2. After subscribing, you will need to accept the terms and conditions. Click on "Accept Terms" to proceed.
  3. Please wait for a few minutes while the processing takes place. Once it's completed, click on "Continue to Configuration".
  4. Select the "CloudFormation Template for fooocus" as the fulfilment option and choose your preferred region on the "Configure this software" page. Afterward, click the "Continue to Launch" button.
  5. From the "Choose Action" dropdown menu in "Launch this software" page, select "Launch CloudFormation" and click "Launch" button.

Create CloudFormation Stack

Step1: Create stack

  1. Ensure the "Template is ready" radio button is selected under "Prepare template".

2. Click "Next".

Step2: Specify stack options

  1. Provide a unique "Stack name".
  2. Provide the "Admin Email" for SSL generation.
  3. For "DeploymentName", enter a name of your choice.
  4. Provide the domain name for "FooocusDomainName". (Fooocus will automatically try to setup SSL based on provided domain name, if that domain hosted on Route53. Please make sure your turn domain name hosted on route53. If its unsuccessful then you have to setup SSL manually)
  5. Choose an instance type, "FooocusInstanceType" (Recommended: g4dn.2xlarge).
  6. Select your preferred "keyName".
  7. Set "SSHLocation" as "0.0.0.0/0".
  8. Keep "SubnetCidrBlock" as "10.0.0.0/24".
  9. Keep "VpcCidrBlock" as "10.0.0.0/16".
  10. Click "Next".

Step3: Configure stack options

  1. Under "Stack failure options", select "Roll back all stack resources".
  2. click "Next".

Step4: Review

  1. Review and verify the details you've entered.

2. Tick the box that says, "I acknowledge that AWS CloudFormation might create IAM resources with custom names".

3. Click "Submit".

Afterward, you'll be directed to the CloudFormation stacks page.

You can easily locate the corresponding stack by searching for the stack name you entered in Step 2.

Please wait for 5-10 minutes until the stack has been successfully created. Afterward, you can click the "Refresh" button under the "Stacks" section.

Access Fooocus Dashboard

Method1: Using public IP
Click the link located under the "DashboardUrlIp" section in the "Outputs" tab. This will direct you to the Fooocus Dashboard.

Method2: Using Domain

  1. Copy the Public IP address indicated as "PublicIp" in the "Outputs" tab.

2. Go to AWS "Route 53" and navigate to "Hosted Zones".

3. From there, select the domain you provided to "FooocusDomainName".

4. Click "Edit record" in the "Record details" and then paste the copied "PublicIp" into the "value" textbox and click "Save".

5. Open a new tab and navigate to the "FooocusDomainName" to access the Fooocus dashboard.

(If you encounter a "502 Bad Gateway error", please wait for about 5 minutes before refreshing the page)

Generate SSL Manually

Fooocus will automatically try to setup SSL based on provided domain name, if that domain hosted on Route53. If its unsuccessful then you have to setup SSL manually. Admin Email is acquiring for generate SSL certificates.

Step1: Point domain name into server IP

Follow steps 1 t0 4 in the "Method 2: Using Domain" section mentioned above, under the "Access Fooocus Dashboard", to point domain name into the server's IP.

Step2: Log in to the server

  1. Copy the Public IP address indicated as "PublicIp" in the "Outputs" tab.

2. Open the terminal and go to the directory where your private key is located.

3. Paste the following command into your terminal and press Enter: ssh -i <your key name> ubuntu@<Public IP address>.

3. Type "yes" and press Enter. This will log you into the server.

Step3: Generate SSL

Paste the following command into your terminal and press Enter:

sudo /root/certificate_generate_standalone.sh

Shutting Down

  1. Click the link labeled "Fooocus" in the "Resources" tab to access the EC2 instance, you will be directed to the Fooocus instance in EC2.

2. Select the fooocus instance by marking the checkbox and click "Stop instance" from the "Instance state" dropdown. You can restart the instance at your convenience by selecting "Start instance".

Remove Fooocus

Delete the stack that has been created in the AWS Management Console under 'CloudFormation Stacks' by clicking the 'Delete' button.

Technical Support

Reach out to Meetrix Support (support@meetrix.io)  for assistance with Fooocus issues.

API Documentation

1. Generate text-to-image

Generate images based on the provided prompt.

  • Endpoint: /api/v1/generation/text-to-image
  • Method: POST
  • Request Body:
    (Enter the text in 'prompt')
{
  "prompt": "car",
  "negative_prompt": "",
  "style_selections": [
    "Fooocus V2",
    "Fooocus Enhance",
    "Fooocus Sharp"
  ],
  "performance_selection": "Speed",
  "aspect_ratios_selection": "1152*896",
  "image_number": 1,
  "image_seed": -1,
  "sharpness": 2,
  "guidance_scale": 4,
  "base_model_name": "juggernautXL_version6Rundiffusion.safetensors",
  "refiner_model_name": "None",
  "refiner_switch": 0.5,
  "loras": [
    {
      "model_name": "sd_xl_offset_example-lora_1.0.safetensors",
      "weight": 0.1
    }
  ],
  "advanced_params": {
    "adaptive_cfg": 7,
    "adm_scaler_end": 0.3,
    "adm_scaler_negative": 0.8,
    "adm_scaler_positive": 1.5,
    "canny_high_threshold": 128,
    "canny_low_threshold": 64,
    "controlnet_softness": 0.25,
    "debugging_cn_preprocessor": false,
    "debugging_inpaint_preprocessor": false,
    "disable_preview": false,
    "freeu_b1": 1.01,
    "freeu_b2": 1.02,
    "freeu_enabled": false,
    "freeu_s1": 0.99,
    "freeu_s2": 0.95,
    "inpaint_disable_initial_latent": false,
    "inpaint_engine": "v1",
    "inpaint_erode_or_dilate": 0,
    "inpaint_respective_field": 1,
    "inpaint_strength": 1,
    "invert_mask_checkbox": false,
    "mixing_image_prompt_and_inpaint": false,
    "mixing_image_prompt_and_vary_upscale": false,
    "overwrite_height": -1,
    "overwrite_step": -1,
    "overwrite_switch": -1,
    "overwrite_upscale_strength": -1,
    "overwrite_vary_strength": -1,
    "overwrite_width": -1,
    "refiner_swap_method": "joint",
    "sampler_name": "dpmpp_2m_sde_gpu",
    "scheduler_name": "karras",
    "skipping_cn_preprocessor": false
  },
  "require_base64": false,
  "async_process": false,
  "webhook_url": "string"
}
  • Response Body:
[
  {
    "base64": null,
    "url": "http://fooocus-test-prod.meetrix.io/api/files/2024-02-16/d0c43ae9-a4fa-4111-ac86-3976fcdaf3ea.png",
    "seed": "7157889350071648458",
    "finish_reason": "SUCCESS"
  }
]

2. List Models

Retrieves a list of available models.

  • Endpoint: /api/v1/engines/all-models
  • Method: GET
  • Response Body:
{
  "model_filenames": [
    "juggernautXL_version6Rundiffusion.safetensors",
    "sd_xl_base_1.0_0.9vae.safetensors",
    "sd_xl_refiner_1.0_0.9vae.safetensors"
  ],
  "lora_filenames": [
    "sd_xl_offset_example-lora_1.0.safetensors"
  ]
}

You can find out the full API documentation here https://github.com/konieshadow/Fooocus-API/blob/main/docs/api_doc_en.md

Discover Seamless Meetings with >>>
Meetrix