After succesfully building my application in part 1 locally. The next step was connecting comfyui’s api to my flask application and editing my workflows. This part will focus on leveraging GPU power for faster, higher-quality image generation.
By utilizing vast.ai’s GPU capabilities, we can significantly enhance our image generation process. This allows us to: — Increase the number of steps in our KSampler — Produce higher quality outputs — Generate images faster than local CPU processing — Handle more complex image transformations. Changing settings in my Ksampler would create a more accurate and precise photo generation process. Which if I edited the below locally in order to produce higher quality it would currently take to long and utilize to much cpu power on my macbook .
Since we developed locally on MacBook but need to deploy to vast.ai’s Ubuntu environment, we need to create a cross-platform compatible Docker image. This requires: 1. A Docker Hub account for storing our image 2. Using `buildx` for cross-platform compatibility between Mac and Linux 3. Proper configuration of CUDA support for GPU acceleration.
The Docker options include several crucial configurations: — Port 5000: Flask web application — Port 8188: ComfyUI interface — Port 8080: Jupyter notebook access — Static IP: Required for stable WebSocket connections — OpenAI API key: For generating hair styling instructions
After building the image successfully and pushing it .
The next step I took was creating a new template on Vast in order to use the docker image.
After clicking create new template I was brought to the page below.
As you see above, I’d deleted the pre filed image path section with the correct image and path to the docker image I’d created earlier.
As you see above Vast gives you the ability to add specific docker options before launch. For my app I needed to open specific ports and also add an env variable with my openai api key. Here is what my docker options looked like for this.
-e DATA_DIRECTORY=/workspace/ -e JUPYTER_DIR=/ -e STATIC_IP=195.0.159.206 -e OPENAI_API_KEY=your_api_key_here -p 5000:5000 -p 8188:8188 -p 8080:8080
Vast gives you the options to choose from different Launch Modes. I chose the Jupyter notebook launch mode because it provides: — Direct access to the code for debugging — An interactive development environment — Built-in terminal access — Easy file management This makes troubleshooting and monitoring much easier than other launch options.”
For the on-start script options (above) this is what was added. Below the onstart script you will also need to insert your username and password if the docker image you created is private in order to authenticate.
Okay once everything is setup be sure to unclick public templates unless you want your new template public. Lastly click save. Choose your template you’ve created then choose your instance. Be sure to choose an instance if it’s needed that gives you the ability to have a static ip if it’s needed.
I’d selected an instance with a static ip ahead of time, so I had to go to my instances page. From there I clicked the pencil button seen below.
Then edited the current image by replacing it with my new docker image.
From there I recreated the instance with the new template.
And from there I was able to see my website live on Vast.ai
In Part 3, we’ll explore expanding this application from a prototype to a more robust tool. We’ll cover: — Implementing additional AI models — Enhancing the user interface — Adding more customization options — Optimizing performance with vast.ai’s GPU capabilities If you enjoyed this guide or have questions about deploying your own AI applications on vast.ai, feel free to reach out!