Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement sketch-to-image pipeline and route #231

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

yaodingyd
Copy link
Contributor

@yaodingyd yaodingyd commented Oct 18, 2024

implement / close livepeer/bounties#57

Also added example in cmd/example/sketch-to-image

go run cmd/examples/sketch-to-image/main.go 1 "a lamp on a desk" runner/example_data/sketch.png

Local testing guideline:

  1. start sketch-to-image pipeline docker run --name sketch-to-image -e PIPELINE=sketch-to-image -e MODEL_ID=xinsir/controlnet-scribble-sdxl-1.0 -p 8000:8000 -v ./models:/models livepeer/ai-runner:latest
  2. run this script
import base64
import io

from PIL import Image
import requests

def call_api_and_save_image():
    url = "http://localhost:8000/sketch-to-image"
    prompt = "A lamp with a shade on a table"
    # Request headers
    data = {
        "prompt": prompt,
        "negative_prompt": "nothing",
    }

    image_path = "run.png"
    with open(image_path, "rb") as image_file:
        files = {"image": ("run.png", image_file, "image/png")}

        response = requests.post(url, data=data, files=files)

    # Make the POST request

    # Check if the request was successful
    if response.status_code == 200:
        # Get the image URL from the response
        response_dict = response.json()

        base64_string = response_dict.get("images")[0].get("url")
        image_url = base64_string.split(",")[1]

        if image_url:
            image_data = base64.b64decode(image_url)

            # Use io.BytesIO to convert the bytes into a file-like object
            image_buffer = io.BytesIO(image_data)

            # Open the image using PIL
            image = Image.open(image_buffer)

            # Save the image to a file (e.g., "output_image.png")
            image.save("output_image.png", format="PNG")

        else:
            print("No image URL found in the response")
    else:
        print(f"API request failed. Status code: {response.status_code}")


# Call the function with the prompt
call_api_and_save_image()
  1. result
Screenshot 2024-10-17 at 10 18 43 PM

@yaodingyd
Copy link
Contributor Author

@rickstaa could you take a look when you get a chance?

@yaodingyd
Copy link
Contributor Author

@rickstaa another gentle ping if you get chance to review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sketch-to-Image Pipeline Implementation Bounty [$900]
1 participant