Cao Minh Duc
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Stable Diffusion API: `sdapi/v1/img2img` The `sdapi/v1/img2img` endpoint of the Stable Diffusion API allows you to generate realistic images based on text prompts and source image. It utilizes the Stable Diffusion algorithm to produce high-quality images that align with the given input. ## Endpoint Details - **URL:** `http://stablediffusionalb-1002295627.us-west-2.elb.amazonaws.com/sdapi/v1/img2img` - **HTTP Method:** POST - **Content Type:** JSON ## Request Payload The request payload should be a JSON object containing the following parameters: - `prompt` (string, required): The main text prompt describing the desired image. - `negative_prompt` (string, optional): Additional text prompt describing elements or qualities to avoid in the generated image. - `pic` (list, required): The base64 of the source image. - `seed` (integer, optional): Seed value for reproducibility. Use `-1` for random seed. - `sampler_name` (string, optional): The name of the sampling algorithm to use. Defaults to `"DPM++ SDE Karras"`. - `steps` (integer, optional): The number of steps for diffusion. Defaults to `20`. - `cfg_scale` (integer, optional): The scale of the diffusion model configuration. Defaults to `7`. - `width` (integer, optional): The desired width of the generated image. Defaults to `512`. - `height` (integer, optional): The desired height of the generated image. Defaults to `768`. - `restore_faces` (boolean, optional): Indicates whether to restore faces in the generated image. Defaults to `True`. - `alwayson_scripts` (object, optional): Additional scripts to run during the diffusion process. This object contains the script names as keys and their corresponding arguments as values. - `roop` (object, required): The script name for the Roop script. Contains the following arguments: - `args` (list, required): A list of arguments specific to the Roop script. These arguments control the behavior and characteristics of the generated image. The list format and argument values should be provided as shown in the example. - `Base64 of Face Image` (string): The base64-encoded representation of the face image to be used for face swapping. This image should be in JPEG format. - `Enable` (boolean): Indicates whether face swapping should be enabled or disabled. - `Comma separated face number(s)` (string): A comma-separated list of face numbers in the image to perform face swapping. The face numbers start from 0. - `Model` (string): The path to the face swapping model. Currently, the available model is located at "/home/ubuntu/apps/stable-diffusion-webui/models/roop/inswapper_128.onnx". - `Restore Face` (string): The method used to restore faces in the generated image. It can take one of the following values: "None", "CodeFormer", or "GFPGAN". - `Restore visibility` (float): The visibility of the restored face(s) in the generated image. It is a value between 0 and 1, with a step size of 0.1. A value of 1 represents full visibility. - `Upscaler` (string): The upscaling method to enhance the generated image. It can take one of the following values: "None", "Lanczos", "Nearest", "ESRGAN_4x", "LDSR", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B", "ScuNET GAN", "ScuNET PSNR", or "SwinIR 4x". - `Upscaler scale` (float): The scale factor for the upscaling method. It is a value between 1 and 8, with a step size of 0.1. Higher values result in larger upscaled images. - `Upscaler visibility (if scale = 1)` (float): The visibility of the upscaled image when the scale factor is 1. It is a value between 0 and 1, with a step size of 0.1. A value of 1 represents full visibility. - `Swap in source image` (boolean): Indicates whether face swapping should be performed in the source image. - `Swap in generated image` (boolean): Indicates whether face swapping should be performed in the generated image. ## Response The response from the API will be a JSON object containing the following information: - `images` (list): A list of base64-encoded strings representing the generated image(s). ## Example ```python #Simple img2img API test import io import requests from PIL import Image import base64 import json #grab our two files from disk (a pic, and the b&w mask for it) and convert them to text encoding to put them in the json image_file = "elonmusk.jpeg" im = Image.open(image_file) img_bytes = io.BytesIO() im.save(img_bytes, format='JPEG') img_base64 = base64.b64encode(img_bytes.getvalue()).decode('utf-8') args=[img_base64,True,'0','/home/ubuntu/apps/stable-diffusion-webui/models/roop/inswapper_128.onnx','CodeFormer',1,None,1,'None',False,True] prompt = "Realistic image style,Vertical orientation, Man,White short hair,Shoulder-length, crying" neg = "ng_deepnegative_v1_75t, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, normal quality, ((monochrome)), ((grayscale)), (verybadimagenegative_v1.3:0.8), negative_hand-neg, (lamp), badhandv4" payload = { "prompt": prompt, "negative_prompt": neg, "init_images": [img_base64], "seed": -1, "sampler_name": "DPM++ SDE Karras", "steps": 20, "cfg_scale": 7, "width": 512, "height": 768, "restore_faces": True, "alwayson_scripts": {"roop":{"args":args}} } response = requests.post('http://stablediffusionalb-1002295627.us-west-2.elb.amazonaws.com/sdapi/v1/img2img', json=payload) result = response.json() print(result) images = result['images'] image_bytes = base64.b64decode(images[0]) image_buffer = io.BytesIO(image_bytes) image = Image.open(image_buffer) image.save('output_img2img_1.jpg') ``` Please note that the example provided above assumes that the necessary libraries are installed and the required image file exists in the specified location. Make sure to replace the appropriate values in the example code, such as the `image_file` path and the API endpoint `address`, according to your specific setup. The resulting generated image will be saved as `output_image_1.jpg` in the current directory.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully