<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: alisdairbr</title>
    <description>The latest articles on DEV Community by alisdairbr (@alisdairbr).</description>
    <link>https://dev.to/alisdairbr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F496719%2F7e25728e-bc1f-4297-8633-04a1db6af8f7.png</url>
      <title>DEV Community: alisdairbr</title>
      <link>https://dev.to/alisdairbr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alisdairbr"/>
    <language>en</language>
    <item>
      <title>Best Open Source LLMs in 2025</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Fri, 14 Feb 2025 13:23:35 +0000</pubDate>
      <link>https://dev.to/koyeb/best-open-source-llms-in-2025-ldj</link>
      <guid>https://dev.to/koyeb/best-open-source-llms-in-2025-ldj</guid>
      <description>&lt;p&gt;Open source LLMs continue to compete with proprietary models on performance benchmarks for natural language tasks like text generation, code completion, and reasoning. &lt;br&gt;
Despite having fewer resources than closed models, these open &lt;a href="https://www.koyeb.com/blog/what-are-large-language-models" rel="noopener noreferrer"&gt;LLMs&lt;/a&gt; offer cutting-edge AI without the high costs and restrictions of proprietary models. &lt;/p&gt;

&lt;p&gt;However, running these open-source models in production and at scale remains a challenge. Enter &lt;a href="https://www.koyeb.com/blog/serverless-gpus-public-preview-run-ai-workloads-on-h100-a100-l40s-and-more" rel="noopener noreferrer"&gt;Serverless GPUs&lt;/a&gt;: a cost-effective, scalable way to deploy and fine-tune LLMs without managing complex infrastructure. &lt;/p&gt;

&lt;p&gt;In this blog post, we’ll explore the best open LLMs available at the start of 2025, including: &lt;a href="https://www.koyeb.com/deploy/deepseek-r1-qwen-32b" rel="noopener noreferrer"&gt;DeepSeek-R1&lt;/a&gt;, &lt;a href="https://www.koyeb.com/deploy/mistral-small-3-instruct" rel="noopener noreferrer"&gt;Mistral Small 3&lt;/a&gt;, and &lt;a href="https://www.koyeb.com/deploy/qwen-2-5-coder-7b-instruct" rel="noopener noreferrer"&gt;Qwen 2.5 Coder&lt;/a&gt;. After comparing their capabilities and ideal use cases for real-world AI applications, we’ll also share how to fine-tune and deploy them using serverless GPUs for optimized inference and training. &lt;/p&gt;

&lt;h2&gt;
  
  
  DeepSeek-R1 Qwen 32B
&lt;/h2&gt;

&lt;p&gt;DeepSeek released two first-generation reasoning models: DeepSeek-R1-Zero and DeepSeek-R1. &lt;br&gt;
DeepSeek-R1-Zero was trained via large-scale reinforcement learning (RL) without supervised fine-tuning (SFT), allowing it to explore chain-of-thought (CoT) reasoning for complex problem-solving. &lt;/p&gt;

&lt;p&gt;Although this approach led to impressive advancements, DeepSeek-R1-Zero faced challenges, such as: repetition, poor readability, and language mixing. To improve performance, DeepSeek developed DeepSeek-R1, with cold-start data incorporated before RL. &lt;/p&gt;

&lt;p&gt;In addition to these two models, DeepSeek released six models of varying sizes based on Llama and Qwen, including &lt;a href="https://www.koyeb.com/deploy/deepseek-r1-qwen-32b" rel="noopener noreferrer"&gt;DeepSeek-R1-Distill-Qwen-32B&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Distilled models are smaller models that have been trained with the reasoning patterns of larger, more complex models.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model Provider&lt;/strong&gt;: DeepSeek&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Size&lt;/strong&gt;: 32B&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context Length&lt;/strong&gt;: 131K tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comparison to Proprietary Models&lt;/strong&gt;: DeepSeek-R1-Distill-Qwen-32B outperforms OpenAI-o1-mini across various benchmarks. &lt;a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B#4-evaluation-results" rel="noopener noreferrer"&gt;Explore available benchmarks&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills&lt;/strong&gt;: Strong in reasoning, mathematical reasoning, and general natural language tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Languages Supported&lt;/strong&gt;: Primarily trained in English and Chinese&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;License&lt;/strong&gt;: Apache 2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.koyeb.com/deploy/deepseek-r1-qwen-32b" rel="noopener noreferrer"&gt;&lt;strong&gt;Deploy DeepSeek R1 on Koyeb →&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistral Small 3
&lt;/h2&gt;

&lt;p&gt;Mistral AI is a leading provider for AI models, including multimodal models like &lt;a href="https://www.koyeb.com/deploy/pixtral-12b" rel="noopener noreferrer"&gt;Pixtral 12B&lt;/a&gt; and Large, edge models such as Ministral 3B and 8B, LLMs like &lt;a href="https://www.koyeb.com/deploy/mistral-nemo-instruct" rel="noopener noreferrer"&gt;Nemo Instruct&lt;/a&gt;, Codestral for code generation, Mathstral for mathematics, and more.&lt;/p&gt;

&lt;p&gt;Released in January 2025, &lt;a href="https://www.koyeb.com/deploy/mistral-small-3-instruct" rel="noopener noreferrer"&gt;Mistral Small 3 Instruct&lt;/a&gt; is a 24-billion-parameter model that achieves state-of-the-art capabilities comparable to larger models. It is ideal for various text generation tasks, including fast-response conversational agents, low-latency function calling, and any other applications requiring robust language understanding and instruction-following performance.&lt;/p&gt;

&lt;p&gt;This model is an instruction-fine-tuned version of the base model: &lt;a href="https://huggingface.co/mistralai/Mistral-Small-24B-Base-2501" rel="noopener noreferrer"&gt;&lt;strong&gt;Mistral-Small-24B-Base-2501&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model Provider&lt;/strong&gt;: Mistral AI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Size&lt;/strong&gt;: 24B parameters&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context Window&lt;/strong&gt;: 32K tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comparison to Proprietary Models&lt;/strong&gt;: Competitive with larger models like Llama 3.3 70B and Qwen 32B. &lt;a href="https://huggingface.co/mistralai/Mistral-Small-24B-Instruct-2501#benchmark-results" rel="noopener noreferrer"&gt;Explore available benchmarks&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills&lt;/strong&gt;: Strong at summarization, conversational AI, multilingual tasks, and creating highly accurate subject matter experts for specific domains&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Languages Supported&lt;/strong&gt;: English, French, German, Spanish, Italian, Chinese, Japanese, Korean, Portuguese, Dutch, Polish and more&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;License&lt;/strong&gt;: Apache 2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.koyeb.com/deploy/mistral-small-3-instruct" rel="noopener noreferrer"&gt;&lt;strong&gt;Deploy Mistral Small 3 on Koyeb →&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Qwen 2.5 Coder 7B Instruct
&lt;/h2&gt;

&lt;p&gt;Qwen2.5 is a new family of models from Qwen that includes Qwen2.5 LLMs, and specialized models Qwen2.5-Math for mathematics and Qwen2.5 Coder for coding.&lt;br&gt;&lt;br&gt;
The open-source Qwen2.5 models available with an Apache 2.0 license include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Qwen2.5: 0.5B, 1.5B, 7B, 14B, and 32B&lt;/li&gt;
&lt;li&gt;Qwen2.5-Coder: 1.5B, 7B, and 32B&lt;/li&gt;
&lt;li&gt;Qwen2.5-Math: 1.5B and 7B&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are also 3B and 72B variants, not available with an open-source license.&lt;/p&gt;

&lt;p&gt;Among all the advancements in AI, code generation has been significant. Qwen 2.5 7B Coder Instruct stands out for its high performance in code tasks, including generation, reasoning, and code fixing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model Provider&lt;/strong&gt;: Alibaba Cloud&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Size&lt;/strong&gt;: 7.61B&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context Length&lt;/strong&gt;: 131,072 tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comparison to Proprietary Models&lt;/strong&gt;: Performs better than other open source code generation models. Competitive performance with GPT-4o. &lt;a href="https://qwenlm.github.io/blog/qwen2.5-coder-family/" rel="noopener noreferrer"&gt;Explore available benchmarks&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills&lt;/strong&gt;: Code generation, code reasoning and code fixing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Languages Supported&lt;/strong&gt;: Over 10, including Chinese, English, and Spanish&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;License&lt;/strong&gt;: Apache 2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.koyeb.com/deploy/qwen-2-5-coder-7b-instruct" rel="noopener noreferrer"&gt;Deploy Qwen 2.5 Coder 7B Instruct on Koyeb →&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Open Source Models for Reasoning, Code Generation, and More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Best for reasoning → DeepSeek-R1-Distill-Qwen-32B&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Best for conversational AI &amp;amp; summarization → Mistral Small 3&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Best for coding → Qwen 2.5 Coder 7B Instruct&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fine-Tuning and Deploying Open LLMs with Serverless GPUs
&lt;/h2&gt;

&lt;p&gt;Open-source AI models like &lt;a href="https://www.koyeb.com/deploy/deepseek-r1-qwen-32b" rel="noopener noreferrer"&gt;DeepSeek-R1&lt;/a&gt;, &lt;a href="https://www.koyeb.com/deploy/mistral-small-3-instruct" rel="noopener noreferrer"&gt;Mistral Small 3&lt;/a&gt;, and &lt;a href="https://www.koyeb.com/deploy/qwen-2-5-coder-7b-instruct" rel="noopener noreferrer"&gt;Qwen 2.5 Coder&lt;/a&gt; provide powerful alternatives to proprietary options, offering flexibility and cost-effectiveness. &lt;/p&gt;

&lt;p&gt;With Koyeb’s serverless GPUs, you can fine-tune and deploy these models with a single click. Get a dedicated inference endpoint running on high performance GPUs without managing any infrastructure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.koyeb.com/deploy" rel="noopener noreferrer"&gt;Explore the one-click deploy catalog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Deploy &lt;a href="https://www.koyeb.com/deploy/vllm" rel="noopener noreferrer"&gt;vLLM&lt;/a&gt;, &lt;a href="https://www.koyeb.com/deploy/ollama" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt;, and other &lt;a href="https://www.koyeb.com/deploy/category/model" rel="noopener noreferrer"&gt;open-source models&lt;/a&gt; like &lt;a href="https://www.koyeb.com/deploy/flux-dev" rel="noopener noreferrer"&gt;Flux.1 [dev]&lt;/a&gt; and &lt;a href="https://www.koyeb.com/deploy/microsoft-phi-4-14b" rel="noopener noreferrer"&gt;Phi-4&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Read our &lt;a href="https://www.koyeb.com/docs" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://app.koyeb.com/auth/signup" rel="noopener noreferrer"&gt;Sign up for Koyeb&lt;/a&gt; to get started deploying serverless inference endpoints today&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Use FLUX, PyTorch, and Streamlit to Build an AI Image Generation App</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Tue, 03 Dec 2024 10:56:18 +0000</pubDate>
      <link>https://dev.to/koyeb/use-flux-pytorch-and-streamlit-to-build-an-ai-image-generation-app-4911</link>
      <guid>https://dev.to/koyeb/use-flux-pytorch-and-streamlit-to-build-an-ai-image-generation-app-4911</guid>
      <description>&lt;p&gt;The need for AI-generated images has been growing rapidly in recent years. These images are not only used for artistic purposes, but also for practical applications in various industries. For example, in the fashion industry, AI-generated images can be used to create virtual models for showcasing clothing. In the automotive industry, AI-generated images can be used for designing and testing new car models. And the best part? You can now run your own AI image generation machine on Koyeb GPUs.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="noopener noreferrer"&gt;FLUX.1 [dev] model&lt;/a&gt; (by BlackForestLabs) is an advanced AI image generation model that produces outstanding output quality. &lt;a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="noopener noreferrer"&gt;It is a 12 billion parameter rectified flow transformer capable of generating images from text descriptions&lt;/a&gt;. It features competitive prompt following, and is trained using guidance distillation. Additionally, the generated outputs can be utilized for personal, scientific, and non-commercial purposes as outlined in the &lt;a href="https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md" rel="noopener noreferrer"&gt;FLUX.1 [dev] Non-Commercial License&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will learn how to set up a Streamlit application, integrate the FLUX model for real-time image generation, and deploy the application using Docker and Koyeb, ensuring a scalable image generation service.&lt;/p&gt;

&lt;p&gt;You can deploy the FLUX application as built in this tutorial using the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-to-koyeb-button" rel="noopener noreferrer"&gt;Deploy to Koyeb&lt;/a&gt; button below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.koyeb.com/deploy?name=flux-pytorch&amp;amp;type=git&amp;amp;repository=github.com/koyeb/example-flux-1-pytorch&amp;amp;branch=main&amp;amp;builder=dockerfile&amp;amp;instance_type=gpu-nvidia-rtx-4000-sff-ada" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.koyeb.com%2Fstatic%2Fimages%2Fdeploy%2Fbutton.svg" alt="Deploy to Koyeb" width="178" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;To successfully follow this tutorial, you will need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt; installed&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.python.org/downloads/release/python-360/" rel="noopener noreferrer"&gt;Python 3.6+&lt;/a&gt; or later&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://huggingface.co/" rel="noopener noreferrer"&gt;Hugging Face&lt;/a&gt; account&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb&lt;/a&gt; account&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understanding of the components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Text-To-Image Generation and FLUX Model
&lt;/h3&gt;

&lt;p&gt;The process of text-to-image generation involves the model interpreting input text and translating it into visual representations. This process consists of several steps: first, the model encodes the textual input into a latent space, capturing the semantic meaning of the words. Next, it employs a generative process to sample from this latent space, producing images that align with the described concepts. The FLUX model, developed by BlackForestLabs, is a state-of-the-art 12 billion parameter rectified flow transformer trained on extensive datasets containing pairs of images and their corresponding textual descriptions. This training enables the model to learn the intricate relationships between language and visual content. Consequently, users can input detailed prompts, and the FLUX model generates images that reflect those prompts with accuracy (and creativity).&lt;/p&gt;

&lt;h3&gt;
  
  
  Streamlit
&lt;/h3&gt;

&lt;p&gt;Streamlit is an open-source Python library designed to create interactive data applications, often referred to as dashboards. It empowers developers to build and share data apps simply and intuitively, eliminating the need for extensive web development expertise.&lt;/p&gt;

&lt;p&gt;Streamlit apps are created as Python scripts, which are then executed within the Streamlit environment. The library offers a set of functions that can be utilized to add interactive elements to the app such as upload file button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
Set up the environment: Start by setting up your project directory, installing necessary dependencies, and configuring environment variables.&lt;/li&gt;
&lt;li&gt;
Set up Streamlit: Next, install Streamlit and create the initial user interface for your application.&lt;/li&gt;
&lt;li&gt;
Generate AI Images with FLUX Model: Using the FLUX model to generate AI images based on the user prompt and configuration.&lt;/li&gt;
&lt;li&gt;
Dockerize the Streamlit application: Create a Dockerfile to containerize your application for consistent deployment.&lt;/li&gt;
&lt;li&gt;
Deploy to Koyeb: Finally, deploy your application on the Koyeb platform.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Set up the environment
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a new Streamlit project. To keep your Python dependencies organized you should create a virtual environment.&lt;/p&gt;

&lt;p&gt;First, create and navigate into a local directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create and move to the new directory&lt;/span&gt;
&lt;span class="nb"&gt;mkdir &lt;/span&gt;example-koyeb-flux-images
&lt;span class="nb"&gt;cd &lt;/span&gt;example-koyeb-flux-images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterwards, create and activate a new virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a virtual environment&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv

&lt;span class="c"&gt;# Active the virtual environment (Windows)&lt;/span&gt;
.&lt;span class="se"&gt;\v&lt;/span&gt;&lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;cripts&lt;span class="se"&gt;\a&lt;/span&gt;ctivate.bat

&lt;span class="c"&gt;# Active the virtual environment (Linux)&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; ./venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create a &lt;code&gt;requirements.txt&lt;/code&gt; file with the following dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit
watchdog
diffusers
torch
torchvision
einops
huggingface_hub[hf_transfer]
safetensors
sentencepiece
transformers
tokenizers
protobuf
requests
invisible-watermark
accelerate
peft
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In terms of dependencies, we have included Streamlit for building a web app in Python, Hugging Face for real-time local use of the FLUX model, and watchdog to monitor file system events. The &lt;code&gt;accelerate&lt;/code&gt; package is used to streamline the training and inference processes of machine learning models, making it easier to manage distributed training and optimize performance. The &lt;code&gt;invisible-watermark&lt;/code&gt; package is utilized to embed invisible watermarks in generated content, ensuring uniqueness of the outputs produced by the model.&lt;/p&gt;

&lt;p&gt;Now, you can install the dependencies with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's move on to creatng a new Streamlit project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up Streamlit
&lt;/h2&gt;

&lt;p&gt;In this step, you will set up the Streamlit UI that will define the visual layout of the page, and the ability for users to load the FLUX model to start generating images with AI. All the logic for the project will reside in this file, so you can start by creating an &lt;code&gt;app.py&lt;/code&gt; file with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# File: app.py
&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;diffusers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FluxPipeline&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;huggingface_hub&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snapshot_download&lt;/span&gt;

&lt;span class="c1"&gt;# Log in to Hugging Face using the provided token from environment variables
&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Set the title of the Streamlit application
&lt;/span&gt;&lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;AI Image Generation with FLUX.1-dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create a text input field for the user to enter a prompt for image generation
&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your prompt:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Create four columns for user inputs
&lt;/span&gt;&lt;span class="n"&gt;col1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;col2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;col3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;col4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Column 1: Input for image width
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;col1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;num_width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Width:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Column 2: Input for image height
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;col2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;num_height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Height:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Column 3: Input for the number of images to generate
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;col3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;num_images&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Images:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Column 4: Input for the number of inference steps
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;col4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;num_inference_steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Steps:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Button to load the model from Hugging Face
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Load Model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;snapshot_download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;repo_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;black-forest-labs/FLUX.1-dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cache_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./FLUX_1_dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Begins with importing the Streamlit module.&lt;/li&gt;
&lt;li&gt;Logs into Hugging Face using a token stored in environment variables, allowing access to the model repository.&lt;/li&gt;
&lt;li&gt;Defines text values for each step and page's title and description&lt;/li&gt;
&lt;li&gt;Creates four columns to organize user inputs for image dimensions, the number of images, and inference steps. Each column contains a number input field with specified minimum values and default values.&lt;/li&gt;
&lt;li&gt;Creates a &lt;code&gt;Load Model&lt;/code&gt; button to load the FLUX model from Hugging Face. When clicked, it downloads the model snapshot to a specified cache directory using &lt;code&gt;snapshot_download&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this, you have setup a UI that is able to load the FLUX model per user request. Now, let's move on to generating AI images based on the user prompt and settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate AI Images with FLUX Model
&lt;/h2&gt;

&lt;p&gt;In this step, you will invoke FLUX model to generate AI images based on the user prompt. Per the default values set in the input, the model will be generate 3 images for each prompt by user. Make the following additions in the &lt;code&gt;app.py&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# File: app.py
&lt;/span&gt;
&lt;span class="c1"&gt;# Existing code
&lt;/span&gt;
&lt;span class="c1"&gt;# Button to generate images using the FLUX model
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Generate Image&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Load the FLUX model with specified parameters
&lt;/span&gt;    &lt;span class="n"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FluxPipeline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;black-forest-labs/FLUX.1-dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch_dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bfloat16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cache_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./FLUX_1_dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Generate images based on the user input parameters
&lt;/span&gt;    &lt;span class="n"&gt;images&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_inference_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_inference_steps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_images_per_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;num_images&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;

    &lt;span class="c1"&gt;# Create three columns to display the generated images
&lt;/span&gt;    &lt;span class="n"&gt;cols&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamlit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Loop through the generated images and display them in the columns
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;caption&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code addition above does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates a button titled &lt;code&gt;Generate Image&lt;/code&gt;. When clicked, it will instantiate a Flux pipeline for text-to-image generation.&lt;/li&gt;
&lt;li&gt;Invokes the pipeline with the user configured parameters to generate the desired height and width, number of inference steps to be taken, and number of images to be generated.&lt;/li&gt;
&lt;li&gt;Creates three columns to organize the generated images.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, you can run the Streamlit application with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;streamlit run ./app.py &lt;span class="nt"&gt;--server&lt;/span&gt;.port 8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application would now be ready on &lt;a href="http://localhost:8000" rel="noopener noreferrer"&gt;http://localhost:8000&lt;/a&gt;. Test the application by generating AI images by altering the default input values and your own custom prompt.&lt;/p&gt;

&lt;p&gt;Now, let's dockerize the application to ensure consistency between multiple deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dockerize the Streamlit application
&lt;/h2&gt;

&lt;p&gt;Dockerizing deployments helps by creating a consistent and reproducible environment, ensuring that the application runs the same way on any system. It simplifies dependencies management and enhances scalability, making deployments more efficient and reliable. To dockerize, create a &lt;code&gt;Dockerfile&lt;/code&gt; at the root of your project with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;python:3.12&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;runner&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; app.py requirements.txt .&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt &lt;span class="nt"&gt;--root-user-action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ignore
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--pre&lt;/span&gt; torch &lt;span class="nt"&gt;--index-url&lt;/span&gt; https://download.pytorch.org/whl/nightly/cu121 &lt;span class="nt"&gt;--root-user-action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ignore &lt;span class="c"&gt;# [!code ++]&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update 
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; libsm6 libxext6 git git-lfs &lt;span class="c"&gt;# [!code ++]&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /var/lib/apt/lists/&lt;span class="k"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8000 # [!code ++]&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; HF_HUB_ENABLE_HF_TRANSFER=1&lt;/span&gt;

&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; HF_TOKEN # [!code ++]&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["streamlit", "run", "./app.py", "--server.port", "8000"] # [!code ++]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apart from the usual Dockerfile to deploy Python applications, following tweaks/additions have been made in this code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121 --root-user-action=ignore&lt;/code&gt; to install PyTorch with CUDA support for GPU acceleration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RUN apt-get update &amp;amp;&amp;amp; apt-get install -y libsm6 libxext6 git git-lfs &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*&lt;/code&gt; is used to install &lt;code&gt;git-lfs&lt;/code&gt; and &lt;code&gt;git&lt;/code&gt;, and then clean up package lists to reduce image size.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;EXPOSE 8000&lt;/code&gt; is used to specify the port on which the Streamlit application will run.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD ["streamlit", "run", "./app.py", "--server.port", "8000"]&lt;/code&gt; is used to define the command to start the Streamlit app on port 8000.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With all configured, let's move on to deploy the application to Koyeb.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy to Koyeb
&lt;/h2&gt;

&lt;p&gt;Now that you have the application running locally you can also deploy it on Koyeb and make it available on the internet.&lt;/p&gt;

&lt;p&gt;Create a &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;new repository on your GitHub account&lt;/a&gt; so that you can push your code.&lt;/p&gt;

&lt;p&gt;You can download a &lt;a href="https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore" rel="noopener noreferrer"&gt;standard &lt;code&gt;.gitignore&lt;/code&gt; file&lt;/a&gt; for Python from GitHub to exclude certain directories and files from being pushed to the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore &lt;span class="nt"&gt;-o&lt;/span&gt; .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the following commands in your terminal to commit and push your code to the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"first commit"&lt;/span&gt;
git branch &lt;span class="nt"&gt;-M&lt;/span&gt; main
git remote add origin &lt;span class="o"&gt;[&lt;/span&gt;Your GitHub repository URL]
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now have all your local code in your remote repository. Now it is time to deploy the application.&lt;/p&gt;

&lt;p&gt;Within the &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb control panel&lt;/a&gt;, while on the Overview tab, initiate the app creation and deployment process by clicking Create Web Service.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;strong&gt;GitHub&lt;/strong&gt; as the deployment method.&lt;/li&gt;
&lt;li&gt;Select your repository from the menu. Alternatively, deploy from the &lt;a href="https://github.com/koyeb/example-flux-1-pytorch" rel="noopener noreferrer"&gt;example repository associated with this tutorial&lt;/a&gt; by entering &lt;code&gt;https://github.com/koyeb/example-flux-1-pytorch&lt;/code&gt; in the public repository field.&lt;/li&gt;
&lt;li&gt;In the Instance selection, select a GPU Instance.&lt;/li&gt;
&lt;li&gt;Set your HuggingFace access token in the &lt;code&gt;HF_TOKEN&lt;/code&gt; environment variable.&lt;/li&gt;
&lt;li&gt;Finally, click the &lt;strong&gt;Deploy&lt;/strong&gt; button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once the application is deployed, you can visit the Koyeb service URL (ending in &lt;code&gt;.koyeb.app&lt;/code&gt;) to access the Streamlit application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you built an AI Image Generation application using FLUX dev model with Streamlit framework. During the process, you learned how to invoke the Flux pipeline in python to generate AI images on the go, customized with user fed prompt and settings, and use the Streamlit framework to quickly prototype the user interface.&lt;/p&gt;

&lt;p&gt;Given that the application was deployed using the Git deployment option, subsequent code push to the deployed branch will automatically initiate a new build for your application. Changes to your application will become live once the deployment is successful. In the event of a failed deployment, Koyeb retains the last operational production deployment, ensuring the uninterrupted operation of your application.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Use Stable Diffusion and PyTorch to Build an Image Inpainting Service</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Sun, 13 Oct 2024 22:00:00 +0000</pubDate>
      <link>https://dev.to/koyeb/use-stable-diffusion-and-pytorch-to-build-an-image-inpainting-service-2ahm</link>
      <guid>https://dev.to/koyeb/use-stable-diffusion-and-pytorch-to-build-an-image-inpainting-service-2ahm</guid>
      <description>&lt;p&gt;One standout feature of Firefly models from &lt;a href="https://www.adobe.com/products/firefly.html" rel="noopener noreferrer"&gt;Adobe&lt;/a&gt; is &lt;strong&gt;generative fill: simply outline the area you want to modify, provide a prompt, and the model generates the content for you&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Generative fill is possible due to &lt;strong&gt;image inpainting&lt;/strong&gt;, which restores missing or damaged parts of an image by using information from surrounding pixels.&lt;br&gt;
Common use cases range from personal photo editing to professional image restoration in various industries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stable Diffusion is an open source generative AI model&lt;/strong&gt; that creates unique photorealistic images from text and image prompts.&lt;br&gt;
In this tutorial, we will create an image inpaint service using Stable Diffusion. We will deploy the endpoint to Koyeb as a web service, enabling users to upload images and receive modified versions based on their prompts.&lt;/p&gt;

&lt;p&gt;You can consult the &lt;a href="https://github.com/koyeb/example-stable-diffusion-inpainting" rel="noopener noreferrer"&gt;repository&lt;/a&gt; for this guide to follow along on your own. You can deploy Stable Diffusion by clicking the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-to-koyeb-button" rel="noopener noreferrer"&gt;Deploy to Koyeb&lt;/a&gt; button below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.koyeb.com/deploy?name=stable-diffusion&amp;amp;type=git&amp;amp;repository=koyeb%2Fexample-stable-diffusion-inpainting&amp;amp;branch=main&amp;amp;builder=dockerfile&amp;amp;instance_type=gpu-nvidia-rtx-4000-sff-ada&amp;amp;ports=8000%3Bhttp%3B%2F" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.koyeb.com%2Fstatic%2Fimages%2Fdeploy%2Fbutton.svg" alt="Deploy to Koyeb" width="178" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to set the grace period to 300 seconds.&lt;/p&gt;

&lt;p&gt;By the end, you will have built and deployed your own image inpainting service that will look like this:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ACpNCwpYMp4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Here are the following requirements for the project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.10 or later&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pytorch.org/get-started/locally/" rel="noopener noreferrer"&gt;Pytorch 2.4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb account&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;Here are the steps we will follow to build the image inpainting service:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Set up the environment&lt;/strong&gt;: Begin by setting up your project directory and installing the necessary dependencies, including Python and Hugging Face's Diffusers library. Configure the environment variables required for the application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement Inpaint&lt;/strong&gt;: Use a pre-trained model, like Stable Diffusion, to handle the inpainting process. This function will take the user’s image and mask to generate the output.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set up the Web Service:&lt;/strong&gt; Use Gradio to create the user interface for the inpainting service. The web interface will allow users to upload images and masks for the inpainting process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerize the Application:&lt;/strong&gt; Create a Dockerfile to containerize the application. This step ensures the service is portable and can be deployed consistently across environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy to Koyeb GPU:&lt;/strong&gt; Deploy your Dockerized inpainting service on Koyeb. This final step brings your service online and makes it accessible to users.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Overview of implementation of image inpaint service
&lt;/h2&gt;

&lt;p&gt;In this section, we’ll guide you through implementing the image inpainting service and deploying it to Koyeb. Here is an overview of the approach to this project and a diagram of the application’s architecture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ynsztog1s2s9ln068au.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ynsztog1s2s9ln068au.png" alt="Image Inpainting Service Architecture" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up the project
&lt;/h2&gt;

&lt;p&gt;First, let's create a project directory named &lt;code&gt;inpaint-koyeb&lt;/code&gt;. This will be the base folder where all the code, models, and configurations for the image inpainting service will reside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir inpaint-koyeb
cd inpaint-koyeb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create and activate a virtual environment
&lt;/h3&gt;

&lt;p&gt;It's best to use a virtual environment to isolate the project dependencies and avoid conflicts with other projects. In this case, we’ll use Python 3.10&lt;/p&gt;

&lt;p&gt;Ensure Python &amp;gt;=3.10 is installed. You can check your Python version by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create and activate the virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, activate the virtual environment. On &lt;strong&gt;macOS/Linux&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On &lt;strong&gt;Windows&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.\venv\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once activated, your terminal will be prefixed with &lt;code&gt;(venv)&lt;/code&gt;, indicating the active environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize Git repository
&lt;/h3&gt;

&lt;p&gt;To track changes and manage your code efficiently, it’s a good idea to initialize your project directory as a Git repository. Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a hidden &lt;code&gt;.git&lt;/code&gt; folder in your project directory, allowing you to commit changes and work with version control.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install requirements
&lt;/h3&gt;

&lt;p&gt;Create &lt;code&gt;requirements.txt&lt;/code&gt;. The &lt;code&gt;requirements.txt&lt;/code&gt; file lists the dependencies your project will need. Create the file and add the following dependencies to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;torch==2.4
diffusers==0.30.2
gradio==4.43.0
transformers==4.44.2
gradio_client==1.3.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we will build a Docker container later, we must add the versions to ensure consistency across environments and prevent breaking changes.&lt;/p&gt;

&lt;p&gt;Finally, install the dependencies listed in &lt;code&gt;requirements.txt&lt;/code&gt; using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will ensure all necessary libraries for the inpainting service are installed within your virtual environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a &lt;code&gt;.gitignore&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;You should exclude specific files and directories, such as your virtual environment, from version control. Create a &lt;code&gt;.gitignore&lt;/code&gt; file and add the venv folder to it to ensure Git does not track it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .gitignore
venv/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will prevent your virtual environment from being uploaded to the repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implement inpaint service
&lt;/h2&gt;

&lt;p&gt;Huggingface has made it much easier for developers to work with the Stable Diffusion model by creating &lt;code&gt;diffusers&lt;/code&gt; library. It allows you to quickly implement models for tasks like image generation, inpainting, and more, leveraging state-of-the-art architectures like Stable Diffusion.&lt;/p&gt;

&lt;p&gt;In this example, we use the &lt;code&gt;AutoPipelineForInpainting&lt;/code&gt; class from the diffusers library to create an inpainting model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Import the necessary libraries
&lt;/h3&gt;

&lt;p&gt;In an &lt;code&gt;app.py&lt;/code&gt; file, import the necessary libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import torch
from diffusers import AutoPipelineForInpainting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;torch&lt;/code&gt;: This is the PyTorch library for tensors and GPU computations.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AutoPipelineForInpainting&lt;/code&gt;: A pipeline specifically designed for the task of image inpainting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Load the pre-trained inpainting model
&lt;/h3&gt;

&lt;p&gt;Next, load the pre-trained inpainting model in the &lt;code&gt;app.py&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline = AutoPipelineForInpainting.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")

pipeline.enable_model_cpu_offload()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model:&lt;/strong&gt; The model being used is &lt;code&gt;stable-diffusion-xl-base-1.0&lt;/code&gt;, which supports inpainting. This pre-trained model means you don’t need to train it from scratch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inference Speed:&lt;/strong&gt; To optimize performance, we implemented the following:

&lt;ul&gt;
&lt;li&gt;torch_dtype=torch.float16 ensures the model uses half-precision (FP16) for computations, which speeds up inference on modern GPUs.&lt;/li&gt;
&lt;li&gt;to("cuda") moves the model to the GPU for faster processing. This is important for large models like stable-diffusion-xl.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Memory&lt;/strong&gt;: To save memory, enable_model_cpu_offload() ensures the model offloads some parts of its computation to the CPU when GPU memory is full, allowing you to use larger models even on limited GPU resources.&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Defining the inpainting function
&lt;/h3&gt;

&lt;p&gt;Now that the model is ready, we define the function in &lt;code&gt;app.py&lt;/code&gt; that will handle the inpainting process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def image_inpaint(image_input, mask_input, prompt_input):
    image = pipeline(prompt=prompt_input, image=image_input, mask_image=mask_input).images[0]
    return image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function &lt;code&gt;image_inpaint&lt;/code&gt; is designed to take three inputs: the original image, a mask indicating the area to be filled in, and a text prompt that guides the model on how to fill in that masked region.&lt;/p&gt;

&lt;p&gt;Inside the function, the &lt;code&gt;pipeline&lt;/code&gt; object is used to perform the inpainting. It processes the image and mask according to the provided prompt, and then generates an output image where the masked part is filled in based on the prompt's instructions. Once the new image is created, the function returns it.&lt;/p&gt;

&lt;p&gt;With this setup, we now have the core logic for modifying images by filling in missing parts. The next steps will cover how to create a user interface to make this functionality accessible to end users.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up the web service
&lt;/h3&gt;

&lt;p&gt;To set up the web service, we will use Gradio. Gradio is an easy-to-use library that allows developers to create web interfaces for machine learning models and other Python functions. We will create a function that includes two image input sections, one text input section, and an output image section.&lt;/p&gt;

&lt;p&gt;In your `app.py' file, add the following code to set up the Gradio interface:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`app.py&lt;br&gt;
import gradio as gr&lt;/p&gt;

&lt;p&gt;def image_inpaint(image_input, mask_input, prompt_input):&lt;br&gt;
    image = pipeline(prompt=prompt_input, image=image_input, mask_image=mask_input).images[0]&lt;br&gt;
    return image&lt;/p&gt;

&lt;p&gt;def gradio_interface():&lt;br&gt;
    with gr.Blocks() as demo:&lt;br&gt;
        gr.Markdown("## Image Inpainting Service")&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    with gr.Row():
        with gr.Column():
            image_input = gr.Image(type="pil", label="Upload Image")
            mask_input = gr.Image(type="pil", label="Upload Mask")
            prompt_input = gr.Textbox(label="Enter Prompt", placeholder="Describe what you want to inpaint")
            submit_btn = gr.Button("Inpaint")

        with gr.Column():
            result_output = gr.Image(type="pil", label="Inpainted Image")

    # Connect the button click event with the image inpainting
    submit_btn.click(image_inpaint, inputs=[image_input, mask_input, prompt_input], outputs=result_output)

demo.launch()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Run the Gradio interface
&lt;/h1&gt;

&lt;p&gt;if &lt;strong&gt;name&lt;/strong&gt; == "&lt;strong&gt;main&lt;/strong&gt;":&lt;br&gt;
    gradio_interface()&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here’s an explanation of the code above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Import Gradio&lt;/strong&gt;: We begin by importing the gradio library to set up the interface for the image inpainting service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creating the Interface Function (gradio_interface)&lt;/strong&gt;: The function gradio_interface() is where we define the layout and logic of the web service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gradio Blocks&lt;/strong&gt;: gr.Blocks() define the overall structure of the interface. Think of it as the container for the entire UI.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Markdown Header&lt;/strong&gt;: gr.Markdown() adds a header describing the service: "Image Inpainting Service."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Creating Input Fields&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Image Input&lt;/strong&gt;: gr.Image(type="pil", label="Upload Image") allows users to upload a base image for inpainting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mask Input&lt;/strong&gt;: gr.Image(type="pil", label="Upload Mask") lets users upload a mask, which defines the areas to be inpainted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt Input&lt;/strong&gt;: gr.Textbox() enables users to input a description of the changes or details to be inpainted into the image.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Submit Button&lt;/strong&gt;: gr.Button("Inpaint") adds a button to trigger the inpainting process when clicked.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Output Image&lt;/strong&gt;: gr.Image(type="pil", label="Inpainted Image") is where the result of the inpainting operation will be displayed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Button Click Action&lt;/strong&gt;: submit_btn.click() connects the button to the image_inpaint function, taking the inputs (image, mask, and prompt) and displaying the resulting inpainted image in the output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Launch the Interface&lt;/strong&gt;: demo.launch() starts the Gradio interface, making the web service accessible.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To run the application locally, simply execute the file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
python app.py&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Dockerize the application
&lt;/h2&gt;

&lt;p&gt;Dockerization is an essential step for packaging and deploying modern applications. Creating a Docker container ensures your application runs consistently in any environment. Deploying the application to Koyeb during the build step further streamlines this process.  Now, let’s go through the Dockerfile, which will allow you to containerize your Image Inpainting Service.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`Dockerfile&lt;br&gt;
FROM python:3.10&lt;br&gt;
WORKDIR /app&lt;/p&gt;
&lt;h1&gt;
  
  
  Copy the requirements file
&lt;/h1&gt;

&lt;p&gt;COPY requirements.txt app.py&lt;/p&gt;
&lt;h1&gt;
  
  
  Install the dependencies
&lt;/h1&gt;

&lt;p&gt;RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install -r requirements.txt&lt;br&gt;
ENV GRADIO_SERVER_NAME="0.0.0.0”&lt;br&gt;
ENV GRADIO_SERVER_PORT=${GRADIO_SERVER_PORT:-8000}&lt;br&gt;
CMD ["python", "app.py"]&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Apart from the usual dockerfile commands, these are some new additions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CMD ["python", "app.py"]: This command tells Docker to execute the &lt;code&gt;app.py&lt;/code&gt; file (which starts the Gradio interface) when the container is run. The CMD instruction sets the container's default command.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Deploy to Koyeb GPU
&lt;/h2&gt;

&lt;p&gt;With the application now running locally, you can quickly deploy it to Koyeb and make it accessible online.&lt;/p&gt;
&lt;h3&gt;
  
  
  Push the code to GitHub
&lt;/h3&gt;

&lt;p&gt;Since we have already set up a GitHub repository, simply commit your changes and push the code to GitHub.&lt;/p&gt;

&lt;p&gt;To do this, run the following commands in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git add app.py Dockerfile requirements.txt .gitignore&lt;br&gt;
git commit -m "first commit"&lt;br&gt;
git branch -M main&lt;br&gt;
git remote add origin [Your GitHub repository URL]&lt;br&gt;
git push -u origin main&lt;/code&gt;&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Deploy the application on Koyeb
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;In the &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb control panel&lt;/a&gt;, go to the &lt;strong&gt;Overview&lt;/strong&gt; tab. Click &lt;strong&gt;Create Service&lt;/strong&gt; and select &lt;strong&gt;Create Web Service&lt;/strong&gt; to begin the app creation and deployment&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;GitHub&lt;/strong&gt; as the deployment source&lt;/li&gt;
&lt;li&gt;From the menu, select your repository&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Instance Selection&lt;/strong&gt;, choose a &lt;strong&gt;GPU Instance&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Builder&lt;/strong&gt; section, select &lt;strong&gt;Dockerfile&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Adjust the &lt;strong&gt;grace period&lt;/strong&gt; for TCP health checks to &lt;strong&gt;300 seconds&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Deploy&lt;/strong&gt; button to finalize the process&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After deploying the application, you can track the deployment progress through the provided build and runtime logs.&lt;br&gt;
Once the deployment is complete and health checks pass, your Gradio application will be up and running.&lt;/p&gt;

&lt;p&gt;Click the provided public URL to access your live application.&lt;/p&gt;

&lt;p&gt;Here is an example of the deployed application:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ACpNCwpYMp4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this guide, you built an image inpainting service using Stable Diffusion and Gradio and deployed it on Koyeb. You learned how to set up a Python environment, implement the inpainting function with Stable Diffusion, and create a user-friendly web interface with Gradio. After containerizing the application with Docker, &lt;strong&gt;Koyeb&lt;/strong&gt; enabled scalable and efficient deployment.&lt;/p&gt;

&lt;p&gt;The models for image inpaint are computationally expensive, so we want something like Koyeb to handle the deployment and scaling.&lt;/p&gt;

&lt;p&gt;With automatic builds and deployments managed through Git, Koyeb ensures your service remains operational, even in the event of a failed deployment, by reverting to the last stable version.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fine-Tune MistralAI on Koyeb GPUs</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Fri, 11 Oct 2024 09:40:33 +0000</pubDate>
      <link>https://dev.to/koyeb/fine-tune-mistralai-on-koyeb-gpus-1dk7</link>
      <guid>https://dev.to/koyeb/fine-tune-mistralai-on-koyeb-gpus-1dk7</guid>
      <description>&lt;p&gt;&lt;a href="https://mistral.ai/" rel="noopener noreferrer"&gt;MistralAI&lt;/a&gt; is an advanced language model designed for tasks like text generation, sentiment analysis, translation, summarization, and more.&lt;/p&gt;

&lt;p&gt;By default, MistralAI is trained on general language data. It &lt;strong&gt;performs even better when fine-tuned to specific domains&lt;/strong&gt; like finance, law, or medicine.&lt;/p&gt;

&lt;p&gt;Fine-tuning retrains the model on domain-specific data, enabling it to understand the specific terms, patterns, and concepts used in that field. For instance, in finance, supplementary information for retraining a model includes financial reports, stock market data, or legal documents.&lt;/p&gt;

&lt;p&gt;With fine-tuning, MistralAI becomes more accurate at understanding complex financial terms, market trends, and regulatory requirements. This enhancement makes the model more adept at predicting financial outcomes, generating insightful analysis, and supporting decision-making in areas like trading or risk management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;To successfully complete this tutorial, you will need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Account&lt;/strong&gt;: Needed for managing the fine-tuning code. Sign up at &lt;a href="https://github.com/signup" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; if you don’t have one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Koyeb Account&lt;/strong&gt;: Required for accessing Koyeb’s cloud infrastructure, including GPU resources. Create an account at &lt;a href="https://app.koyeb.com/signup" rel="noopener noreferrer"&gt;Koyeb&lt;/a&gt; if you don’t have one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Koyeb GPU Access&lt;/strong&gt;: Make sure your Koyeb account has access to GPU instances for fine-tuning and to deploy GPU-enabled instances through the Koyeb dashboard.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic Knowledge&lt;/strong&gt;: Familiarity with &lt;strong&gt;Python&lt;/strong&gt; (running scripts, setting up virtual environments). Basic understanding of &lt;strong&gt;Docker&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="http://NewsAPI.org" rel="noopener noreferrer"&gt;NewsAPI.org&lt;/a&gt; API Key&lt;/strong&gt;: Access to a NewsAPI API Key. This is needed to retrieve content for the financial data set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MistralAI&lt;/strong&gt;: Access to a Mistral AI API key. This will be needed to prepare the financial data set with AI.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;This tutorial is divided into the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cloning and Exploring the GitHub Repository&lt;/li&gt;
&lt;li&gt;Understanding the Fine-Tuning Workflow&lt;/li&gt;
&lt;li&gt;Preparing the Financial Dataset&lt;/li&gt;
&lt;li&gt;Preparing Training and Evaluation Datasets&lt;/li&gt;
&lt;li&gt;Configure the Training Script&lt;/li&gt;
&lt;li&gt;Deploying to Koyeb GPU&lt;/li&gt;
&lt;li&gt;Running the Fine-Tuning process&lt;/li&gt;
&lt;li&gt;Evaluating the Fine-Tuned Model&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Cloning and Exploring the GitHub Repository
&lt;/h2&gt;

&lt;p&gt;To start fine-tuning MistralAI, the first step is to clone the official GitHub repository, which has all the necessary scripts and settings for training.&lt;/p&gt;

&lt;p&gt;Clone the repository with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/mistralai/mistral-finetune.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Exploring the Key Files and Folders&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After cloning the repository, take a moment to look around its structure. Understanding these files will help you customize and run the fine-tuning process effectively.&lt;/p&gt;

&lt;p&gt;The file &lt;code&gt;example/7B.yaml&lt;/code&gt; is particularly important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This configuration file defines the model architecture and settings such as batch size, and number of training cycles.&lt;/li&gt;
&lt;li&gt;It is crucial for setting up the training environment and should be reviewed and adjusted based on your specific needs, especially if you are fine-tuning for a specialized area like finance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other important files are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;validate_data.py&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;This script is used to validate the dataset before training. It ensures that the data is complete, correctly formatted, and free of errors that could impact the training process.&lt;/li&gt;
&lt;li&gt;Running this script helps identify and resolve any issues with the dataset, ensuring smooth training.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;reformat_data.py&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;This script is used to reformat the dataset if necessary. It ensures that the data is in the correct format required by the model for training.&lt;/li&gt;
&lt;li&gt;This step is important to maintain consistency and accuracy in the dataset, which is essential for effective fine-tuning.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Understanding and properly configuring the &lt;code&gt;7B.yaml&lt;/code&gt; file is essential for effective fine-tuning of the MistralAI model. We will see later on the necessary settings for our fine-tune process for the Mistral 7B model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Fine-Tuning Workflow
&lt;/h2&gt;

&lt;p&gt;Fine-tuning a language model like MistralAI involves a systematic workflow to ensure the model is properly adapted to a specific domain or task.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Prepare the Dataset
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gather the Data (Content)&lt;/strong&gt;: Collect domain-specific data relevant to the task you are fine-tuning the model for. This could include financial reports, market data, customer reviews, or any other textual data that reflects the language and concepts you want the model to learn. Ensure the data is comprehensive and diverse enough to cover different scenarios and contexts within the domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Proper Formatting&lt;/strong&gt;: Format the collected data into a structure that the model can process. This typically involves organizing the text into a sequence of interactions (e.g., question-answer pairs) or continuous text segments. Ensure consistency in formatting across all data samples to avoid confusion during training. This might include tokenization, lowercasing, and handling special characters or symbols.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Prepare Training and Evaluation Datasets
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Splitting the Original Dataset&lt;/strong&gt;: Divide the prepared dataset into two parts: the training set and the evaluation (or validation) set. The training set is used to teach the model, while the evaluation set is used to monitor performance and avoid overfitting. A common split ratio is 80/20 or 90/10, but this can be adjusted based on the size of your dataset and the specific requirements of your task. Ensure that both sets are representative of the full dataset, covering all relevant aspects of the domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balancing the Datasets&lt;/strong&gt;: Check for balance in the training and evaluation datasets. For example, if the data includes different categories (e.g., different financial instruments or market conditions), ensure that each category is well-represented in both the training and evaluation sets. This step is crucial to avoid bias in the model's predictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Configure the Training Script
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set Batch Size&lt;/strong&gt;: Batch size determines how many samples are processed before the model's weights are updated. Larger batch sizes can make training faster but require more memory, while smaller batches can lead to better generalization but might make training slower. Experiment with different batch sizes to find the optimal setting for your hardware and data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Define Training Steps&lt;/strong&gt;: Specify the number of training steps or epochs. This determines how many times the model will iterate over the entire training dataset. Monitor the model's performance during training to decide whether more or fewer steps are needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Verify the Dataset (Training + Evaluation)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Check Data Integrity&lt;/strong&gt;: Verify that the data in both training and evaluation sets is complete and correctly formatted. Look for missing values, corrupted files, or inconsistencies that could impact training. Run preliminary checks to ensure that the data loads correctly into the training pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate Data Distribution&lt;/strong&gt;: Confirm that the distribution of data in the training and evaluation sets aligns with the expected real-world distribution. This is especially important in domains like finance, where different market conditions need to be represented.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Train the Model
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Initiate Training&lt;/strong&gt;: Begin the fine-tuning process by running the configured training script.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor Performance&lt;/strong&gt;: Regularly evaluate the model's performance on the validation set during training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save Checkpoints&lt;/strong&gt;: Save model checkpoints at regular intervals to preserve the model’s state at different points in training.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Preparing the Financial Dataset
&lt;/h2&gt;

&lt;p&gt;To prepare the dataset for training, it needs to be structured in a specific format that the MistralAI fine-tune process can understand. The format typically follows a structure similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User interaction n°1 contained in document n°1"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bot interaction n°1 contained in document n°1"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User interaction n°2 contained in document n°1"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bot interaction n°2 contained in document n°1"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User interaction n°1 contained in document n°2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bot interaction n°1 contained in document n°2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User interaction n°2 contained in document n°2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bot interaction n°2 contained in document n°2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"weight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;don't&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;train&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;on&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;n°&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User interaction n°3 contained in document n°2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bot interaction n°3 contained in document n°2"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each JSON object contains a list of messages, with each message having a &lt;code&gt;role&lt;/code&gt; field to indicate the speaker (either "user" or "assistant") and a &lt;code&gt;content&lt;/code&gt; field to store the text of the interaction.&lt;/p&gt;

&lt;p&gt;This file type is called a JSONL (JSON lines files), because it contains several JSON objects separated by a newline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing Training and Evaluation Datasets
&lt;/h2&gt;

&lt;p&gt;To gather the data (content), we will use an API from &lt;a href="http://newsapi.org/" rel="noopener noreferrer"&gt;NewsAPI.org&lt;/a&gt; to get financial news content. You will need to register to get a free API key from &lt;a href="http://newsapi.org/" rel="noopener noreferrer"&gt;NewsAPI.org&lt;/a&gt; if you don’t have one.&lt;/p&gt;

&lt;p&gt;You will also need access to an API key from MistralAI. You can register for one &lt;a href="https://auth.mistral.ai/ui/registration" rel="noopener noreferrer"&gt;here&lt;/a&gt; if you don’t have one.&lt;/p&gt;

&lt;p&gt;Then you can write the &lt;code&gt;dataset_processing.py&lt;/code&gt; script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;decouple&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;mistralai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Mistral&lt;/span&gt;

&lt;span class="n"&gt;NEWS_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NEWS_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;MISTRAL_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MISTRAL_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Function to fetch financial news data related to a specific topic
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_financial_news&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;financial market&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;page_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://newsapi.org/v2/everything?q=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;pageSize=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;page_size&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;apiKey=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;news_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;articles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;news_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;articles&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;

&lt;span class="c1"&gt;# Function to process and save the data to a CSV file
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;save_news_to_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Create a DataFrame from the articles
&lt;/span&gt;    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;source&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;author&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;author&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;description&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;publishedAt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;publishedAt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Save the DataFrame to a CSV file
&lt;/span&gt;    &lt;span class="n"&gt;output_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;_news.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Data saved to &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;output_file&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_csv_to_jsonl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Read the CSV file
&lt;/span&gt;        &lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Process each row and append each content to a list
&lt;/span&gt;        &lt;span class="n"&gt;json_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterrows&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Mistral&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;MISTRAL_API_KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mistral-small-latest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;You will receive news article. Analyze it and generated user and assistant
                                interactions in a chat like format. The output should be a JSON with the
                                following format:
                               &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{
                                  &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: [
                                    {
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;User interaction n°1 contained in document n°1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
                                    },
                                    {
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assistant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bot interaction n°1 contained in document n°1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
                                    },
                                    {
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;User interaction n°2 contained in document n°1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
                                    },
                                    {
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assistant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
                                      &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bot interaction n°2 contained in document n°1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
                                    }
                                  ]
                                }&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;
                               Return only the JSON and nothing else, and no JSON tags.
                               &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
                    &lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Here is the news content: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="n"&gt;result_txt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
            &lt;span class="n"&gt;result_txt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result_txt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;```

json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;

```&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;json_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result_txt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;json_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Save the list to a JSONL file
&lt;/span&gt;        &lt;span class="n"&gt;output_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;json_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;separate_jsonl_train_eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Read the JSONL file and separate into training and evaluation sets using pandas
&lt;/span&gt;        &lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;df_train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frac&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;df_eval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Save the training and evaluation sets to JSONL files keeping the same file name
&lt;/span&gt;        &lt;span class="n"&gt;train_output_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_train.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;eval_output_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_eval.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train_output_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;orient&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;records&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;df_eval&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;eval_output_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;orient&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;records&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;

&lt;span class="c1"&gt;# Main function to run the data processing pipeline
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Specify the topic you want to search for
&lt;/span&gt;    &lt;span class="n"&gt;topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;financial market&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="c1"&gt;# Fetch data
&lt;/span&gt;    &lt;span class="n"&gt;articles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetch_financial_news&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NEWS_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Save the data to a CSV file
&lt;/span&gt;    &lt;span class="nf"&gt;save_news_to_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Process the CSV file to generate a JSONL file
&lt;/span&gt;    &lt;span class="nf"&gt;process_csv_to_jsonl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;financial_market_news.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Separate the JSONL file into training and evaluation sets
&lt;/span&gt;    &lt;span class="nf"&gt;separate_jsonl_train_eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;financial_market_news.jsonl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Entry point of the script
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="sb"&gt;``&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;Python&lt;/span&gt; &lt;span class="n"&gt;script&lt;/span&gt; &lt;span class="n"&gt;automates&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;collecting&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;formatting&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;MistralAI&lt;/span&gt; &lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;preparing&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;evaluation&lt;/span&gt; &lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`fetch_financial_news`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fetches&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;articles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;NewsAPI&lt;/span&gt; &lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;specified&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`save_news_to_csv`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;saves&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;fetched&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;CSV&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`process_csv_to_jsonl`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;converts&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;CSV&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;JSONL&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;generating&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="n"&gt;interactions&lt;/span&gt; &lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;MistralAI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`separate_jsonl_train_eval`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;splits&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;JSONL&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;evaluation&lt;/span&gt; &lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;orchestrates&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;entire&lt;/span&gt; &lt;span class="n"&gt;workflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Fetching&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Saving&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;CSV&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Converting&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;CSV&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;JSONL&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Splitting&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;JSONL&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;evaluation&lt;/span&gt; &lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;script&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;which&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="nf"&gt;model &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;script&lt;/span&gt; &lt;span class="n"&gt;later&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`financial_market_news_train.jsonl`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Contains&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`financial_market_news_eval.jsonl`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Contains&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;evaluation&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;## Configure the Training Script
&lt;/span&gt;
&lt;span class="n"&gt;Before&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Koyeb&lt;/span&gt; &lt;span class="n"&gt;CPU&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="n"&gt;preparing&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;which&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;YAML&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;necessary&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;mentioned&lt;/span&gt; &lt;span class="n"&gt;earlier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;So&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;go&lt;/span&gt; &lt;span class="n"&gt;ahead&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="sb"&gt;`7B.yaml`&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="sb"&gt;``&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;yaml&lt;/span&gt;
&lt;span class="c1"&gt;# data
&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;instruct_data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/mistral-finetune/financial_market_news_train.jsonl&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;# Fill
&lt;/span&gt;  &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;''&lt;/span&gt; &lt;span class="c1"&gt;# Optionally fill with pretraining data
&lt;/span&gt;  &lt;span class="n"&gt;eval_instruct_data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/mistral-finetune/financial_market_news_eval.jsonl&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;# Optionally fill
&lt;/span&gt;
&lt;span class="c1"&gt;# model
&lt;/span&gt;&lt;span class="n"&gt;model_id_or_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/mistral-finetune/mistral_models/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;# Change to downloaded path
&lt;/span&gt;&lt;span class="n"&gt;lora&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;

&lt;span class="c1"&gt;# optim
&lt;/span&gt;&lt;span class="n"&gt;seq_len&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;32768&lt;/span&gt;
&lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;max_steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;span class="n"&gt;optim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;6.e-5&lt;/span&gt;
  &lt;span class="n"&gt;weight_decay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;
  &lt;span class="n"&gt;pct_start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;

&lt;span class="c1"&gt;# other
&lt;/span&gt;&lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;log_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;eval_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="n"&gt;no_eval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="n"&gt;ckpt_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;

&lt;span class="n"&gt;save_adapters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt; &lt;span class="c1"&gt;# save only trained LoRA adapters. Set to `False` to merge LoRA adapter into the base model and save full fine-tuned model
&lt;/span&gt;
&lt;span class="n"&gt;run_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/mistral-finetune/chat_test&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;# Fill
&lt;/span&gt;&lt;span class="sb"&gt;``&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;important&lt;/span&gt; &lt;span class="n"&gt;information&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`instruct_data`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;generated&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`dataset_processing.py`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`eval_instruct_data`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;evaluation&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;generated&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`dataset_processing.py`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;script&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`model_id_or_path`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;identifier&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;download&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;later&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`batch_size`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;adjust&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;needed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;but&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="n"&gt;well&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`max_steps`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="n"&gt;provides&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;good&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="n"&gt;between&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="nb"&gt;reduce&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;faster&lt;/span&gt; &lt;span class="n"&gt;processing&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;cost&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;less&lt;/span&gt; &lt;span class="n"&gt;accuracy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="sb"&gt;`run_dir`&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;directory&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;trained&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;saved&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;After&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;download&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="n"&gt;script&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;These&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;prepared&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="n"&gt;later&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;## Deploying to Koyeb GPU
&lt;/span&gt;
&lt;span class="n"&gt;To&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;Koyeb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Dockerfile&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;sets&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;environment&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;Koyeb&lt;/span&gt; &lt;span class="n"&gt;via&lt;/span&gt; &lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;built&lt;/span&gt; &lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Dockerfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;### Create a Dockerfile
&lt;/span&gt;
&lt;span class="n"&gt;We&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ll start by preparing a Dockerfile to ensure we have all the necessary dependencies installed, especially for GPU support. Create a `Dockerfile` with the following contents:

```docker
# Use the official Python base image
FROM python:3.11

# Clone the repository
RUN git clone https://github.com/mistralai/mistral-finetune.git

# Set the working directory
WORKDIR /mistral-finetune

# Update pip, install torch and other dependencies
RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install -r requirements.txt

# Copy the 7B.yaml file
COPY 7B.yaml /mistral-finetune/example/7B.yaml

# Script to prepare the training data
COPY dataset_processing.py /mistral-finetune/dataset_processing.py
```

This Dockerfile is designed to set up an environment for fine-tuning the MistralAI language model. It automates the process of cloning the necessary repository, installing dependencies, and copying both the training configuration and the training dataset script.

### Create the repository

The final step is to create a new repository on GitHub to store the project files.

Once you&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="n"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;terminal&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;push&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="sb"&gt;``&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;# MistralFineTuning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;README&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;md&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;First Commit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;branch&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Your&lt;/span&gt; &lt;span class="n"&gt;GitHub&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;push&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="sb"&gt;``&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}{&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;

&lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Dockerfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;### Deploy to Koyeb
&lt;/span&gt;
&lt;span class="n"&gt;In&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Koyeb&lt;/span&gt; &lt;span class="n"&gt;control&lt;/span&gt; &lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;koyeb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Overview&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;tab&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;initiate&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="n"&gt;creation&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;clicking&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;select&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Worker&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;On&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;App&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="mf"&gt;1.&lt;/span&gt; &lt;span class="n"&gt;Select&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;GitHub&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="mf"&gt;2.&lt;/span&gt; &lt;span class="n"&gt;Choose&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="n"&gt;resides&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;For&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="sb"&gt;`MistralFineTuning`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="mf"&gt;3.&lt;/span&gt; &lt;span class="n"&gt;Select&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;GPU&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;wish&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="sb"&gt;`A100`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;might&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="n"&gt;GPUs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;but&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;performance&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;training&lt;/span&gt; &lt;span class="n"&gt;accuracy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;recommended&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="mf"&gt;4.&lt;/span&gt; &lt;span class="n"&gt;In&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Builder&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;section&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choose&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Dockerfile&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="mf"&gt;5.&lt;/span&gt; &lt;span class="n"&gt;In&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Service&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;section&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choose&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;appropriate&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="mf"&gt;6.&lt;/span&gt; &lt;span class="n"&gt;Finally&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;click&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;Deploy&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;## Running the Fine-Tuning process
&lt;/span&gt;
&lt;span class="n"&gt;Once&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="n"&gt;preparing&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;Dockerfile&lt;/span&gt; &lt;span class="n"&gt;deployment&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt; &lt;span class="n"&gt;needed&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;but&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;didn&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;download&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;so&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Since&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;interaction&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ll use the Koyeb CLI to access the remote machine through the terminal.

First, make sure you have the Koyeb CLI installed. You can find the installation instructions [**here**](https://www.koyeb.com/docs/build-and-deploy/cli/installation). Then, generate an API Token, which you can do [**here**](https://app.koyeb.com/user/settings/api/).

Now you are ready to log in with the Koyeb CLI:

```bash
koyeb login
```

First, input your API token key when asked for it.

To see a list of running instances, use the following command:

```bash
koyeb instances list
```

Note the instance ID you want to connect to. Then, create a remote terminal session to the remote machine:

```bash
koyeb instances exec &amp;lt;instance_id&amp;gt; /bin/bash
```

You now have an active remote session to the remote machine. All commands executed from now on will be on the remote machine.

As mentioned, the first step is to download the model to train, in this case the Mistral 7B Instruct:

```bash
mkdir mistral_models
wget https://models.mistralcdn.com/mistral-7b-v0-3/mistral-7B-Instruct-v0.3.tar &amp;amp;&amp;amp; tar -xf mistral-7B-Instruct-v0.3.tar -C mistral_models
```

It might take a couple of minutes for the model to be downloaded and extracted.

Next, to ensure proper compatibility, make sure that the Numpy package installed is at version 1.26.4:

```bash
pip install numpy==1.26.4
```

Now you can install the necessary libraries for executing the dataset script:

```bash
pip install requests pandas mistralai python-decouple
```

You can then copy the necessary information for the **`.env`** file:

```bash
echo &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NEWS_API_KEY=&amp;lt;YOUR_NEWS_API_KEY&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &amp;gt; .env
echo &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MISTRAL_API_KEY=&amp;lt;YOUR_MISTRAL_API_KEY&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &amp;gt;&amp;gt; .env

```

Make sure to replace the values with your own API keys.

And then you can execute the **`dataset_processing.py`** script:

```bash
python3 dataset_processing.py
```

It might take a couple of minutes to prepare the dataset. After it finishes, you should have two JSONL files corresponding to the training and evaluation datasets.

You can now validate those datasets with:

```bash
python3 -m utils.validate_data --train_yaml example/7B.yaml
```

You should get an estimate on the ETA for the training and there should not be any validation errors. If there are errors, you can fix them with:

```bash
python3 -m utils.reformat_data cryptocurrency_market_news_train.jsonl
python3 -m utils.reformat_data cryptocurrency_market_news_eval.jsonl
```

Validate the dataset again (if needed) and now there should be no errors:

```bash
python3 -m utils.validate_data --train_yaml example/7B.yaml
```

Everything is now ready to train the model, which you can do with:

```bash
CUDA_VISIBLE_DEVICES=0 python3 -m torch.distributed.run --nproc-per-node 1 --master_port 65123 -m train example/7B.yaml
```

The **`CUDA_VISIBLE_DEVICES=0`** is necessary to make sure the training script recognizes the GPU on the remote machine.

This process will take several minutes, possibly even hours. It will show an estimate of the remaining processing time.

After it is finished, you will be able to evaluate the trained model against the standard model, which we will see how to do in the next section.

## Evaluating the Fine-Tuned Model

To evaluate the fine-tuned model, we first need to establish a baseline with the default model.

First, you need to install the necessary package on the remote machine:

```bash
pip install mistral_inference
```

Now you can test the default model by running:

```bash
mistral-chat /mistral-finetune/mistral_models/ --max_tokens 1024 --temperature 0.7 --instruct
```

It will ask you for a prompt. Let’s try this one:

```bash
Prompt: how is x adverstising doing?

To provide an accurate answer, I would need specific details about X advertising. However, I can share some general insights about advertising in today&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;digital&lt;/span&gt; &lt;span class="n"&gt;landscape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="mf"&gt;1.&lt;/span&gt; &lt;span class="n"&gt;Digital&lt;/span&gt; &lt;span class="n"&gt;Advertising&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;With&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;rise&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;internet&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;mobile&lt;/span&gt; &lt;span class="n"&gt;devices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;digital&lt;/span&gt; &lt;span class="n"&gt;advertising&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="n"&gt;become&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;significant&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;marketing&lt;/span&gt; &lt;span class="n"&gt;mix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Platforms&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="n"&gt;Google&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Facebook&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Instagram&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;YouTube&lt;/span&gt; &lt;span class="n"&gt;offer&lt;/span&gt; &lt;span class="n"&gt;targeted&lt;/span&gt; &lt;span class="n"&gt;advertising&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;demographics&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interests&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;online&lt;/span&gt; &lt;span class="n"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="mf"&gt;2.&lt;/span&gt; &lt;span class="n"&gt;Social&lt;/span&gt; &lt;span class="n"&gt;Media&lt;/span&gt; &lt;span class="n"&gt;Advertising&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Social&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="n"&gt;platforms&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;popular&lt;/span&gt; &lt;span class="n"&gt;advertising&lt;/span&gt; &lt;span class="n"&gt;channels&lt;/span&gt; &lt;span class="n"&gt;due&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;their&lt;/span&gt; &lt;span class="n"&gt;vast&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;ability&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="n"&gt;ads&lt;/span&gt; &lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;profiles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Brands&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;social&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="n"&gt;ads&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;increase&lt;/span&gt; &lt;span class="n"&gt;brand&lt;/span&gt; &lt;span class="n"&gt;awareness&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;drive&lt;/span&gt; &lt;span class="n"&gt;traffic&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;their&lt;/span&gt; &lt;span class="n"&gt;websites&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt; &lt;span class="n"&gt;leads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="mf"&gt;3.&lt;/span&gt; &lt;span class="n"&gt;Influencer&lt;/span&gt; &lt;span class="n"&gt;Marketing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Influencer&lt;/span&gt; &lt;span class="n"&gt;marketing&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="n"&gt;grown&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;popularity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;brands&lt;/span&gt; &lt;span class="n"&gt;partner&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;social&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="n"&gt;influencers&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;promote&lt;/span&gt; &lt;span class="n"&gt;their&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt; &lt;span class="n"&gt;allows&lt;/span&gt; &lt;span class="n"&gt;brands&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;tap&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;influencer&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s audience and leverage their credibility.

4. Traditional Advertising: While digital advertising is on the rise, traditional advertising methods like television, radio, print, and outdoor advertising still have a place in the marketing mix, especially for reaching broader audiences or those who are less tech-savvy.

5. Measuring Success: Advertising success is often measured by metrics such as reach, impressions, click-through rates, conversion rates, and return on investment (ROI). Brands use these metrics to evaluate the effectiveness of their advertising campaigns and make data-driven decisions.

Without more specific information about X advertising, it&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;difficult&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;say&lt;/span&gt; &lt;span class="n"&gt;how&lt;/span&gt; &lt;span class="n"&gt;they&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;doing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;It&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s essential for brands to regularly analyze their advertising performance and adjust their strategies as needed to maximize their return on investment.

```

As you can see, the default model gave a very generic answer.

Now let’s run the fine-tuned model with:

```bash
mistral-chat /mistral-finetune/mistral_models/ --max_tokens 1024 --temperature 0.7 --instruct --lora_path /mistral-finetune/chat_test/checkpoints/checkpoint_000300/consolidated/lora.safetensors
```

And we use the same prompt:

```bash
Prompt: how is x adverstising doing?

X advertising is currently seeing a slight increase in performance.
```

As you can see, the fine-tuned model gave a much more accurate and precise answer.

### Impact on Domain Knowledge

Fine-tuning MistralAI on financial data significantly improves the model&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;ability&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;understand&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;operate&lt;/span&gt; &lt;span class="n"&gt;within&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="n"&gt;transforms&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;specialized&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;deep&lt;/span&gt; &lt;span class="n"&gt;understanding&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Here&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;exposed&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;subset&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="n"&gt;news&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;but&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;exposing&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;specific&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;such&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;reports&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt; &lt;span class="n"&gt;analysis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;regulatory&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;learns&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;precise&lt;/span&gt; &lt;span class="n"&gt;meanings&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;nuances&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;terminology&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="n"&gt;helps&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;stay&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;ongoing&lt;/span&gt; &lt;span class="n"&gt;trends&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;industry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;includes&lt;/span&gt; &lt;span class="n"&gt;understanding&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;implications&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;market&lt;/span&gt; &lt;span class="n"&gt;movements&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;economic&lt;/span&gt; &lt;span class="n"&gt;indicators&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;geopolitical&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;markets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;enhanced&lt;/span&gt; &lt;span class="n"&gt;understanding&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;specialization&lt;/span&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;perform&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;wide&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;finance&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;greater&lt;/span&gt; &lt;span class="n"&gt;accuracy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;relevance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;compliance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;makes&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;invaluable&lt;/span&gt; &lt;span class="n"&gt;asset&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;professionals&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;organizations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;helping&lt;/span&gt; &lt;span class="n"&gt;them&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;informed&lt;/span&gt; &lt;span class="n"&gt;decisions&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;improve&lt;/span&gt; &lt;span class="n"&gt;their&lt;/span&gt; &lt;span class="n"&gt;overall&lt;/span&gt; &lt;span class="n"&gt;performance&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;financial&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="c1"&gt;## Conclusion
&lt;/span&gt;
&lt;span class="n"&gt;You&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ve just completed this tutorial on fine-tuning MistralAI on Koyeb Serverless GPUs.

You can check out the example repository for this tutorial on Koyeb&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;GitHub&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;MistralAI&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;koyeb&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;finetune&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;mistralai&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;serverless&lt;/span&gt; &lt;span class="n"&gt;GPUs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;While&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;guide&lt;/span&gt; &lt;span class="n"&gt;focused&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;fine&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tuning&lt;/span&gt; &lt;span class="n"&gt;MistralAI&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;finance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;approach&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;techniques&lt;/span&gt; &lt;span class="n"&gt;covered&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;same&lt;/span&gt; &lt;span class="n"&gt;across&lt;/span&gt; &lt;span class="n"&gt;various&lt;/span&gt; &lt;span class="n"&gt;domains&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Whether&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;re working with healthcare data, legal documents, technical manuals, or customer service interactions, fine-tuning can significantly improve the relevance and accuracy of AI models.

Have fun experimenting with your own datasets and seeing how fine-tuning can add value and improve performance in your specific area of interest!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Fine-Tune Llama 3.1 8B using QLORA</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Wed, 02 Oct 2024 08:33:53 +0000</pubDate>
      <link>https://dev.to/koyeb/fine-tune-llama-31-8b-using-qlora-e59</link>
      <guid>https://dev.to/koyeb/fine-tune-llama-31-8b-using-qlora-e59</guid>
      <description>&lt;p&gt;Large Language Models (LLMs) are fantastic tools for getting quick answers on programming questions. However, their knowledge is not always up to date and they may not know about your favourite framework or library. Maybe it's software that only your company uses, a new framework that's just come out or a new version of a popular library.&lt;/p&gt;

&lt;p&gt;In this guide, we'll walk you through how to fine-tune an LLM on your favourite project's documentation. This will enable the model to answer questions with (hopefully) correct, and up-to-date information. We'll be using Llama 3.1 8B, Meta's latest open-source model and teach it about Apple's new deep learning framework: MLX.&lt;/p&gt;

&lt;p&gt;We will first generate a custom LLM training dataset from Apple's documentation and publish it on the HuggingFace Hub. Then, we'll fine-tune Llama 3.1 8B using QLORA, a training method which significantly reduces GPU memory usage and training time. Finally, we'll deploy the model on Koyeb's serverless GPUs, enabling you to get answers to your questions in real-time.&lt;/p&gt;

&lt;p&gt;Quick disclaimer: This guide is intended as an introductory overview. Fine-tuning a language model involves careful consideration of data distribution, hyperparameters, and continual pre-training. For production-level models, a more rigorous approach is required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;To successfully follow this tutorial, you will need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;Python 3.&lt;/a&gt; or later.&lt;/li&gt;
&lt;li&gt;An &lt;a href="https://platform.openai.com/api-keys" rel="noopener noreferrer"&gt;OpenAI API key&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://huggingface.co/settings/tokens" rel="noopener noreferrer"&gt;HuggingFace access token&lt;/a&gt; with write permissions and access to &lt;a href="https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct" rel="noopener noreferrer"&gt;Llama 3.1 8B Instruct&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://wandb.ai/" rel="noopener noreferrer"&gt;Weights &amp;amp; Biases access token&lt;/a&gt; (Optional).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Configure the local environment.&lt;/li&gt;
&lt;li&gt;Build the Apple MLX documentation from source (Optional).&lt;/li&gt;
&lt;li&gt;Generate the training dataset with Python and the OpenAI API.&lt;/li&gt;
&lt;li&gt;Fine-tune the model using Jupyter Notebook on Koyeb.&lt;/li&gt;
&lt;li&gt;Deploy and use the fine-tuned model.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Configure the local environment
&lt;/h2&gt;

&lt;p&gt;First, we'll clone the repository for this project and create a Python virtual environment and install the required dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone the repository&lt;/span&gt;
git clone https://github.com/koyeb/finetune-llama-on-koyeb.git
&lt;span class="nb"&gt;cd &lt;/span&gt;finetune-llama-on-koyeb

&lt;span class="c"&gt;# Create a virtual environment&lt;/span&gt;
python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv

&lt;span class="c"&gt;# Active the virtual environment (Windows)&lt;/span&gt;
.&lt;span class="se"&gt;\v&lt;/span&gt;&lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;cripts&lt;span class="se"&gt;\a&lt;/span&gt;ctivate.bat
&lt;span class="c"&gt;#  Active the virtual environment (Linux &amp;amp; macOS)&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; ./venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's install the dependencies required for this project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="nv"&gt;datasets&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;2.16.1 &lt;span class="nv"&gt;openai&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;1.42.0 tqdm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;datasets&lt;/code&gt; library is used to push our dataset to the HuggingFace Hub and the openai library lets us interact with the OpenAI API.&lt;/p&gt;

&lt;p&gt;Next, we'll login to the HuggingFace Hub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;huggingface-cli login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the instructions in the terminal and paste your access token when prompted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build the Apple MLX documentation from source (Optional)
&lt;/h3&gt;

&lt;p&gt;The repository for this tutorial already contains the Apple MLX documentation in text format. However, if you want to build the documentation from source, you can follow the instructions below. Otherwise, you can skip to the next step.&lt;/p&gt;

&lt;p&gt;You'll need to install doxygen to build the Apple MLX documentation from source.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install doxygen (macOS)&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;doxygen
&lt;span class="c"&gt;# Install doxygen (Linux)&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;doxygen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can clone the MLX repository and build the documentation using Doxygen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone the MLX repository&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; mlx &lt;span class="p"&gt;;&lt;/span&gt; git clone git@github.com:ml-explore/mlx.git

&lt;span class="c"&gt;# Install the required dependencies and build the documentation in text format&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;mlx/docs
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; mlx/requirements.txt
doxygen &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; make text

&lt;span class="c"&gt;# Move back to the project directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ../..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything went well, the &lt;code&gt;mlx/docs/build/text directory&lt;/code&gt; should now contain the documentation in text format. If you encounter any issues, you can fallback to using the pre-built documentation from the repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate the training dataset
&lt;/h2&gt;

&lt;p&gt;To generate the training datase, we'll use the OpenAI API. The script generate_dataset.py in the repository does this for us. There's a lot going on in this script, so let's break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At the top of the file, we define the prompts used to generate questions and answers.&lt;/li&gt;
&lt;li&gt;After parsing the command-line arguments, we read all the documentation files in an array.&lt;/li&gt;
&lt;li&gt;For each chunk of documentation, we generate N questions using the chat endpoint of the OpenAI API.

&lt;ul&gt;
&lt;li&gt;We use OpenAI's structured output feature to ensure the model generates a list of questions. This is done by specifying a JSON schema in the response_format parameter.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;For each question, we generate an answer using the same chat endpoint.&lt;/li&gt;

&lt;li&gt;Finally, we write the question-answer pairs to a JSONL file and push it to the HuggingFace Hub.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;We can now run the script, specifying the input directory, output file location, the OpenAI model to use and the HuggingFace repository to push the dataset to. This should be the name of your organization (or HuggingFace account) and the name of the dataset (for example koyeb/Apple-MLX-QA).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'your-openai-api-key'&lt;/span&gt;
python generate_dataset.py &lt;span class="nt"&gt;--input&lt;/span&gt; mlx/docs/build/text &lt;span class="nt"&gt;--output&lt;/span&gt; apple-mlx-qa.jsonl &lt;span class="nt"&gt;--model&lt;/span&gt; gpt-4o &lt;span class="nt"&gt;--repo&lt;/span&gt; koyeb/Apple-MLX-QA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should use less than 10$ in OpenAI credits and take an hour or so. If you don't have an OpenAI API key or don't want to use it, you can skip to the next step and &lt;a href="https://huggingface.co/datasets/koyeb/Apple-MLX-QA" rel="noopener noreferrer"&gt;use the dataset we published on HuggingFace&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fine-tune the model using Jupyter Notebook on Koyeb
&lt;/h2&gt;

&lt;p&gt;Now that we have our fine-tuning dataset, we can proceed with fine-tuning. The next step involves deploying a Jupyter Notebook server on a Koyeb GPU instance. To do this, you can visit the &lt;a href="https://www.koyeb.com/deploy/pytorch-jupyter" rel="noopener noreferrer"&gt;One-Click App page for the Jupyter Notebook on Koyeb&lt;/a&gt; and follow the instructions on the page.&lt;/p&gt;

&lt;p&gt;Once your service is started, visit the URL and connect to the Jupyter server using the password you set during the deployment process. Once you're logged into Jupyter, import the notebook.ipynb file by clicking on the "Upload" button in the Jupyter interface as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvobxzau1qm3nf25wk0gt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvobxzau1qm3nf25wk0gt.png" alt="Upload the notebook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The rest of the instructions for this step are in the notebook. Once you're done, you can come back here to deploy and use the fine-tuned model on Koyeb.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy and use the fine-tuned model on Koyeb
&lt;/h2&gt;

&lt;p&gt;This section teaches you how to use the model in Python code and how to deploy it for production use on Koyeb's serverless GPUs.&lt;/p&gt;

&lt;p&gt;You can use your LORA adapter in Python code using torch, transformers, and peft. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install torch transformers peft
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;peft&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;PeftModel&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;

&lt;span class="c1"&gt;# Load the base model and tokenizer
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meta-llama/Llama-3.1-8B-Instruct&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;torch_dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bfloat16&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meta-llama/Llama-3.1-8B-Instruct&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Load the fine-tuned model using LORA
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PeftModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;koyeb/Meta-Llama-3.1-8B-Instruct-Apple-MLX-Adapter&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cuda&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Define input using a chat template with a system prompt and user query
&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply_chat_template&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a helpful AI coding assistant with expert knowledge of Apple&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s latest machine learning framework: MLX. You can help answer questions about MLX, provide code snippets, and help debug code.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How do you transpose a matrix in MLX?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;tokenize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;add_generation_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cuda&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Generate and print the response
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_new_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;
            &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For production, you can deploy your fine-tune on Koyeb's serverless GPUs using vLLM with One-Click Apps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit the One-Click App page for vLLM and click the "Deploy" button.&lt;/li&gt;
&lt;li&gt;Override the command args and specify the HuggingFace repository for your merged model: ["--model", "YOUR-ORG/Meta-LLaMa-3.1-8B-Instruct-Apple-MLX"]&lt;/li&gt;
&lt;li&gt;Set your HuggingFace access token in the HF_TOKEN environment variable. Optionally, set VLLM_DO_NOT_TRACK to 1 to disable telemetry.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once deployed, you can interact with the model using the OpenAI API format. Here's an example using curl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://YOUR-SERVICE-URL.koyeb.app/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
     "messages": [
        {"role": "system", "content": "You are a helpful AI coding assistant with expert knowledge of Apple latest machine learning framework: MLX. You can help answer questions about MLX, provide code snippets, and help debug code."}
        {"role": "user", "content": "How do you transpose a matrix in MLX?"}
    ],
     "temperature": 0.3
   }'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations, you've successfully fine-tuned Llama 3.1 8B using QLORA!&lt;/p&gt;

&lt;p&gt;Remember, fine-tuning is an iterative process. Feel free to experiment with different hyperparameters and training methods to get the best results. You can also work on increasing the size or improving the quality of your training dataset using additional data sources or data augmentation techniques.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Volumes: High IOPS and Low Latency NVMe SSDs Public Preview</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Mon, 23 Sep 2024 11:00:00 +0000</pubDate>
      <link>https://dev.to/koyeb/volumes-high-iops-and-low-latency-nvme-ssds-public-preview-3209</link>
      <guid>https://dev.to/koyeb/volumes-high-iops-and-low-latency-nvme-ssds-public-preview-3209</guid>
      <description>&lt;p&gt;It’s the final day of &lt;a href="https://www.koyeb.com/blog/koyeb-launch-week-round-2" rel="noopener noreferrer"&gt;Koyeb's Launch Week Round 2&lt;/a&gt;, and today we’re announcing the public preview of Volumes!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.koyeb.com/docs/reference/volumes" rel="noopener noreferrer"&gt;Volumes&lt;/a&gt; on Koyeb are blazing-fast NVMe SSD you can use to persist data across deployments.&lt;br&gt;
After announcing &lt;a href="https://www.koyeb.com/blog/volumes-technical-preview-blazing-fast-nvme-ssd-for-your-data" rel="noopener noreferrer"&gt;Volumes in technical preview&lt;/a&gt; a few months ago, we are now opening the preview to all users on the Starter plan!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcgg609elcmadj8q3j14e.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcgg609elcmadj8q3j14e.gif" alt="Volumes Public Preview" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Offering high throughput and low latency, Volumes open the door to a wide range of new workloads and use cases to handle the state of your applications.&lt;br&gt;
Whether you’re looking to run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clustered databases&lt;/li&gt;
&lt;li&gt;Object storage&lt;/li&gt;
&lt;li&gt;Queue systems&lt;/li&gt;
&lt;li&gt;Storing model checkpoints and weights for AI workloads&lt;/li&gt;
&lt;li&gt;Or anything else that requires data persistence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Get seamless data persistence by deploying any container image from &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;DockerHub&lt;/a&gt; - such as Minio, Neo4j, ClickHouse, or Meilisearch - on Koyeb. With just a few clicks or simple CLI commands, you can leverage volumes and persist your data across deployments.&lt;/p&gt;

&lt;p&gt;Right now, Volumes are available in Washington DC and Frankfurt for all Standard CPU instance types. Over the next few months, we will progressively add Volumes to more regions, if you are interested in a specific region, just &lt;a href="https://feedback.koyeb.com/" rel="noopener noreferrer"&gt;let us know&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
  During the public preview, Volumes are completely free, so dive in and start adding persistence to your&lt;br&gt;
  services!&lt;br&gt;
{' '}&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started with Volumes
&lt;/h2&gt;

&lt;p&gt;To help you get started, here are a few examples to deploy some popular stateful applications including Minio, ClickHouse, MongoDB, and Neo4j using Volumes to handle data persistence using &lt;a href="https://www.koyeb.com/docs/build-and-deploy/cli/installation" rel="noopener noreferrer"&gt;Koyeb CLI&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Minio
&lt;/h3&gt;

&lt;p&gt;Minio is a high-performance distributed object storage server with an S3 compatible API.&lt;br&gt;
In the following example, we will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a 10GB Volume in the Washington DC region&lt;/li&gt;
&lt;li&gt;Deploy Minio using the official Minio Docker image &lt;code&gt;quay.io/minio/minio&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attach the &lt;code&gt;minio-data&lt;/code&gt; Volume to the service and mount our volume into the &lt;code&gt;/data&lt;/code&gt; directory of the container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Volume&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb volume create minio-data &lt;span class="nt"&gt;--size&lt;/span&gt; 10 &lt;span class="nt"&gt;--region&lt;/span&gt; was
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy Minio&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb app init minio &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker&lt;/span&gt; quay.io/minio/minio &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker-command&lt;/span&gt; server &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker-args&lt;/span&gt; /data &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker-args&lt;/span&gt; &lt;span class="nt"&gt;--console-address&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker-args&lt;/span&gt; :9001 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; was &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--volumes&lt;/span&gt; minio-data:/data &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;MINIO_BROWSER_REDIRECT_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://&lt;span class="o"&gt;{{&lt;/span&gt; KOYEB_PUBLIC_DOMAIN &lt;span class="o"&gt;}}&lt;/span&gt;/console/ &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 9000:http &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 9001:http &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--route&lt;/span&gt; /:9000 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--route&lt;/span&gt; /console:9001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ClickHouse
&lt;/h3&gt;

&lt;p&gt;ClickHouse is a fast and resource efficient open-source column-oriented database management system.&lt;br&gt;
In the following example, we will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a 10GB Volume in the Washington DC region&lt;/li&gt;
&lt;li&gt;Deploy ClickHouse using the official ClickHouse Docker image &lt;code&gt;clickhouse/clickhouse-server&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attach the &lt;code&gt;clickhouse-data&lt;/code&gt; Volume to the service and mount our volume into the &lt;code&gt;/var/lib/clickhouse&lt;/code&gt; directory of the container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Volume&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb volume create clickhouse-data &lt;span class="nt"&gt;--size&lt;/span&gt; 10 &lt;span class="nt"&gt;--region&lt;/span&gt; was
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy ClickHouse&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb app init clickhouse-server &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker&lt;/span&gt; clickhouse/clickhouse-server &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; was &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--volumes&lt;/span&gt; clickhouse-data:/var/lib/clickhouse &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;CLICKHOUSE_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;main &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;CLICKHOUSE_PASSOWRd&lt;/span&gt;&lt;span class="o"&gt;={{&lt;/span&gt; secrets.clickhouse_password &lt;span class="o"&gt;}}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 8123:http &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 9000:tcp &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--route&lt;/span&gt; /:8123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  MongoDB
&lt;/h3&gt;

&lt;p&gt;MongoDB is a general-purpose, document-based, distributed database built for modern applications.&lt;br&gt;
In the following example, we will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a 10GB Volume in the Washington DC region&lt;/li&gt;
&lt;li&gt;Deploy MongoDB using the official MongoDB Docker image &lt;code&gt;mongo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attach the &lt;code&gt;mongo-data&lt;/code&gt; Volume to the service and mount our volume into the &lt;code&gt;/data/db&lt;/code&gt; directory of the container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Volume&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb volume create mongo-data &lt;span class="nt"&gt;--size&lt;/span&gt; 10 &lt;span class="nt"&gt;--region&lt;/span&gt; fra
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command above creates a 10GB Volume in the Frankfurt region.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deploy MongoDB&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb app init mongo &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker&lt;/span&gt; mongo &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; was &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--volumes&lt;/span&gt; mongo-data:/data/db &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;MONGO_INITDB_ROOT_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;main &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;MONGO_INITDB_ROOT_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;={{&lt;/span&gt; secrets.mongodb_password &lt;span class="o"&gt;}}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 27017:tcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Neo4j
&lt;/h3&gt;

&lt;p&gt;Neo4j is a highly scalable, robust native graph database.&lt;br&gt;
In the following example, we will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Created a 10GB Volume in the Washington DC region&lt;/li&gt;
&lt;li&gt;Deploy Neo4j using the official Neo4j Docker image &lt;code&gt;neo4j&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attach the &lt;code&gt;neo4j-data&lt;/code&gt; Volume to the service and mount our volume into the &lt;code&gt;/data&lt;/code&gt; directory of the container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Volume&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb volume create neo4j-data &lt;span class="nt"&gt;--size&lt;/span&gt; 10 &lt;span class="nt"&gt;--region&lt;/span&gt; fra
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command above creates a 10GB Volume in the Frankfurt region.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deploy Neo4j&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;koyeb app init neo4j &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--docker&lt;/span&gt; neo4j &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; was &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--volumes&lt;/span&gt; neo4j-data:/data &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;NEO4J_AUTH&lt;/span&gt;&lt;span class="o"&gt;={{&lt;/span&gt; secrets.neo4j_password &lt;span class="o"&gt;}}&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 7474:http &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--port&lt;/span&gt; 7687:tcp &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--route&lt;/span&gt; /:7474
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! For each of the example above, in less than 60 seconds, you will have a Minio, ClickHouse, Mongo, or Neo4j service running on Koyeb using a Volume to handle peristence.&lt;br&gt;
You can then start using from your other services using our built-in service mesh for secure service to service communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next?
&lt;/h2&gt;

&lt;p&gt;Volumes is a foundational primitive to build and run stateful applications on Koyeb. We're currently working on adding more features around data mobility to let you attach and detach Volumes from services and support snapshots to create a point-time copy of your Volumes.&lt;/p&gt;

&lt;p&gt;We're looking forward to your feedback to help us shape the product, and stay tuned as we roll out even more exciting updates during Launch Week!&lt;/p&gt;

</description>
      <category>database</category>
      <category>webdev</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>AWS Regions Public Preview: Deploy on AWS in Minutes</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Fri, 20 Sep 2024 15:40:55 +0000</pubDate>
      <link>https://dev.to/koyeb/aws-regions-public-preview-deploy-on-aws-in-minutes-29pf</link>
      <guid>https://dev.to/koyeb/aws-regions-public-preview-deploy-on-aws-in-minutes-29pf</guid>
      <description>&lt;p&gt;Today, we are thrilled to announce the &lt;strong&gt;public preview of AWS Regions on Koyeb&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;During last launch week, we introduced the &lt;a href="https://www.koyeb.com/blog/aws-regions-build-run-scale-on-aws-with-koyeb" rel="noopener noreferrer"&gt;private preview of AWS Regions&lt;/a&gt;. We announced our first region, the famous, &lt;strong&gt;us-east-1 (N. Virginia) region&lt;/strong&gt;, and started onboarding our first users.&lt;/p&gt;

&lt;p&gt;What’s new with this public preview? In addition to the &lt;strong&gt;us-east-1 location now being available to everyone&lt;/strong&gt; on the platform, you can now deploy to this region via &lt;strong&gt;the control panel and the CLI&lt;/strong&gt;! Get ready for faster releases and an even better deployment experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb1a6yztts4sfdckj5l3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb1a6yztts4sfdckj5l3.gif" alt="AWS Regions Public Preview" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to see another AWS region on the platform? &lt;a href="https://app.reclaim.ai/m/koyeb-intro/short-call" rel="noopener noreferrer"&gt;Let us know&lt;/a&gt; what you need! We will be adding more regions based on demand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why AWS regions on Koyeb?
&lt;/h2&gt;

&lt;p&gt;We repeatedly heard from some of our business users that they needed an &lt;strong&gt;easier way to deploy on their AWS infrastructure&lt;/strong&gt;. A solution where they could benefit from the seamless Koyeb deployment experience while running on their existing AWS infrastructure.&lt;/p&gt;

&lt;p&gt;This was the case for &lt;a href="https://www.sush.app/" rel="noopener noreferrer"&gt;Sush&lt;/a&gt;, a mobile game with several million users. Here's what Nathan Appere, CTO at Sush, had to say about the new AWS region on Koyeb:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Scaling Sush to several millions of users while maintaining a lean infrastructure has been a real challenge. We started on Heroku, but we lacked flexibility and the costs were unsustainable at scale. As we’re using AWS RDS with high bandwidth, we had to stay on AWS to control our egress costs. Switching to the Koyeb AWS region is a game changer: we have a seamless deployment experience, improved efficiency, and cut costs by 50%!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Get the power of 8+ AWS products without the hassle of manual configuration
&lt;/h2&gt;

&lt;p&gt;AWS offers a wide ecosystem of products and services. Setting up and managing infrastructure on AWS quickly becomes complex and a full time job, even for experienced teams.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2 machines&lt;/li&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;Gateways&lt;/li&gt;
&lt;li&gt;Load balancers&lt;/li&gt;
&lt;li&gt;VPCs&lt;/li&gt;
&lt;li&gt;Network policies&lt;/li&gt;
&lt;li&gt;Static IPs&lt;/li&gt;
&lt;li&gt;DNS&lt;/li&gt;
&lt;li&gt;Network policies&lt;/li&gt;
&lt;li&gt;Security policies&lt;/li&gt;
&lt;li&gt;Build pipelines&lt;/li&gt;
&lt;li&gt;Continuous deployment pipelines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You name it, AWS has it. And you need to manage it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdo8knxumq72rs37hqae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdo8knxumq72rs37hqae.png" alt="AWS Configuration Meme" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This where Koyeb comes in. &lt;strong&gt;Koyeb manages these layers, removes complexity, and provides you a seamless deployment experience out-of-the-box.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy on AWS Regions with Koyeb in Minutes
&lt;/h2&gt;

&lt;p&gt;As of today, everyone can deploy in our inaugural AWS region: &lt;code&gt;us-east-1&lt;/code&gt;! Deploying in this region is as simple as deploying in our &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;Koyeb regions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a quick rundown of how to deploy in the new AWS region using the &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;control panel&lt;/a&gt; and the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/cli/installation" rel="noopener noreferrer"&gt;Koyeb CLI&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Via the Control Panel
&lt;/h3&gt;

&lt;p&gt;For new deployments, simply click on the AWS tab above the map of core locations to select the new AWS region in us-east-1. From there, you can select the &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Instance&lt;/a&gt; size with the resources your workload needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb1a6yztts4sfdckj5l3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb1a6yztts4sfdckj5l3.gif" alt="AWS Regions on Koyeb" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Via the CLI
&lt;/h3&gt;

&lt;p&gt;As a part of this public preview, you can now deploy in &lt;code&gt;aws-us-east-1&lt;/code&gt; using the Koyeb CLI.&lt;/p&gt;

&lt;p&gt;Here’s an example for how to deploy our demo application in AWS us-east-1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;koyeb&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="nx"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;docker&lt;/span&gt; &lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;io&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;koyeb&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;demo&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;ports&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;regions&lt;/span&gt; &lt;span class="nx"&gt;aws&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;us&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;east&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;small&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;AWS regions are more expensive than &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Koyeb optimized regions&lt;/a&gt;. Here are the prices of our Standard Instance types on AWS:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Instance type&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;vCPU&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;RAM&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Disk&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Price&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;nano&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;td&gt;256MB&lt;/td&gt;
&lt;td&gt;2.5GB SSD&lt;/td&gt;
&lt;td&gt;$5.36/month($0.000002/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;micro&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;512MB&lt;/td&gt;
&lt;td&gt;5GB SSD&lt;/td&gt;
&lt;td&gt;$10.71/month($0.000004/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;small&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1GB&lt;/td&gt;
&lt;td&gt;10GB SSD&lt;/td&gt;
&lt;td&gt;$21.43/month($0.000008/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;medium&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2GB&lt;/td&gt;
&lt;td&gt;20GB SSD&lt;/td&gt;
&lt;td&gt;$42.85/month($0.000016/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;large&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4GB&lt;/td&gt;
&lt;td&gt;40GB SSD&lt;/td&gt;
&lt;td&gt;$85.71/month($0.000032/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;xlarge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;8GB&lt;/td&gt;
&lt;td&gt;80GB SSD&lt;/td&gt;
&lt;td&gt;$171.42/month($0.000064/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;2xlarge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;16GB&lt;/td&gt;
&lt;td&gt;160GB SSD&lt;/td&gt;
&lt;td&gt;$342.84/month($0.000128/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;3xlarge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;32GB&lt;/td&gt;
&lt;td&gt;240GB SSD&lt;/td&gt;
&lt;td&gt;$685.67/month($0.000256/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;4xlarge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;64GB&lt;/td&gt;
&lt;td&gt;320GB SSD&lt;/td&gt;
&lt;td&gt;$1371.34/month($0.000512/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;5xlarge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;128GB&lt;/td&gt;
&lt;td&gt;400GB SSD&lt;/td&gt;
&lt;td&gt;$2742.68/month($0.001024/second)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Keep in mind: As bandwidth is more expensive on AWS, we will charge you the real cost.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reduce Bandwidth Cost &amp;amp; Maximize Performance
&lt;/h3&gt;

&lt;p&gt;In this day and age of cloud, network is more expensive than compute.&lt;/p&gt;

&lt;p&gt;
  content="Switching to the Koyeb AWS region is a game changer: we have a seamless deployment experience, improved efficiency, and cut costs by 50%!"&lt;br&gt;
  author="Nathan Appere"&lt;br&gt;
  position="CTO, Sush"&lt;br&gt;
/&amp;gt;&lt;/p&gt;

&lt;p&gt;Running on AWS regions on Koyeb eliminates data transfer and bandwidth costs between your Koyeb services and AWS products, giving you the ability to scale faster and more cost-effectively.&lt;br&gt;
All while maximizing performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prototype with Koyeb, Deploy to Production on AWS
&lt;/h3&gt;

&lt;p&gt;Switching between Koyeb and AWS regions is as simple as one click.&lt;/p&gt;

&lt;p&gt;With Koyeb, you can deploy your applications and services across our &lt;a href="https://www.koyeb.com/docs/reference/edge-network" rel="noopener noreferrer"&gt;255+ edge locations&lt;/a&gt; and &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;6 core locations&lt;/a&gt; worldwide, so your applications run close to your users and provide them blazing-fast experiences.&lt;/p&gt;

&lt;p&gt;If you want to switch your deployment from one of our regions to an AWS region, or vice versa, it's just a matter of changing the region in your deployment configuration. In other words, one click away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Seamless deployment experience on top of high-performance infrastructure
&lt;/h2&gt;

&lt;p&gt;Whether its on AWS or our own infrastructure, we run the same secured virtualization technology on top of bare metal machines. Having control of the &lt;a href="https://www.koyeb.com/blog/the-koyeb-serverless-engine-from-kubernetes-to-nomad-firecracker-and-kuma" rel="noopener noreferrer"&gt;core technology&lt;/a&gt; allows us to offer you greater productivity and the best performance.&lt;/p&gt;

&lt;p&gt;With AWS Regions on Koyeb, you can seamlessly integrate the Koyeb deployment experience with AWS. Run on top of your existing infrastructure and leverage the entire AWS products portfolio.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s next: Join over 100k developers and deploy global applications across 3 continents 🚀
&lt;/h2&gt;

&lt;p&gt;Need a feature on Koyeb? Want to see what we'll be releasing on the platform next? Check out our &lt;a href="https://feedback.koyeb.com/" rel="noopener noreferrer"&gt;public roadmap&lt;/a&gt; and &lt;a href="https://feedback.koyeb.com/feature-requests" rel="noopener noreferrer"&gt;feature request platform&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you need some ideas about what to deploy first, check out our &lt;a href="https://www.koyeb.com/tutorials" rel="noopener noreferrer"&gt;tutorials&lt;/a&gt; section, our &lt;a href="https://www.koyeb.com/deploy" rel="noopener noreferrer"&gt;one-click apps catalog&lt;/a&gt;, and our collection of &lt;a href="https://www.koyeb.com/docs/deploy" rel="noopener noreferrer"&gt;deploy guides&lt;/a&gt; in our documentation.&lt;/p&gt;

&lt;p&gt;To get you started, we provide a Free Tier that lets you deploy your first service and managed database for free. If you want to know more about why we offer a free tier and how we sustain it, read our dedicated &lt;a href="https://www.koyeb.com/blog/sustaining-free-compute-in-a-hostile-environment" rel="noopener noreferrer"&gt;blog post about sustaining a free tier&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are looking forward to seeing what you’ll deploy across our global locations, including AWS us-east-1! 🚀 🌐&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>aws</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Paris and Tokyo Regions in GA</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Fri, 20 Sep 2024 15:38:56 +0000</pubDate>
      <link>https://dev.to/koyeb/paris-and-tokyo-regions-in-ga-l99</link>
      <guid>https://dev.to/koyeb/paris-and-tokyo-regions-in-ga-l99</guid>
      <description>&lt;p&gt;Today is Day 3 of Launch Week, and we are excited to announce not just one, but &lt;strong&gt;two new regions are generally available&lt;/strong&gt; to deploy your low-latency AI workloads, full stack applications, APIs, and databases &lt;em&gt;globally&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;Join us in welcoming &lt;strong&gt;Paris and Tokyo&lt;/strong&gt; to the Koyeb platform and to a growing list of &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;global locations&lt;/a&gt; where you can deploy your applications! 🎉&lt;/p&gt;

&lt;p&gt;As of today &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;GA locations&lt;/a&gt; now include: Paris 🇫🇷, Tokyo 🇯🇵, Washington, D.C. 🇺🇸, Singapore 🇸🇬, and Frankfurt. 🇩🇪 🇪🇺&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm72hyl400mxq1wsdj3fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm72hyl400mxq1wsdj3fh.png" alt="Paris and Tokyo" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything you need to deploy high performance serverless apps is now available in Paris and Tokyo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Standard Instances&lt;/a&gt; with blazing fast CPUs to host your APIs, inference endpoints, or &lt;a href="https://www.koyeb.com/blog/deploy-and-scale-high-performance-background-jobs-with-koyeb-workers" rel="noopener noreferrer"&gt;Workers&lt;/a&gt; for async processing&lt;/li&gt;
&lt;li&gt;Deploy any one of &lt;a href="https://www.koyeb.com/deploy" rel="noopener noreferrer"&gt;over 40 Apps in One-Click&lt;/a&gt; or your own GitHub repository and Docker containers&lt;/li&gt;
&lt;li&gt;Our &lt;a href="https://www.koyeb.com/blog/70-faster-deployments-and-high-performance-private-network" rel="noopener noreferrer"&gt;70% faster deployment speed and high-performance private network&lt;/a&gt; that we announced yesterday.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, the Paris and Tokyo regions benefit from our zero infrastructure management experience with all the platform’s features: &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;continuous deployment&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/autoscaling" rel="noopener noreferrer"&gt;autoscaling&lt;/a&gt;, built-in &lt;a href="https://www.koyeb.com/docs/reference/edge-network" rel="noopener noreferrer"&gt;edge network&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/reference/service-mesh-and-discovery" rel="noopener noreferrer"&gt;service discovery&lt;/a&gt; for seamless service-to-service communication, real-time logs and &lt;a href="https://www.koyeb.com/docs/run-and-scale/metrics" rel="noopener noreferrer"&gt;metrics&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy in Paris and Tokyo in Seconds 秒
&lt;/h2&gt;

&lt;p&gt;Whether you prefer a user-friendly control panel or prefer working from your terminal, you can deploy through our dashboard or CLI within seconds.&lt;/p&gt;

&lt;p&gt;Our platform supports deployments with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.koyeb.com/docs/build-and-deploy/build-from-git" rel="noopener noreferrer"&gt;Git&lt;/a&gt;&lt;/strong&gt;: Seamlessly integrate with GitHub to push code directly from your repositories to production. We take care of the build process, using either native buildpacks or a Dockerfile that you provide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images" rel="noopener noreferrer"&gt;Docker images&lt;/a&gt;&lt;/strong&gt;: Deploy container images from any public or private registry. This is ideal if you already have a CI pipeline generating Docker images. In both cases, your workloads are run in isolated Firecracker microVMs on our bare metal servers, located in your chosen regions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-project-directory" rel="noopener noreferrer"&gt;Local directory&lt;/a&gt;&lt;/strong&gt;: Using the Koyeb CLI, you can build and deploy your application directly from your project's directory. Unlike deploying with GitHub or from a container registry, deploying from a project directory does not require any intermediary services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For today’s demo, we’ll deploy a sample Go application from a public Git repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Via the CLI
&lt;/h3&gt;

&lt;p&gt;To deploy our Go example in Paris and Tokyo, run the following command with the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;koyeb app init fast \
  --git github.com/koyeb/go \
  --git-branch main \
  --regions par,tyo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the deployment has finished and your application is live, run the following command to obtain the public domain, which you can then use to access your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;koyeb app get fast
ID          NAME    STATUS      DOMAINS                                 CREATED AT
b77006e8    fast    STARTING    ["fast-lets-go-2455e588.koyeb.app"] 18 Sep 24 08:58 UTC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Via the control panel
&lt;/h3&gt;

&lt;p&gt;To deploy any project in Paris and Tokyo using the &lt;a href="https://www.koyeb.com/blog/new-dashboard-build-run-and-scale-apps-in-minutes-with-a-simple-and-elegant-interface" rel="noopener noreferrer"&gt;freshly revamped control panel&lt;/a&gt;, you will need to follow 3 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;👨‍💻 Select your deployment method: &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; or &lt;a href="https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⬇️ Import your project&lt;/li&gt;
&lt;li&gt;✅ Configure your service&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After you've imported your project, you can &lt;strong&gt;select the instance type and the regions&lt;/strong&gt; you want to deploy to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo7vbepqv1facs4webpj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo7vbepqv1facs4webpj.png" alt="Deploying a Go application in Koyeb" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the service summary page you'll see before deploying the example Golang application using the control panel:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxep485m6inna8k8ttkag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxep485m6inna8k8ttkag.png" alt="Deploying a Go application in Koyeb" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this page, you can configure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.koyeb.com/docs/build-and-deploy/build-from-git" rel="noopener noreferrer"&gt;Builder&lt;/a&gt;&lt;/strong&gt;: Koyeb can use either native buildpacks or a Dockerfile to build your application&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/build-and-deploy/environment-variables" rel="noopener noreferrer"&gt;Environment variables&lt;/a&gt;: You can also set &lt;a href="https://www.koyeb.com/docs/reference/secrets" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt; to keep sensitive information safe&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Instance type&lt;/a&gt;: GPU, Standard, and Eco Instances&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;Regions&lt;/a&gt;: Tokyo, Paris, San Francisco, Washington, D.C., Frankfurt, and Signapore&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/run-and-scale/autoscaling" rel="noopener noreferrer"&gt;Scaling&lt;/a&gt;: Fixed or autoscaling&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/build-and-deploy/exposing-your-service" rel="noopener noreferrer"&gt;Ports&lt;/a&gt;: The ports on which your service listens&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.koyeb.com/docs/run-and-scale/health-checks" rel="noopener noreferrer"&gt;Health checks&lt;/a&gt;: By default, Koyeb automatically performs TCP health checks on your Service's exposed ports to ensure maximum availability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can see the estimated cost of your service before deploying it. Once you’re ready, hit &lt;strong&gt;Deploy&lt;/strong&gt; to launch your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Paris and Tokyo?
&lt;/h2&gt;

&lt;p&gt;Proximity is essential when it comes to delivering optimal performance to your end users in Europe and APAC.&lt;br&gt;
&lt;a href="https://feedback.koyeb.com/feature-requests/p/france-eu-core-location" rel="noopener noreferrer"&gt;Paris&lt;/a&gt; and &lt;a href="https://feedback.koyeb.com/feature-requests/p/north-east-asia-core-location" rel="noopener noreferrer"&gt;Tokyo&lt;/a&gt; were two highly demanded regions for the platform.&lt;/p&gt;

&lt;p&gt;Hosting your services closer to your audience &lt;strong&gt;improves connectivity and reduces latency&lt;/strong&gt;, ensuring a faster and smoother experience.&lt;/p&gt;

&lt;p&gt;As a part of our mission to provide everyone using your apps and services the best possible experience, we needed to add a core location closer to them.&lt;br&gt;
We're so excited about the thriving tech ecosystems in these regions and look forward to seeing what you deploy there!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo33mxjmr0exe785n92h9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo33mxjmr0exe785n92h9.png" alt="New GA regions" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.koyeb.com/pricing" rel="noopener noreferrer"&gt;Standard Instance&lt;/a&gt; in Paris and Tokyo are available for everyone at the same price than other regions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our pricing model is simple and transparent: you only pay resources used per second, allowing you to scale based on your needs.&lt;br&gt;
You can deploy our &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;GPU, Standard, and Eco Instances&lt;/a&gt; on-demand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GPU Instances are perfect for running AI workloads and inference. &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Explore our GPU Instances&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Standard Instances are ideal for production workloads and resource-intensive applications. &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Explore our Standard Instances&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Eco Instances are designed for cost-effective workloads that can tolerate some latency. &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Explore our Eco Instances&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also offer managed PostgreSQL databases, so you can run your databases in the same place as your services. &lt;a href="https://www.koyeb.com/docs/databases" rel="noopener noreferrer"&gt;Explore our Postgres database details and pricing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more details, check our &lt;a href="https://www.koyeb.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; or &lt;a href="https://tally.so/r/nGLjGo" rel="noopener noreferrer"&gt;contact us&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Built-in to all Koyeb Instances to Power Your Apps
&lt;/h3&gt;

&lt;p&gt;We're bringing the world’s best serverless features to Paris and Tokyo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;Continuous delivery with Git&lt;/a&gt; streamlines pushing your code to production&lt;/li&gt;
&lt;li&gt;🧑‍💻 Deploy code from &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; or &lt;a href="https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images" rel="noopener noreferrer"&gt;pre-built Docker images&lt;/a&gt; from your container registry&lt;/li&gt;
&lt;li&gt;🐳 Automatic build process with &lt;a href="https://www.koyeb.com/docs/build-and-deploy/build-from-git" rel="noopener noreferrer"&gt;native buildpacks&lt;/a&gt; or via your &lt;a href="https://www.koyeb.com/blog/dockerfile-deployment-on-high-performance-microvms-is-ga" rel="noopener noreferrer"&gt;Dockerfile&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🗺️ Global deployments in any or all &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;6 regions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📈 &lt;a href="https://www.koyeb.com/docs/run-and-scale/autoscaling" rel="noopener noreferrer"&gt;Autoscaling&lt;/a&gt; automatically adapts the resources allocated to your services to adapt to your production traffic while giving you full control of the maximum costs you will be paying&lt;/li&gt;
&lt;li&gt;🌐 &lt;a href="https://www.koyeb.com/blog/building-a-multi-region-service-mesh-with-kuma-envoy-anycast-bgp-and-mtls" rel="noopener noreferrer"&gt;Built-in edge network&lt;/a&gt; ensures requests to your service are always routed to the closest edge location and if need be to the closest core location. &lt;a href="https://www.koyeb.com/docs/reference/edge-network" rel="noopener noreferrer"&gt;Global Edge Network&lt;/a&gt; provides native load balancing, TLS encryption, and caching&lt;/li&gt;
&lt;li&gt;🤝 Support for &lt;a href="https://www.koyeb.com/blog/enabling-grpc-and-http2-support-at-edge-with-kuma-and-envoy" rel="noopener noreferrer"&gt;gRPC, HTTP/2&lt;/a&gt; and websockets&lt;/li&gt;
&lt;li&gt;🔎 Built-in &lt;a href="https://www.koyeb.com/docs/reference/service-mesh-and-discovery" rel="noopener noreferrer"&gt;service mesh and discovery&lt;/a&gt; for seamless service-to-service communication&lt;/li&gt;
&lt;li&gt;📊 Get insights into your service with &lt;a href="https://www.koyeb.com/blog/koyeb-metrics-built-in-observability-to-monitor-your-apps-performances" rel="noopener noreferrer"&gt;Koyeb Metrics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📃 &lt;a href="https://www.koyeb.com/docs/run-and-scale/log-exporter" rel="noopener noreferrer"&gt;Log exporter&lt;/a&gt; to forward logs to external log management&lt;/li&gt;
&lt;li&gt;🧑‍⚕️ Configure &lt;a href="https://www.koyeb.com/docs/run-and-scale/health-checks" rel="noopener noreferrer"&gt;custom health checks&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🤫 &lt;a href="https://www.koyeb.com/docs/reference/secrets" rel="noopener noreferrer"&gt;Secrets Management&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🧑‍💻 Deploy and manage your services with the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/cli/installation" rel="noopener noreferrer"&gt;Koyeb CLI&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/integrations/infrastructure-as-code/terraform" rel="noopener noreferrer"&gt;Terraform&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/integrations/infrastructure-as-code/pulumi" rel="noopener noreferrer"&gt;Pulumi&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next? Join over 100k developers and deploy global applications across 3 continents 🚀
&lt;/h2&gt;

&lt;p&gt;We are working on adding more regions to our platform. If you have a specific region in mind, please let us know by upvoting it on our &lt;a href="https://feedback.koyeb.com/feature-requests?search=regions" rel="noopener noreferrer"&gt;feedback board&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you need some ideas about what to deploy first, check out our &lt;a href="https://www.koyeb.com/tutorials" rel="noopener noreferrer"&gt;tutorials&lt;/a&gt; section, our &lt;a href="https://www.koyeb.com/deploy" rel="noopener noreferrer"&gt;one-click apps catalog&lt;/a&gt;, and our collection of &lt;a href="https://www.koyeb.com/docs/deploy" rel="noopener noreferrer"&gt;deploy guides&lt;/a&gt; in our documentation.&lt;/p&gt;

&lt;p&gt;To get you started, we provide a Free Tier that lets you deploy your first service and managed database for free. If you want to know more about why we offer a free tier and how we sustain it, read our dedicated blog post about &lt;a href="https://www.koyeb.com/blog/sustaining-free-compute-in-a-hostile-environment" rel="noopener noreferrer"&gt;sustaining a free tier&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are looking forward to seeing what you’ll deploy in Paris and Tokyo!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>70% Faster Deployments and High-Performance Private Network</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Tue, 17 Sep 2024 13:30:57 +0000</pubDate>
      <link>https://dev.to/koyeb/70-faster-deployments-and-high-performance-private-network-36h3</link>
      <guid>https://dev.to/koyeb/70-faster-deployments-and-high-performance-private-network-36h3</guid>
      <description>&lt;p&gt;It’s Day 2 of our &lt;a href="https://www.koyeb.com/blog/koyeb-launch-week-round-2" rel="noopener noreferrer"&gt;Launch Week&lt;/a&gt;, and we’re excited to unveil our &lt;strong&gt;new networking stack&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;If you're following us, you know that we're obsessed with performance: we want fast deployments and a speedy network once your apps are live.&lt;/p&gt;

&lt;p&gt;Long story short: while working on optimizing deployments speed, we hit limitations with our old stack, we decided to revamp everything and built a new networking stack for the platform.&lt;/p&gt;

&lt;p&gt;When you deploy on the platform, you get &lt;strong&gt;advanced capabilities out-of-the-box&lt;/strong&gt; including &lt;a href="https://www.koyeb.com/docs/reference/edge-network" rel="noopener noreferrer"&gt;automatic load-balancing&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/reference/edge-network#built-in-tls" rel="noopener noreferrer"&gt;fully encrypted private networking&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/metrics" rel="noopener noreferrer"&gt;built-in observability&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/health-checks" rel="noopener noreferrer"&gt;auto-healing&lt;/a&gt;, and &lt;a href="https://www.koyeb.com/docs/reference/service-mesh-and-discovery" rel="noopener noreferrer"&gt;automatic service discovery&lt;/a&gt; to name a few. All these features are tied to the networking stack.&lt;/p&gt;

&lt;p&gt;To build this new network layer, we've replaced our previous setup, a forked Kuma Mesh, with a custom-built stack on top of Envoy and Cilium. We had to completely rewrite our GLB component (Global Load Balancer), move to a custom service mesh built on CoreDNS and backed by Consul DNS, and swap out sidecars for a power combination of Cilium and &lt;a href="https://www.koyeb.com/blog/ebpf-the-future-of-the-service-mesh-and-network-innovation" rel="noopener noreferrer"&gt;eBPF&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This brings three major improvements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;70% faster deployments&lt;/strong&gt;: A new service now takes between a couple of seconds and 90 seconds to go live. Previously, it could take up to 5 minutes before. (Don't quote us on this if you have a 200GB model in your image (: )&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High-Performance Private Network&lt;/strong&gt;: The built-in private network, or VPC, now provides up to 10 Gb/s of bandwidth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved deployment reliability&lt;/strong&gt;: Network configuration propagation errors are gone!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is now live in &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;all regions&lt;/a&gt; and all new deployments happen on this new stack!&lt;/p&gt;

&lt;h2&gt;
  
  
  From Envoy sidecars with Kuma to eBPF processing with Cilium and... Envoy
&lt;/h2&gt;

&lt;p&gt;When we started building Koyeb, we had to pick the right tools and technology to build and scale our platform in its early days.&lt;/p&gt;

&lt;p&gt;For the network stack, we've always aimed to provide a built-in service mesh with the following key features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-tenancy: network isolation for each user&lt;/li&gt;
&lt;li&gt;Service discovery: a service is addressable via an internal domain name&lt;/li&gt;
&lt;li&gt;Observability: Network calls between services may be traced and metrics can be collected&lt;/li&gt;
&lt;li&gt;Built-in load-balancing: to easily scale and autoscale horizontally services&lt;/li&gt;
&lt;li&gt;Resiliency: Automatic detection of instances not answering to health checks&lt;/li&gt;
&lt;li&gt;Zero Trust Network: mTLS in between each Instance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We picked Kuma, an open-source service mesh built on top of Envoy, to build our &lt;a href="https://www.koyeb.com/blog/building-a-multi-region-service-mesh-with-kuma-envoy-anycast-bgp-and-mtls" rel="noopener noreferrer"&gt;multi-region service mesh&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;Kuma helped us go from nothing to scaling 10s of thousands of applications running on the platform.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then, we started to hit limitations as we scaled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deployment speed&lt;/strong&gt;: The relationship between networking and deployment speed is &lt;strong&gt;&lt;em&gt;network convergence time&lt;/em&gt;&lt;/strong&gt;. We want faster deployment times so you can deploy a critical patch in seconds and iterate quickly. Our machinery used to spend a lot of time computing network configurations and delivering them to a numerous amount of proxies, all over the world. The green line on the graph below is the propagation time before (with Kuma) vs our new network stack in yellow.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1cevt7xcgsr5c921unv.png" alt="Graph Faster Deployments" width="800" height="232"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bandwidth and latency&lt;/strong&gt;: Bandwidth and latency are critical for network-intensive apps like distributed databases and real-time applications. Kuma, like most service meshes, uses a sidecar model, which functionally adds latency to all requests flowing in and out of Koyeb instances. As &lt;a href="https://www.koyeb.com/blog/volumes-technical-preview-blazing-fast-nvme-ssd-for-your-data" rel="noopener noreferrer"&gt;data volumes&lt;/a&gt; are coming to the platform, you'll be able to deploy distributed databases where high-throughput networking matters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ensure we can continue delivering the best possible experience, we decided to rethink our approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjxfr3gfhnsgfuao7ixv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjxfr3gfhnsgfuao7ixv.png" alt="New stack" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Long story short, we decided to drop Kuma and Envoy for networking and opt for a &lt;strong&gt;custom solution&lt;/strong&gt; that is conceptually simpler and incredibly fast. By adopting Cilium and leveraging eBPF + Wireguard, network processing is now directly done in the Linux kernel with full encryption, eliminating the overhead associated with sidecar proxies. Load-balancing is still performed by Envoy proxies that are directly controlled by our control plane.&lt;/p&gt;

&lt;p&gt;Curious to hear more? Stay tuned for our dedicated engineering blog post!&lt;/p&gt;

&lt;h2&gt;
  
  
  Changes and How to Use the New Networking Stack
&lt;/h2&gt;

&lt;p&gt;What do you need to use the new stack? The answer is simple: nothing!&lt;br&gt;
You don't need to take any action—your applications will benefit from the performance improvements automatically.&lt;/p&gt;

&lt;p&gt;San Francisco, Washington D.C., Paris, Frankfurt, Singapore, and Tokyo - Our new networking stack is available in all Koyeb &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;regions&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqq3azkrnhud573u5zuk0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqq3azkrnhud573u5zuk0.png" alt="Koyeb Regions" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Technically, you'll see that instances can now be directly accessed inside of the private network as there is no sidecard anymore, making it easier to build clusters.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next
&lt;/h2&gt;

&lt;p&gt;This is just the beginning. Our &lt;a href="https://community.koyeb.com/t/rolling-out-our-new-networking-stack-for-3x-faster-deployments/2156" rel="noopener noreferrer"&gt;new networking stack&lt;/a&gt; lays the foundation for future improvements and innovations that will allow us to continue pushing the boundaries of what’s possible for cloud-native applications.&lt;/p&gt;

&lt;p&gt;Stay tuned as we roll out even more exciting updates during Launch Week!&lt;/p&gt;

</description>
      <category>networking</category>
      <category>cloud</category>
      <category>serverless</category>
      <category>programming</category>
    </item>
    <item>
      <title>New Dashboard: Build, Run, and Scale Apps in Minutes with a Simple and Elegant Interface</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Mon, 16 Sep 2024 15:41:00 +0000</pubDate>
      <link>https://dev.to/koyeb/new-dashboard-build-run-and-scale-apps-in-minutes-with-a-simple-and-elegant-interface-4pjd</link>
      <guid>https://dev.to/koyeb/new-dashboard-build-run-and-scale-apps-in-minutes-with-a-simple-and-elegant-interface-4pjd</guid>
      <description>&lt;p&gt;Welcome to the first day of &lt;a href="https://www.koyeb.com/blog/koyeb-launch-week-round-2" rel="noopener noreferrer"&gt;launch week #2&lt;/a&gt;! Today, we are excited to introduce our brand new &lt;a href="https://app.koyeb.com/auth/signup" rel="noopener noreferrer"&gt;control panel&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Our mission at &lt;a href="https://www.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb&lt;/a&gt; is to offer the fastest way to deploy applications globally while delivering an exceptional developer experience. Over the past few months, we totally reimagined how to deliver a simple, reactive, and intuitive experience to deploy, manage, and scale projects to production.&lt;/p&gt;

&lt;p&gt;Behind the scenes, the Koyeb web interface acts as a powerful control panel that lets you provision an end-to-end production environment for your workloads with &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;continuous deployment&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/autoscaling" rel="noopener noreferrer"&gt;autoscaling&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/metrics" rel="noopener noreferrer"&gt;metrics&lt;/a&gt;, advanced networking whether on CPU or GPU.&lt;/p&gt;

&lt;p&gt;Perhaps you’ve already noticed the changes during the last months as we’ve been adding the final touches.&lt;br&gt;
So far, the initial feedback we’ve received about the new experience has been extremely positive, people love it!&lt;/p&gt;

&lt;p&gt;So what’s new? The long and short: Our new control panel simplifies serverless deployments, provides an organized overview page to efficiently visualize and manage your Koyeb resources, and offers a simplified navigation experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Revamped deployment experience&lt;/li&gt;
&lt;li&gt;New Service overview page for a summary of your Services&lt;/li&gt;
&lt;li&gt;Overview page: Efficiently visualize and manage Koyeb resources&lt;/li&gt;
&lt;li&gt;Enhanced navigation experience&lt;/li&gt;
&lt;li&gt;First deployments: An easier way to get started&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Revamped deployment experience
&lt;/h2&gt;

&lt;p&gt;The new deployment experience in the control panel is a simple click operation. Simply select the type of &lt;a href="https://www.koyeb.com/docs/reference/services" rel="noopener noreferrer"&gt;service&lt;/a&gt; you want to deploy — service, private service, worker or &lt;a href="https://www.koyeb.com/docs/databases" rel="noopener noreferrer"&gt;database&lt;/a&gt; — and your deployment method — via a &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-with-git" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; or any &lt;a href="https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images" rel="noopener noreferrer"&gt;container registry&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then, you can choose the &lt;a href="https://www.koyeb.com/docs/reference/instances" rel="noopener noreferrer"&gt;Instance&lt;/a&gt; resource type for your workload between our line up of GPUs, Standard CPUs, and Eco CPUs and select where in the world you want to deploy them. On the map of &lt;a href="https://www.koyeb.com/docs/reference/regions" rel="noopener noreferrer"&gt;core locations&lt;/a&gt;, we display latencies to your location.&lt;/p&gt;

&lt;p&gt;Next up is a summary of your deployment. On this page, you can configure environment variables, autoscaling policies, see deployments, and an estimated cost for your deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  View build and deployment logs in real-time for deployments
&lt;/h3&gt;

&lt;p&gt;When you’re ready to deploy, you can see the build and deployment logs. We enhanced the logs experience, so now you can see the duration and last line of the build and deployment process even when the section is collapsed. This gives you clear insight into your deployment progress.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy9so0buw4lvdosxdjs4d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy9so0buw4lvdosxdjs4d.gif" alt="Improved build and deploy logs" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  New additions to the service summary page: Build artifacts and ability to pause and delete services
&lt;/h3&gt;

&lt;p&gt;After a first deployment, the service’s setting page provides more useful actions. If you wish to redeploy with a previous build, you can opt to use the build archived from the previous deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudj7fpo52dr9xnvrsd6c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudj7fpo52dr9xnvrsd6c.gif" alt="Deploy with rebuild on service settings page" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another useful action found on the bottom of this page is the ability to pause and delete the service. Previously, these actions were tucked away in the service setting’s page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzotf9phou8muoc3xkgnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzotf9phou8muoc3xkgnw.png" alt="Useful actions on service setting's page" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New service overview page
&lt;/h2&gt;

&lt;p&gt;Navigate through your service’s deployments effortlessly with our redesigned service overview page. It offers a seamless user experience without compromising on crucial deployment details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkmfut6bsjjbcn9mna69.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkmfut6bsjjbcn9mna69.gif" alt="new-service-overview-page" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate across your deployments witout losing important context&lt;/li&gt;
&lt;li&gt;Get an overview of your deployment in one click&lt;/li&gt;
&lt;li&gt;Visualize a summary of your resources&lt;/li&gt;
&lt;li&gt;Easier identification of your Services&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Overview page: Efficiently visualize and manage Koyeb resources
&lt;/h2&gt;

&lt;p&gt;From the overview page in the dashboard, you get a high-level view of your Koyeb resources, recent activity, and easy access to creating and managing all of your resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easily view all of your Koyeb resources&lt;/li&gt;
&lt;li&gt;Visualize all key information at a quick glance: Instance health status, URL, regions, and deployment source&lt;/li&gt;
&lt;li&gt;See your Organizations &lt;a href="https://www.koyeb.com/docs/reference/organizations#view-organization-activity" rel="noopener noreferrer"&gt;recent activity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Quick access to the side navigation bar for &lt;a href="https://www.koyeb.com/docs/reference/secrets" rel="noopener noreferrer"&gt;Services&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/run-and-scale/domains" rel="noopener noreferrer"&gt;Domains&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/reference/secrets" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/reference/volumes" rel="noopener noreferrer"&gt;Volumes&lt;/a&gt;, &lt;a href="https://www.koyeb.com/docs/reference/organizations#invite-members" rel="noopener noreferrer"&gt;Teams&lt;/a&gt;, and creating new Services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dwov6ebujt3cvqqdyxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dwov6ebujt3cvqqdyxh.png" alt="New overview page" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Enhanced Navigation with New Sidebar&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Our new sidebar lets you navigate the control panel. In one-click, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Toggle between Koyeb &lt;a href="https://www.koyeb.com/docs/reference/organizations" rel="noopener noreferrer"&gt;Organizations&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Configure &lt;a href="https://www.koyeb.com/docs/run-and-scale/domains" rel="noopener noreferrer"&gt;Domains&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Manage &lt;a href="https://www.koyeb.com/docs/reference/secrets" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Manage &lt;a href="https://www.koyeb.com/docs/reference/volumes" rel="noopener noreferrer"&gt;Volumes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;See all recent activity&lt;/li&gt;
&lt;li&gt;Add team members&lt;/li&gt;
&lt;li&gt;Track costs at a glance to ensure optimal resource management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Falz0ue7cslfrahsa9f4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Falz0ue7cslfrahsa9f4z.png" alt="Highlight sidebar improvements and cost tracking capabilities" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  First deployments: An easier way to get to started
&lt;/h2&gt;

&lt;p&gt;We've enhanced the first deployment experience with a revamped build and deployment logs experience, in-app guidance for troubleshooting, and clearer representation of instance types and statuses. This makes it easier than ever to get started with your initial deployments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zv0yBhYr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://www.koyeb.com/static/images/blog/new-dashboard/improved-first-deployment-experience.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zv0yBhYr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://www.koyeb.com/static/images/blog/new-dashboard/improved-first-deployment-experience.gif" alt="Improved first deployment experience" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Instant guidance when an issue occurs
&lt;/h3&gt;

&lt;p&gt;When an issue occurs during your first deployment, we provide instant guidance to help you troubleshoot and resolve the issue. This improvement is especially helpful for new users who may encounter issues during their first deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0kvm2psarg22n2arnwaf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0kvm2psarg22n2arnwaf.gif" alt="Troubleshooting improvements" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Easily track progress with new build and deployment logs experience
&lt;/h3&gt;

&lt;p&gt;As mentioned above, the new build and deployment logs experience allows you to easily track the progress of your deployment. This is especially useful for new users who may not be familiar with the deployment process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clear representation of instances and status
&lt;/h3&gt;

&lt;p&gt;After a deployment, you can easily see the instance type and status of your deployment. This makes it easier to understand the resources you are using and the status of your deployment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4ect8vxllsi9jiyy704.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4ect8vxllsi9jiyy704.png" alt="clear representation of instances and status" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Future plans for the control panel
&lt;/h2&gt;

&lt;p&gt;We are very excited about these milestones! And yet, there are still so many things we want to add! We’re looking forward to these enhancements, like adding support for mobile versions and making continuous improvements based on your feedback.&lt;/p&gt;

&lt;p&gt;Let us know what you think of the new deployment experience in the &lt;a href="https://community.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb Community&lt;/a&gt; and on X &lt;a href="https://x.com/gokoyeb" rel="noopener noreferrer"&gt;@gokoyeb&lt;/a&gt;. While you're at it, show us what you’re building on the platform!&lt;/p&gt;

</description>
      <category>ux</category>
      <category>ui</category>
      <category>cloud</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Using ComfyUI, ComfyUI Manager, and Flux to Generate High-Quality Images</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Tue, 03 Sep 2024 10:43:00 +0000</pubDate>
      <link>https://dev.to/koyeb/using-comfyui-comfyui-manager-and-flux-to-generate-high-quality-images-bl3</link>
      <guid>https://dev.to/koyeb/using-comfyui-comfyui-manager-and-flux-to-generate-high-quality-images-bl3</guid>
      <description>&lt;p&gt;Recently, AI image creation has seen significant progress. Many new tools are available to make the creative process easier with flexible, powerful functionality. One of these tools, ComfyUI, has grown to prominence due to its versatile, ease of use, and high-quality image generation.&lt;/p&gt;

&lt;p&gt;Whether you're an artist wanting to try new things or a developer wanting to use AI for visual content, ComfyUI is a powerful tool that can help solve your image-based needs. In this guide, we'll explain what ComfyUI is, how it works, and how to set it up on a Koyeb GPU.&lt;/p&gt;

&lt;p&gt;We'll also show you how to install ComfyUI Manager to add custom modules and give a step-by-step process for making high-quality images with Flux. By the end of this guide, you'll know everything you need to get the most out of ComfyUI and create amazing visuals.&lt;/p&gt;

&lt;p&gt;You can consult the &lt;a href="https://github.com/koyeb/example-comfyui" rel="noopener noreferrer"&gt;project repository&lt;/a&gt; as work through this guide. You can deploy ComfyUI as configured in this tutorial using the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-to-koyeb-button" rel="noopener noreferrer"&gt;Deploy to Koyeb&lt;/a&gt; button below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.koyeb.com/deploy?name=example-yolo&amp;amp;type=git&amp;amp;repository=koyeb%2Fexample-yolo&amp;amp;branch=main&amp;amp;builder=dockerfile&amp;amp;instance_type=gpu-nvidia-rtx-4000-sff-ada&amp;amp;env%5B%5D=&amp;amp;ports=8501%3Bhttp%3B%2F" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.koyeb.com%2Fstatic%2Fimages%2Fdeploy%2Fbutton.svg" alt="Deploy to Koyeb"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ComfyUI?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/comfyanonymous/ComfyUI" rel="noopener noreferrer"&gt;ComfyUI&lt;/a&gt; is a powerful, easy-to-use tool for creating images with AI. Users can design workflows, adjust settings, and see results immediately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User-friendly interface:&lt;/strong&gt; ComfyUI is designed to be simple so users of all skill levels can easily navigate and use its features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modular workflow design:&lt;/strong&gt; Users can create custom workflows by connecting different components, enabling flexibility in the image creation process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time feedback:&lt;/strong&gt; ComfyUI provides instant visual feedback so users can see the effects of their adjustments and fine-tune their workflows as needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with AI models:&lt;/strong&gt; ComfyUI supports a variety of pre-trained AI models, as well as custom models, allowing users to generate images that meet their specific needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use cases
&lt;/h3&gt;

&lt;p&gt;ComfyUI is great for many different uses, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Artistic creation:&lt;/strong&gt; Artists can use ComfyUI to explore new creative ideas, make unique visuals, and try out different styles and techniques.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graphic design:&lt;/strong&gt; Graphic designers can use ComfyUI to quickly create design elements, make mockups, and streamline their work process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content creation:&lt;/strong&gt; Marketers, bloggers, and content creators can use ComfyUI to make eye-catching visuals for their content, making it more engaging and appealing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Research and development:&lt;/strong&gt; AI researchers and developers can use ComfyUI to test and visualize the performance of different models, experiment with new algorithms, and push the limits of AI-driven image generation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Basics of a ComfyUI workflow
&lt;/h2&gt;

&lt;p&gt;At its core, a ComfyUI workflow is a series of connected modules, each doing a specific job in the image creation process. You can arrange these modules in different ways to get different results, giving you the flexibility to customize your workflows to fit your needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key components of the workflow
&lt;/h3&gt;

&lt;p&gt;Let's see the example of the default ComfyUI workflow to understand better the components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpgdvz7aqrdfop3159xy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpgdvz7aqrdfop3159xy.png" alt="ComfyUI default workflow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The components of the workflow can be grouped in the following categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Input modules:&lt;/strong&gt; This is the starting point of any workflow. The input module lets you set the initial settings like image size, model choice, and input data (such as sketches, text prompts, or existing images). In the example above, for instance, the &lt;code&gt;Load Checkpoint&lt;/code&gt; and &lt;code&gt;CLIP Text Encode&lt;/code&gt; components are input modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Processing modules:&lt;/strong&gt; These parts handle various aspects of the image creation process, like applying filters, adjusting colors, refining details, and more. You can stack or arrange processing modules in parallel to create complex effects. In the example above, the &lt;code&gt;KSampler&lt;/code&gt; component is a processing module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output module:&lt;/strong&gt; These are the final stages of the workflow, where the generated image is created and saved. You can specify the output format, resolution, and other details. In the example above, the &lt;code&gt;Save Image&lt;/code&gt; component is an output module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control modules:&lt;/strong&gt; These parts give you additional control over the workflow, allowing you to tweak settings, adjust weights, and fine-tune the process. Control modules are essential for getting the desired results and ensuring high-quality outputs. In the example above, the &lt;code&gt;Empty Latent Image&lt;/code&gt; component is a control module.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install ComfyUI on Koyeb GPUs
&lt;/h2&gt;

&lt;p&gt;If you want to use the power of cloud computing for your image generation tasks, installing ComfyUI on a Koyeb GPU is a great choice. Koyeb offers powerful GPU instances that can handle the demanding requirements of AI-driven image generation, making sure your processing is fast and efficient.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before starting the installation process, make sure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Koyeb account:&lt;/strong&gt; &lt;a href="https://app.koyeb.com/auth/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a Koyeb account if you don't already have one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create a Dockerfile
&lt;/h3&gt;

&lt;p&gt;We'll start by preparing a Dockerfile so we can make sure we have all of the dependencies installed, especially for GPU support. Create a &lt;code&gt;Dockerfile&lt;/code&gt; with the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the official Python base image
FROM python:3.12

# Clone the repository
RUN git clone https://github.com/comfyanonymous/ComfyUI.git

# Set the working directory
WORKDIR /ComfyUI

# Update pip, install GPU dependencies, and install Comfy dependencies
RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 &amp;amp;&amp;amp; pip install -r requirements.txt

# Set the entry point for the container
CMD python3 main.py --listen 0.0.0.0 --port ${PORT:-8188}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile sets up a container image for running ComfyUI. Here's what it does step-by-step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, it starts with a base Python image, specifically version 3.12.&lt;/li&gt;
&lt;li&gt;Next, it downloads the ComfyUI repository from GitHub. This repository contains all the code and resources needed to run ComfyUI.&lt;/li&gt;
&lt;li&gt;It sets the working directory to where ComfyUI was downloaded, so any subsequent commands are executed in the correct location.&lt;/li&gt;
&lt;li&gt;Next, it updates the &lt;code&gt;pip&lt;/code&gt; package manager to the latest version to ensure compatibility with new packages. Chained to this &lt;code&gt;RUN&lt;/code&gt; instruction are additional &lt;code&gt;pip&lt;/code&gt; commands that install the GPU dependencies including PyTorch, and a command that installs ComfyUI's dependencies from the included &lt;code&gt;requirements.txt&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Finally, it sets the default command to run the ComfyUI application when the container starts. This command uses &lt;strong&gt;&lt;code&gt;0.0.0.0&lt;/code&gt;&lt;/strong&gt; as the IP address, which means the application will be accessible from any network interface. It listens on the port defined by the &lt;code&gt;PORT&lt;/code&gt; environment variable, using ComfyUI's default port 8188 as a fallback if the environment variable is unset.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create the repository
&lt;/h3&gt;

&lt;p&gt;The final step is to create a &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;new repository on GitHub&lt;/a&gt; to store the project files.&lt;/p&gt;

&lt;p&gt;Once you're ready, run the following commands in your terminal to commit and push your code to the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "# ComfyUI-Flux" &amp;gt;&amp;gt; README.md
git init
git add .
git commit -m "First Commit"
git branch -M main
git remote add origin [Your GitHub repository URL]
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now have all your local code in your remote repository. Now it is time to deploy the Dockerfile.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploy to Koyeb
&lt;/h3&gt;

&lt;p&gt;In the &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb control panel&lt;/a&gt;, while on the &lt;strong&gt;Overview&lt;/strong&gt; tab, initiate the app creation and deployment process by clicking &lt;strong&gt;Create App&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On the App deployment page:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;strong&gt;GitHub&lt;/strong&gt; as your deployment method.&lt;/li&gt;
&lt;li&gt;Choose the repository where your code resides. For example, &lt;code&gt;ComfyUI-Flux&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the GPU you wish to use, for example, &lt;code&gt;RTX-4000-SFF-ADA&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Builder&lt;/strong&gt; section, choose &lt;strong&gt;Dockerfile&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Service name&lt;/strong&gt; section, choose an appropriate name.&lt;/li&gt;
&lt;li&gt;Finally, click &lt;strong&gt;Deploy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After a few minutes, your application should be available at the indicated URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ComfyUI Manager?
&lt;/h2&gt;

&lt;p&gt;While ComfyUI comes with a set of pre-built modules, its real power comes from its extensibility through custom modules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ltdrdata/ComfyUI-Manager" rel="noopener noreferrer"&gt;ComfyUI Manager&lt;/a&gt; is a plugin that lets users manage and install custom modules directly within the ComfyUI interface. It provides an easy-to-use interface for browsing available modules, installing them with a single click, and integrating them into your workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install ComfyUI Manager
&lt;/h2&gt;

&lt;p&gt;To install ComfyUI Manager, the simplest way is to modify your Dockerfile to include the necessary commands to install it.&lt;/p&gt;

&lt;p&gt;Update your &lt;code&gt;Dockerfile&lt;/code&gt; to add an additional &lt;code&gt;git clone&lt;/code&gt; command as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the official Python base image
FROM python:3.12

# Clone the repository
RUN git clone https://github.com/comfyanonymous/ComfyUI.git

# Set the working directory
WORKDIR /ComfyUI

# Update pip, install GPU dependencies, and install Comfy dependencies
RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 &amp;amp;&amp;amp; pip install -r requirements.txt

# Clone ComfyUI-Manager
RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /ComfyUI/custom_nodes/ComfyUI-Manager

# Set the entry point for the container
CMD python3 main.py --listen 0.0.0.0 --port ${PORT:-8188}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile sets up a container for running ComfyUI and installs also ComfyUI Manager. The only difference from the previous Dockerfile is that it clones the ComfyUI manager repository into ComfyUI's &lt;code&gt;custom_nodes&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Once you're done, commit the changes to your repository and push them to GitHub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m "Add ComfyUI Manager"
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Koyeb application will automatically create a new deployment based on your updated Dockerfile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using custom modules
&lt;/h2&gt;

&lt;p&gt;With ComfyUI Manager installed, you can now easily integrate custom modules into your workflows.&lt;/p&gt;

&lt;p&gt;Whether you're looking to add new processing techniques, experiment with different models, or create entirely new workflows, the possibilities are endless.&lt;/p&gt;

&lt;p&gt;We will use ComfyUI Manager to install Flux in the next section to generate high-quality images.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workflow for high-quality image generation with Flux
&lt;/h2&gt;

&lt;p&gt;One of the great features of ComfyUI is that it can work with advanced AI models like Flux, which are specifically made for creating high-quality images. In this section, we'll guide you through a detailed process for generating amazing images using ComfyUI and Flux.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Flux?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/black-forest-labs/flux" rel="noopener noreferrer"&gt;Flux&lt;/a&gt; is a powerful AI model made for creating high-quality images. It's one of the latest deep learning models that use large datasets, complex structures, and advanced algorithms to generate images that look realistic and are artistically impressive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features of Flux
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High-resolution outputs:&lt;/strong&gt; Flux is designed to produce high-resolution images, making it perfect for tasks where detail and clarity are important, like digital art, graphic design, and print media.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Artistic flexibility:&lt;/strong&gt; One of Flux's standout features is its ability to adapt to different artistic styles. Whether you want photorealism, impressionism, or a more abstract look, Flux can be adjusted to create images that match your desired style.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep learning architecture:&lt;/strong&gt; Flux uses a deep neural network architecture, which includes multiple layers of convolutional, generative, and refinement processes. This complex architecture allows it to understand and replicate intricate patterns, textures, and lighting effects in images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contextual understanding:&lt;/strong&gt; Unlike some earlier models, Flux has a strong ability to understand the context within images. This means it can accurately maintain the coherence of a scene, ensuring that elements in the image are not only visually consistent but also logically related.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Versatile input methods:&lt;/strong&gt; Flux supports various input methods, including text prompts, sketches, and even other images. This versatility allows users to guide the image generation process more effectively, providing a high degree of creative control.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Applications of Flux
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Digital art:&lt;/strong&gt; Artists use Flux to create detailed and stylistically diverse pieces of digital art. Its ability to interpret and generate different artistic styles makes it a valuable tool for creators looking to push the boundaries of digital expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Graphic design:&lt;/strong&gt; Graphic designers benefit from Flux's high-resolution outputs and its capability to generate assets that can be directly used in branding, marketing materials, and product designs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content creation:&lt;/strong&gt; For content creators, Flux offers a way to quickly generate unique visuals that can enhance blog posts, social media content, and other digital media.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI research:&lt;/strong&gt; Researchers in the field of artificial intelligence use Flux to explore new techniques in image generation, test theories in deep learning, and develop new applications for AI in the creative industries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install Flux on ComfyUI with ComfyUI Manager
&lt;/h2&gt;

&lt;p&gt;To install a Flux model/checkpoint on ComfyUI, you can use the ComfyUI Manager. Open the ComfyUI Manager by clicking &lt;strong&gt;Manager&lt;/strong&gt; in the sidebar menu.&lt;/p&gt;

&lt;p&gt;This will open the manager window:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrb57y51nya2vhfdrd70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrb57y51nya2vhfdrd70.png" alt="ComfyUI Manager main menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, click on &lt;strong&gt;Model Manager&lt;/strong&gt; and then search for "flux":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7worvwqzrwmjl8pwwzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7worvwqzrwmjl8pwwzw.png" alt="ComfyUI Manager search flux"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this example, install the "Comfy Org/FLUX.1 [schnell]" checkpoint by click the &lt;strong&gt;install&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;After a couple of minutes the download and install should complete:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8u362889j2v2x7fbkukr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8u362889j2v2x7fbkukr.png" alt="ComfyUI Manager flux install complete"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can build your workflow to generate a high-quality image. You can use our &lt;a href="https://github.com/koyeb/example-comfyui/koyeb-workflow.json" rel="noopener noreferrer"&gt;sample workflow&lt;/a&gt; as a starting point. Download the file to your local computer.&lt;/p&gt;

&lt;p&gt;To load the workflow into ComfyUI, click the &lt;strong&gt;Load&lt;/strong&gt; button in the sidebar menu and select the &lt;code&gt;koyeb-workflow.json&lt;/code&gt; file you just downloaded. Next, select the Flux checkpoint in the &lt;strong&gt;Load Checkpoint&lt;/strong&gt; node and type in your prompt in the &lt;strong&gt;CLIP Text Encode (Prompt)&lt;/strong&gt; node.&lt;/p&gt;

&lt;p&gt;When you are ready, press &lt;strong&gt;CTRL-Enter&lt;/strong&gt; to run the workflow and generate the image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68o3ss211dlrhlby8lz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68o3ss211dlrhlby8lz8.png" alt="ComfyUI run Koyeb workflow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the prompt included in the Koyeb sample workflow file followed by an example of an image generated from it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A serene twilight scene by a calm lake surrounded by tall, evergreen pine trees. The sky is painted with soft shades of pink, orange, and purple as the sun sets in the background. A small wooden dock extends into the water, with a single lantern casting a warm glow. Gentle ripples on the lake's surface reflect the vibrant colors of the sky, while a few fireflies dance around the dock. In the distance, mist rises from the water, adding a mystical quality to the peaceful, nature-filled landscape.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvexalb882tmacpbrcgap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvexalb882tmacpbrcgap.png" alt="ComfyUI generated image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;ComfyUI is a powerful and flexible tool for making images with AI. It has a user-friendly interface, lets you design your own workflows, and can work with advanced models like Flux. Whether you are an artist, designer, or researcher, ComfyUI gives you the tools you need to create amazing visuals easily.&lt;/p&gt;

&lt;p&gt;By following the steps in this guide, you learned how to set up ComfyUI on a Koyeb GPU, add custom modules with ComfyUI Manager, and create high-quality images using a detailed workflow. The possibilities are endless, and with ComfyUI, the only limit is your imagination.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using YOLO for Real-Time Object Detection with Koyeb GPUs</title>
      <dc:creator>alisdairbr</dc:creator>
      <pubDate>Wed, 31 Jul 2024 09:47:32 +0000</pubDate>
      <link>https://dev.to/koyeb/using-yolo-for-real-time-object-detection-with-koyeb-gpus-3m83</link>
      <guid>https://dev.to/koyeb/using-yolo-for-real-time-object-detection-with-koyeb-gpus-3m83</guid>
      <description>&lt;p&gt;Welcome to this comprehensive guide on implementing real-time object detection using the &lt;a href="https://arxiv.org/abs/1506.02640" rel="noopener noreferrer"&gt;YOLO (You Only Look Once)&lt;/a&gt; algorithm. This technology represents a leap forward in how we detect objects in real time, making it an invaluable tool in surveillance, robotics, and autonomous driving fields.&lt;/p&gt;

&lt;p&gt;In this guide, we will walk through the theory behind YOLO, how it works, and how to implement it in your projects for your real-time object detection. We'll also see real-world applications of YOLO in action, showcasing its power and versatility.&lt;/p&gt;

&lt;p&gt;You can consult the &lt;a href="https://github.com/koyeb/example-yolo" rel="noopener noreferrer"&gt;project repository&lt;/a&gt; as work through this guide. You can deploy the YOLO object detection application as built in this tutorial using the &lt;a href="https://www.koyeb.com/docs/build-and-deploy/deploy-to-koyeb-button" rel="noopener noreferrer"&gt;Deploy to Koyeb&lt;/a&gt; button below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.koyeb.com/deploy?name=example-yolo&amp;amp;type=git&amp;amp;repository=koyeb%2Fexample-yolo&amp;amp;branch=main&amp;amp;builder=dockerfile&amp;amp;instance_type=gpu-nvidia-rtx-4000-sff-ada&amp;amp;env%5B%5D=&amp;amp;ports=8501%3Bhttp%3B%2F" rel="noopener noreferrer"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RNXMAe6M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/deploy/button.svg" alt="Deploy to Koyeb" width="178" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding YOLO (You Only Look Once)
&lt;/h2&gt;

&lt;p&gt;YOLO, an acronym for "You Only Look Once", is an innovative approach to object detection. The primary difference between YOLO and other object detection algorithms is in the way it handles object detection.&lt;/p&gt;

&lt;p&gt;While most algorithms process an image multiple times to detect objects, YOLO uses a single pass, prompting the name "You Only Look Once".&lt;/p&gt;

&lt;p&gt;This is a simplified breakdown of how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, the entire image is divided into a grid. Each cell in the grid evaluated individually for predicting objects within its boundaries.&lt;/li&gt;
&lt;li&gt;For each grid cell, YOLO generates a number of bounding boxes. A bounding box is a rectangular box that can be computed to contain an object. Each bounding box comes with a confidence score, representing how certain YOLO is that the predicted box encloses some object.&lt;/li&gt;
&lt;li&gt;Along with the bounding box, YOLO also provides the class of the object that it believes exists within the box. For example, it might claim that the object is a cat, dog, car, or any other type of object it has been trained to recognize.&lt;/li&gt;
&lt;li&gt;After making all of the predictions, YOLO selects the bounding box with the highest confidence level and the associated object class as its final prediction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;YOLO's unique approach allows it to detect objects in real-time, making it a great choice for many computer vision tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before diving into building the object detection application with YOLO, it's important to ensure that you have the necessary tools and knowledge. This section outlines the prerequisites you'll need to follow the guide successfully:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;&lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb account&lt;/a&gt;&lt;/strong&gt; is required to deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Knowledge of Python programming&lt;/strong&gt; to understand the scripts we will create.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;&lt;a href="https://github.com" rel="noopener noreferrer"&gt;GitHub account&lt;/a&gt;:&lt;/strong&gt; to store the code and trigger deployments to Koyeb GPUs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;There are several implementations of the YOLO algorithm available, but for ease-of-use, we will use the &lt;a href="https://docs.ultralytics.com/" rel="noopener noreferrer"&gt;Ultralytics&lt;/a&gt; implementation in this guide. We will implement and test the code locally and then deploy to Koyeb's GPUs for higher inference speed.&lt;/p&gt;

&lt;p&gt;To get started, create a project directory and then create and activate a new virtual environment within:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir example-yolo
cd example-yolo
python -m venv venv
source venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the virtual environment and project directory are set up, make sure you have the necessary libraries and a version of YOLO installed. Visit &lt;a href="https://pytorch.org/get-started/locally/" rel="noopener noreferrer"&gt;PyTorch's getting started page&lt;/a&gt; to find the appropriate commands for your operating system. For this guide, we will use the Stable build, the Pip package manager, the Python language, and CUDA 12.1 as the compute platform. The commands to run will depend on your local operating system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Linux
pip install torch torchvision torchaudio

# Windows
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, install the &lt;a href="https://github.com/ultralytics/ultralytics" rel="noopener noreferrer"&gt;Ultralytics YOLO library&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install ultralytics opencv-python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition to installing the YOLO implementation from Ultralytics, this also installs &lt;a href="https://opencv.org/" rel="noopener noreferrer"&gt;OpenCV&lt;/a&gt; for image processing.&lt;/p&gt;

&lt;p&gt;We will be using &lt;a href="https://streamlit.io/" rel="noopener noreferrer"&gt;Streamlit&lt;/a&gt; to build the application UI. In order to support non-local access to the webcam (when deployed to the Koyeb cloud, for instance), you will also need to install a few additional libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install streamlit streamlit-webrtc pyarrow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You now have all the necessary dependencies installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing YOLO for Real-Time Object Detection
&lt;/h2&gt;

&lt;p&gt;Let's now create a simple Streamlit application that shows the YOLO ease of use for object detection, you can create a file called &lt;code&gt;web.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from streamlit_webrtc import webrtc_streamer, WebRtcMode
from ultralytics import YOLO
import av

# Load the YOLOv8 model for Object Detection
model = YOLO("yolov8n.pt")

# Function to process each frame of the video stream
def process_frame(frame):
    # Read image from the frame with PyAV
    img = frame.to_ndarray(format="bgr24")

    # Run YOLOv8 tracking on the frame, persisting tracks between frames
    results = model.track(img, tracker="bytetrack.yaml")

    # Visualize the results on the frame
    annotated_frame = results[0].plot()

    # Return the annotated frame
    return av.VideoFrame.from_ndarray(annotated_frame, format="bgr24")

# Create a WebRTC video streamer with the process_frame callback
webrtc_streamer(key="streamer", video_frame_callback=process_frame, sendback_audio=False,
                media_stream_constraints={"video": True, "audio": False},
                async_processing=True,
                mode=WebRtcMode.SENDRECV,
                rtc_configuration={
                    "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
                }
               )

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a breakdown of the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import the necessary libraries:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;streamlit_webrtc&lt;/code&gt; is used for real-time video streaming&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ultralytics&lt;/code&gt; is used for loading the YOLOv8 model&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;av&lt;/code&gt; is used for handling video frames&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Load the YOLOv8 model with the &lt;code&gt;yolov8n.pt&lt;/code&gt; weights. We will use this model to detect objects in the video frames.&lt;/li&gt;

&lt;li&gt;Define the &lt;code&gt;process_frame&lt;/code&gt; function. This function takes a video frame as input. It converts the frame to an image using &lt;a href="https://github.com/PyAV-Org/PyAV" rel="noopener noreferrer"&gt;PyAV&lt;/a&gt;, and then applies the YOLOv8 model to detect objects in the image. The model uses the ByteTrack tracker to keep track of objects between frames. The detection results are then visualized on the frame, and the annotated frame is returned.&lt;/li&gt;

&lt;li&gt;Call the &lt;code&gt;webrtc_streamer&lt;/code&gt; function to create a WebRTC video streamer. We pass the &lt;code&gt;process_frame&lt;/code&gt; function as the &lt;code&gt;video_frame_callback&lt;/code&gt; argument so that it will be called for each frame of the video stream. The &lt;code&gt;media_stream_constraints&lt;/code&gt; argument is used to specify that only the video should be streamed, not audio. The &lt;code&gt;async_processing&lt;/code&gt; argument is set to &lt;code&gt;True&lt;/code&gt; to enable processing frames in parallel with the streaming. The &lt;code&gt;mode&lt;/code&gt; argument is set to &lt;code&gt;WebRtcMode.SENDRECV&lt;/code&gt;, which sets the streamer to both send and receive video. We also define also an &lt;code&gt;rtc_configuration&lt;/code&gt; so that it can use Google's free STUN servers so that it works when running in the cloud.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;You can run the application locally with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit run web.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the application launches, access it by navigating to &lt;code&gt;http://localhost:8501/&lt;/code&gt; in your browser.&lt;/p&gt;

&lt;p&gt;The YOLOv8 model has the capability to not only detect objects in a frame but also track them across frames. This is particularly useful in applications like video surveillance, autonomous vehicles, and human-computer interaction.&lt;/p&gt;

&lt;p&gt;For tracking objects, YOLOv8 provides two options: BoT-SORT and ByteTrack.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/NirAharon/BoT-SORT" rel="noopener noreferrer"&gt;BoT-SORT&lt;/a&gt; is an extension of the original SORT (Simple Online Realtime Tracker) algorithm that also considers the motion history of objects for tracking. It uses the Kalman filter to predict the future position of objects and the Hungarian algorithm for data association. To enable BoT-SORT in YOLOv8, you need to use the &lt;code&gt;botsort.yaml&lt;/code&gt; configuration file.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/ifzhang/ByteTrack" rel="noopener noreferrer"&gt;ByteTrack&lt;/a&gt; is a more recent tracking algorithm that is designed to handle occlusions and overlapping objects better. It uses a byte-level representation of objects and a motion model to predict the future position of objects. To enable ByteTrack in YOLOv8, use the &lt;code&gt;bytetrack.yaml&lt;/code&gt; configuration file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's expand the initial application and allow users to upload videos for processing in addition to real-time processing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os  # [!code ++]
import tempfile  # [!code ++]
import cv2  # [!code ++]
from streamlit_webrtc import webrtc_streamer, WebRtcMode
import streamlit as st  # [!code ++]
from ultralytics import YOLO
import av

# Load the YOLOv8 model for Object Detection
model = YOLO("yolov8n.pt")

# Function to process each frame of the video stream
def process_frame(frame):
    # Read image from the frame with PyAV
    img = frame.to_ndarray(format="bgr24")

    # Run YOLOv8 tracking on the frame, persisting tracks between frames
    results = model.track(img, tracker="bytetrack.yaml")

    # Visualize the results on the frame
    annotated_frame = results[0].plot()

    # Return the annotated frame
    return av.VideoFrame.from_ndarray(annotated_frame, format="bgr24")

# Function to process the video with OpenCV
def process_video(video_file):  # [!code ++]
    # Open the video file
    cap = cv2.VideoCapture(video_file)  # [!code ++]

    # Set the frame width and height
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)  # [!code ++]
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)  # [!code ++]

    # Loop through the video frames
    while cap.isOpened():  # [!code ++]
        # Read a frame from the video
        success, frame = cap.read()  # [!code ++]

        if success:  # [!code ++]
            # Run YOLOv8 tracking on the frame, persisting tracks between frames
            results = model.track(frame, tracker="bytetrack.yaml")  # [!code ++]

            # Visualize the results on the frame
            annotated_frame = results[0].plot()  # [!code ++]

            # Display the annotated frame
            frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)  # [!code ++]
            frame_placeholder.image(frame, channels="RGB")  # [!code ++]
        else:  # [!code ++]
            # Break the loop if the end of the video is reached
            break  # [!code ++]

    # Release the video capture object and close the display window
    cap.release()  # [!code ++]

# Create a WebRTC video streamer with the process_frame callback
webrtc_streamer(key="streamer", video_frame_callback=process_frame, sendback_audio=False,
                media_stream_constraints={"video": True, "audio": False},
                async_processing=True,
                mode=WebRtcMode.SENDRECV,
                rtc_configuration={
                    "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
                }
                )

# File upload for uploading the video file, placeholder for displaying the frames and button to start processing
file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])  # [!code ++]
button = st.button("Process Video")  # [!code ++]
frame_placeholder = st.empty()  # [!code ++]
# If the button is clicked and a file is uploaded, save the file to a temporary directory and process the video
if button:  # [!code ++]
    # Save the file to a temporary directory
    temp_dir = tempfile.mkdtemp()  # [!code ++]
    path = os.path.join(temp_dir, file.name)  # [!code ++]
    with open(path, "wb") as f:  # [!code ++]
        f.write(file.getvalue())  # [!code ++]
    # Process the video
    process_video(path)  # [!code ++]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;{/* prettier-ignore-end */}&lt;/p&gt;

&lt;p&gt;Here's a breakdown of the new code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import the new libraries:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cv2&lt;/code&gt; is for handling video files with OpenCV&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;streamlit&lt;/code&gt; is to create the web application&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Load the YOLOv8 model with the &lt;code&gt;yolov8n.pt&lt;/code&gt; weights. We will use this model to detect objects in the video frames.&lt;/li&gt;

&lt;li&gt;Define the &lt;code&gt;process_video&lt;/code&gt; function. This function takes a video file path as input and opens the video file using OpenCV. It then loops through the video frames and applies the YOLOv8 model to detect objects in each frame. It returns the frame with the detection results displayed on it.&lt;/li&gt;

&lt;li&gt;Create a Streamlit file uploader to allow the user to upload a video file. We create a Streamlit button to start the video processing. When the button is clicked and a file is uploaded, the file is saved to a temporary directory and then processed using the &lt;code&gt;process_video&lt;/code&gt; function.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World applications of YOLO object detection
&lt;/h2&gt;

&lt;p&gt;The Ultralytics YOLO &lt;a href="https://docs.ultralytics.com/tasks/detect/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; outlines several specific tasks that can be performed using the YOLO algorithm. Let's explore some of these tasks and their applications in real-world scenarios.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object Counting
&lt;/h3&gt;

&lt;p&gt;Object counting is the process of simply counting the number of instances of a specific object within an image or video. This task is particularly useful in scenarios like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;crowd management&lt;/strong&gt;: Estimating the number of people in a crowded area.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;inventory management&lt;/strong&gt;: Counting products on shelves in a retail environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wildlife monitoring&lt;/strong&gt;: Tracking the number of animals in a specific area for ecological studies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see the code changes we could make to our &lt;code&gt;web.py&lt;/code&gt; file in order to support object counting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;... updated imports ...
from ultralytics import YOLO  # [!code --]
from ultralytics import YOLO, solutions  # [!code ++]

... previous code ...

# Function to count objects in the video
def count_objects(video_file):  # [!code ++]
    # Define region points
    region_points = [(20, 150), (400, 150), (400, 350), (20, 350)]  # [!code ++]

    # Init Object Counter
    counter = solutions.ObjectCounter(  # [!code ++]
        view_img=False,  # [!code ++]
        reg_pts=region_points,  # [!code ++]
        names=model.names,  # [!code ++]
        draw_tracks=True,  # [!code ++]
        line_thickness=2,  # [!code ++]
    )  # [!code ++]

    # Open the video file
    cap = cv2.VideoCapture(video_file)  # [!code ++]

    # Loop through the video frames
    while cap.isOpened():  # [!code ++]
        # Read a frame from the video
        success, frame = cap.read()  # [!code ++]

        if success:  # [!code ++]
            # Run YOLOv8 tracking on the frame, persisting tracks between frames
            tracks = model.track(frame, persist=True, show=False)  # [!code ++]

            # Count objects in the frame
            annotated_frame = counter.start_counting(frame, tracks)  # [!code ++]

            # Display the annotated frame
            frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)  # [!code ++]
            frame_placeholder.image(frame, channels="RGB")  # [!code ++]

        else:  # [!code ++]
            # Break the loop if the end of the video is reached
            break  # [!code ++]

    # Release the video capture object
    cap.release()  # [!code ++]


# File upload for uploading the video file, placeholder for displaying the frames and button to start processing
... previous code ...
button_count = st.button("Count Objects")  # [!code ++]
frame_placeholder = st.empty()
# If the button is clicked and a file is uploaded, save the file to a temporary directory and process the video
if button:
    ... previous code ...

if button_count:  # [!code ++]
    # Save the file to a temporary directory
    temp_dir = tempfile.mkdtemp()  # [!code ++]
    path = os.path.join(temp_dir, file.name)  # [!code ++]
    with open(path, "wb") as f:  # [!code ++]
        f.write(file.getvalue())  # [!code ++]
    # Count objects in the video
    count_objects(path)  # [!code ++]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a breakdown of the new code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the &lt;code&gt;solutions&lt;/code&gt; class to the imports from &lt;code&gt;ultralytics&lt;/code&gt;. This class contains pre-made solutions from Ultralytics like &lt;code&gt;ObjectCounter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Define the &lt;code&gt;count_objects(video_file)&lt;/code&gt; function. This function takes a video file as input and processes it to count objects. Inside the function, we do the following:

&lt;ul&gt;
&lt;li&gt;Define the &lt;code&gt;region_points&lt;/code&gt; variable. This variable represents the region of interest (ROI): the coordinates of the region in the video frame where the objects are to be counted.&lt;/li&gt;
&lt;li&gt;Initialize the object counter with &lt;code&gt;solutions.ObjectCounter&lt;/code&gt;. This class is responsible for counting objects that pass through the defined region. It takes parameters such as &lt;code&gt;view_img&lt;/code&gt;, &lt;code&gt;reg_pts&lt;/code&gt;, &lt;code&gt;names&lt;/code&gt;, &lt;code&gt;draw_tracks&lt;/code&gt;, and &lt;code&gt;line_thickness&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Open the uploaded video using OpenCV's &lt;code&gt;cv2.VideoCapture(video_file)&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Loop through the video frame-by-frame until the video is finished. In each iteration, a frame is read from the video. If the frame is successfully read, YOLOv8 tracking is applied to the frame with &lt;code&gt;model.track(frame, persist=True, show=False)&lt;/code&gt;. The &lt;code&gt;counter.start_counting(frame, tracks)&lt;/code&gt; method is called to count objects in the frame and the annotated frame is then displayed.&lt;/li&gt;
&lt;li&gt;Release the video capture object with &lt;code&gt;cap.release()&lt;/code&gt; once the video is finished.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Add a "Count Objects" button and an empty placeholder for displaying the video frames to the user interface. When the button is clicked, the video file is saved to a temporary directory, and the &lt;code&gt;count_objects(path)&lt;/code&gt; function is called to process the video.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's see an example of object counting:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DJypk3IW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-counting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DJypk3IW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-counting.png" alt="YOLO object counting screenshot" width="800" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Object Cropping
&lt;/h3&gt;

&lt;p&gt;Object cropping identifies and extracts specific objects from an image or video. This task allows you to create smaller images containing only the objects of interest, which can be useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;image editing&lt;/strong&gt;: Isolating objects for graphic design purposes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;data augmentation&lt;/strong&gt;: Creating additional training data for machine learning models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;focus enhancement&lt;/strong&gt;: Highlighting objects in presentations or reports.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see the code changes we can make to to the &lt;code&gt;web.py&lt;/code&gt; file in order to support object cropping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;... added imports ...
from ultralytics.utils.plotting import Annotator, colors  # [!code ++]

... previous code ...
# Function to crop objects in the video
def crop_objects(video_file):  # [!code ++]
    # Open the video file
    cap = cv2.VideoCapture(video_file)  # [!code ++]

    with frame_placeholder.container():  # [!code ++]
        # Loop through the video frames
        while cap.isOpened():  # [!code ++]
            # Read a frame from the video
            success, frame = cap.read()  # [!code ++]

            if success:  # [!code ++]
                # Run YOLOv8 tracking on the frame
                results = model.predict(frame, show=False)  # [!code ++]

                # Retrieve the bounding boxes and class labels
                boxes = results[0].boxes.xyxy.cpu().tolist()  # [!code ++]
                clss = results[0].boxes.cls.cpu().tolist()  # [!code ++]

                # Create an Annotator object for drawing bounding boxes
                annotator = Annotator(frame, line_width=2, example=model.names)  # [!code ++]

                # If boxes are detected, crop the objects and save them to a directory
                if boxes is not None:  # [!code ++]
                    # Iterate over the detected boxes and class labels
                    for box, cls in zip(boxes, clss):  # [!code ++]
                        # Draw the bounding box on the frame
                        annotator.box_label(box, color=colors(int(cls), True), label=model.names[int(cls)])  # [!code ++]

                        # Crop the object from the frame
                        annotated_frame = frame[int(box[1]): int(box[3]), int(box[0]): int(box[2])]  # [!code ++]

                        # Display the annotated frame
                        if annotated_frame.shape[0] &amp;gt; 0 and annotated_frame.shape[1] &amp;gt; 0:  # [!code ++]
                            frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)  # [!code ++]
                            st.image(frame, channels="RGB")  # [!code ++]
            else:  # [!code ++]
                # Break the loop if the end of the video is reached
                break  # [!code ++]

    # Release the video capture object
    cap.release()  # [!code ++]


# File upload for uploading the video file, placeholder for displaying the frames and button to start processing
... previous code ...
button_crop = st.button("Crop Objects")  # [!code ++]
frame_placeholder = st.empty()
# If the button is clicked and a file is uploaded, save the file to a temporary directory and process the video
if button:
    ... previous code ...

# If the button is clicked and a file is uploaded, save the file to a temporary directory and count the objects
if button_count:
    ... previous code ...

# If the button is clicked and a file is uploaded, save the file to a temporary directory and crop the objects
if button_crop:  # [!code ++]
    # Save the file to a temporary directory
    temp_dir = tempfile.mkdtemp()  # [!code ++]
    path = os.path.join(temp_dir, file.name)  # [!code ++]
    with open(path, "wb") as f:  # [!code ++]
        f.write(file.getvalue())  # [!code ++]
    # Count objects in the video
    crop_objects(path)  # [!code ++]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a breakdown of the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import the new libraries. Import the &lt;code&gt;Annotator&lt;/code&gt; and &lt;code&gt;colors&lt;/code&gt; classes from &lt;code&gt;ultralytics.utils.plotting&lt;/code&gt;. These classes draw bounding boxes and retrieve colors for the bounding boxes, respectively.&lt;/li&gt;
&lt;li&gt;Define the &lt;code&gt;crop_objects(video_file)&lt;/code&gt; function. This function takes a video file as input and processes it to crop objects. Inside the function, we do the following:

&lt;ul&gt;
&lt;li&gt;Open the uploaded video using OpenCV's &lt;code&gt;cv2.VideoCapture(video_file)&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Loop through the video frame-by-frame until the video is finished. In each iteration, a frame is read from the video. If the frame is successfully read, YOLOv8 detection is applied to the frame with &lt;code&gt;model.predict(frame, show=False)&lt;/code&gt; and the bounding boxes and class labels are retrieved.&lt;/li&gt;
&lt;li&gt;Crop the object. If bounding boxes are detected, an &lt;code&gt;Annotator&lt;/code&gt; object is created and, for each bounding box, the object is cropped from the frame and displayed. The original frame with the bounding boxes is not displayed.&lt;/li&gt;
&lt;li&gt;Release the video capture object with &lt;code&gt;cap.release()&lt;/code&gt; once the video is finished.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Add a "Crop Objects" button and an empty placeholder for displaying the video frames to the user interface. When the button is clicked, the video file is saved to a temporary directory, and the &lt;code&gt;crop_objects(path)&lt;/code&gt; function is called to process the video.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's see an example of object cropping:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JBYRVNcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-cropping.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JBYRVNcI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-cropping.png" alt="YOLO object cropping screenshot" width="800" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Object Blurring
&lt;/h3&gt;

&lt;p&gt;Object blurring detects and blurs specific objects within an image or video. This task is essential for maintaining privacy and confidentiality in various applications, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;privacy protection&lt;/strong&gt;: Blurring faces or license plates in surveillance footage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hiding sensitive information&lt;/strong&gt;: Concealing confidential information in documents or presentations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;anonymization&lt;/strong&gt;: Ensuring individuals' identities are not revealed in public datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see the code changes we need to make to our &lt;code&gt;web.py&lt;/code&gt; file in order to support object blurring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;... previous code ...

# Function to blur objects in the video
def blur_objects(video_file):  # [!code ++]
    # Blur ratio
    blur_ratio = 50  # [!code ++]

    # Open the video file
    cap = cv2.VideoCapture(video_file)  # [!code ++]

    # Loop through the video frames
    while cap.isOpened():  # [!code ++]
        # Read a frame from the video
        success, frame = cap.read()  # [!code ++]

        if success:  # [!code ++]
            # Run YOLOv8 tracking on the frame
            results = model.predict(frame, show=False)  # [!code ++]

            # Retrieve the bounding boxes and class labels
            boxes = results[0].boxes.xyxy.cpu().tolist()  # [!code ++]
            clss = results[0].boxes.cls.cpu().tolist()  # [!code ++]

            # Create an Annotator object for drawing bounding boxes
            annotator = Annotator(frame, line_width=2, example=model.names)  # [!code ++]

            if boxes is not None:  # [!code ++]
                for box, cls in zip(boxes, clss):  # [!code ++]
                    annotator.box_label(box, color=colors(int(cls), True), label=model.names[int(cls)])  # [!code ++]

                    obj = frame[int(box[1]): int(box[3]), int(box[0]): int(box[2])]  # [!code ++]
                    blur_obj = cv2.blur(obj, (blur_ratio, blur_ratio))  # [!code ++]

                    frame[int(box[1]): int(box[3]), int(box[0]): int(box[2])] = blur_obj  # [!code ++]

                    # Display the annotated frame
                    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)  # [!code ++]
                    frame_placeholder.image(frame, channels="RGB")  # [!code ++]
        else:  # [!code ++]
            # Break the loop if the end of the video is reached
            break  # [!code ++]

    # Release the video capture object
    cap.release()  # [!code ++]

# File upload for uploading the video file, placeholder for displaying the frames and button to start processing
... previous code ...
button_blur = st.button("Blur Objects")  # [!code ++]
frame_placeholder = st.empty()
# If the button is clicked and a file is uploaded, save the file to a temporary directory and process the video
if button:
    ... previous code ...

# If the button is clicked and a file is uploaded, save the file to a temporary directory and count the objects
if button_count:
    ... previous code ...

# If the button is clicked and a file is uploaded, save the file to a temporary directory and crop the objects
if button_crop:
    ... previous code ..

# If the button is clicked and a file is uploaded, save the file to a temporary directory and blur the objects
if button_blur:  # [!code ++]
    # Save the file to a temporary directory
    temp_dir = tempfile.mkdtemp()  # [!code ++]
    path = os.path.join(temp_dir, file.name)  # [!code ++]
    with open(path, "wb") as f:  # [!code ++]
        f.write(file.getvalue())  # [!code ++]
    # Count objects in the video
    blur_objects(path)  # [!code ++]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a breakdown of the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define the &lt;code&gt;blur_objects(video_file)&lt;/code&gt; function. This function takes a video file as input and processes it to blur objects. Inside the function, we do the following:

&lt;ul&gt;
&lt;li&gt;Define the &lt;code&gt;blur_ratio&lt;/code&gt; variable. This variable represents the intensity of the blur effect.&lt;/li&gt;
&lt;li&gt;Open the uploaded video using OpenCV's &lt;code&gt;cv2.VideoCapture(video_file)&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Loop through the video frame-by-frame until the video is finished. In each iteration, a frame is read from the video. If the frame is successfully read, YOLOv8 detection is applied to the frame with &lt;code&gt;model.predict(frame, show=False)&lt;/code&gt; and the bounding boxes and class labels are retrieved.&lt;/li&gt;
&lt;li&gt;Blur the object. If bounding boxes are detected, an &lt;code&gt;Annotator&lt;/code&gt; object is created and, for each bounding box, the object is cropped from the frame, blurred using OpenCV's &lt;code&gt;cv2.blur()&lt;/code&gt; function, and then placed back in the original frame. The annotated frame with the blurred objects is then displayed.&lt;/li&gt;
&lt;li&gt;Release the video capture object with &lt;code&gt;cap.release()&lt;/code&gt; once the video is finished.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Add a "Blur Objects" button and an empty placeholder for displaying the frames with blurred objects. When the button is clicked, the video file is saved to a temporary directory, and the &lt;code&gt;blur_objects(path)&lt;/code&gt; function is called to process the video.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's see an example of object blurring:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2FtbYt1j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-blurring.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2FtbYt1j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.koyeb.com/static/images/tutorials/yolo-object-detection/object-blurring.png" alt="YOLO object blurring screenshot" width="800" height="801"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy to Koyeb's GPUs
&lt;/h2&gt;

&lt;p&gt;Now that we have the application running locally, it is time to make use of Koyeb's high-performance GPUs to increase the inference processing speed.&lt;/p&gt;

&lt;p&gt;Before we do that, we need to create a Dockerfile to install and configure the necessary code and dependencies.&lt;/p&gt;

&lt;p&gt;First, create a &lt;code&gt;requirements.txt&lt;/code&gt; file with versions of the packages we installed earlier that will work in the cloud:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;opencv-python-headless
streamlit
streamlit-webrtc
pyarrow
torch
torchvision
torchaudio
matplotlib
numpy&amp;lt;2.0.0
pyyaml
scipy
seaborn
tqdm
ultralytics-thop
psutil
py-cpuinfo
contourpy
cycler
fonttools
kiwisolver
pyparsing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This list includes all of the project's requirements, including the dependencies of the &lt;code&gt;ultralytics&lt;/code&gt; package. However, you may notice that we do &lt;em&gt;not&lt;/em&gt; list &lt;code&gt;ultralytics&lt;/code&gt; itself. That's because the &lt;code&gt;ultralytics&lt;/code&gt; package depends explicitly on &lt;code&gt;opencv-python&lt;/code&gt;, which won't work in a headless environment like Koyeb.&lt;/p&gt;

&lt;p&gt;Instead, we install &lt;code&gt;opencv-python-headless&lt;/code&gt; as a workable substitute along with all of the package's other dependencies. Afterwards, in the Dockerfile, we will install &lt;code&gt;ultralytics&lt;/code&gt; separately with the &lt;code&gt;--no-deps&lt;/code&gt; flag. In this way we can install all of the package's dependencies ahead of time, substituting &lt;code&gt;opencv-python-headless&lt;/code&gt; for &lt;code&gt;opencv-python&lt;/code&gt;, to avoid conflicts with &lt;code&gt;ultralytics&lt;/code&gt; stated dependencies.&lt;/p&gt;

&lt;p&gt;Next, create a new Dockerfile in your project directory with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the official Python base image
FROM python:3.12

# Copy the requirements file
COPY requirements.txt .

# Install the dependencies
RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install -r requirements.txt
RUN pip install --no-deps ultralytics

# Copy the rest of the application code
COPY web.py .

# Expose port 8501
EXPOSE 8501

# Set the entry point for the container
CMD ["streamlit", "run", "web.py"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's examine the Dockerfile in detail:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;FROM python:3.12&lt;/code&gt;: This line specifies the base image for the Docker image. In this case, it's the official Python 3.12 image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;COPY requirements.txt .&lt;/code&gt;: This line copies the &lt;code&gt;requirements.txt&lt;/code&gt; file from the local machine to the current working directory of the Docker image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RUN pip install --upgrade pip &amp;amp;&amp;amp; pip install -r requirements.txt&lt;/code&gt;: This line upgrades pip, the Python package installer, to the latest version and then uses it to install all of the Python dependencies listed in the &lt;code&gt;requirements.txt&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RUN pip install --no-deps ultralytics&lt;/code&gt;: This line installs &lt;code&gt;ultralytics&lt;/code&gt; without dependencies to avoid installing &lt;code&gt;opencv-python&lt;/code&gt;. We can do this because the &lt;code&gt;requirements.txt&lt;/code&gt; file already manually installs all of the dependencies and provides a workable substitute for &lt;code&gt;opencv-python&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;COPY web.py .&lt;/code&gt;: This line copies the &lt;code&gt;web.py&lt;/code&gt; file from the local machine to the Docker image in the current directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;EXPOSE 8501&lt;/code&gt;: This line specifies that the Docker container will listen on port 8501.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD ["streamlit", "run", "web.py"]&lt;/code&gt;: This is the command that will be run when the Docker container starts. It starts the Streamlit app by running the &lt;code&gt;web.py&lt;/code&gt; script.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now your project is ready to deploy on GPUs from Koyeb. The final step is to &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;create a repository&lt;/a&gt; on your GitHub account.&lt;/p&gt;

&lt;p&gt;Download the standard &lt;a href="https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore" rel="noopener noreferrer"&gt;Python &lt;code&gt;.gitignore&lt;/code&gt; file&lt;/a&gt; from GitHub to exclude certain folders and files from being pushed to the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -L https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore -o .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a line to avoid committing the &lt;code&gt;yolov8n.pt&lt;/code&gt; file that the application creates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "yolov8n.pt" &amp;gt;&amp;gt; .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;create a new repository on GitHub&lt;/a&gt; and run the following commands in your terminal to commit and push your code to the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "# Yolo Real Time" &amp;gt;&amp;gt; README.md
git init
git add .
git commit -m "First Commit"
git branch -M main
git remote add origin [Your GitHub repository URL]
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of your local code should now be present in the remote repository. You can now deploy the application to Koyeb.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://app.koyeb.com/" rel="noopener noreferrer"&gt;Koyeb control panel&lt;/a&gt;, on the &lt;strong&gt;Overview&lt;/strong&gt; tab, initiate the app creation and deployment process by clicking &lt;strong&gt;Create Service&lt;/strong&gt; and then &lt;strong&gt;Create web service&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;GitHub&lt;/strong&gt; as the deployment source.&lt;/li&gt;
&lt;li&gt;Choose the repository where your code resides. For example, &lt;code&gt;YoloRealTime&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;GPU&lt;/strong&gt; Instances and choose your Instance type, for example &lt;code&gt;RTX-4000-SFF-ADA&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Builder&lt;/strong&gt; section, select &lt;strong&gt;Dockerfile&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Exposed ports&lt;/strong&gt; section, change the port to &lt;code&gt;8501&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Give the Service your preferred name.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Deploy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;During the deployment process, it may take a few minutes to build the Docker image from the Dockerfile and upload it to Koyeb's container registry. After deployment, you can access the Streamlit application using your Koyeb application's public URL. Please note that when running in the cloud, the video image from a webcam might take several of seconds to start streaming since it needs to connect with the STUN servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this guide, we learned about real-time object detection using the YOLO (You Only Look Once) algorithm. We started by discussing areas where real-time detection is important, such as in surveillance, robotics, and self-driving cars and why its ability to process images in a single pass makes it a good tool for real-time applications.&lt;/p&gt;

&lt;p&gt;Afterwards, we took a look at &lt;em&gt;how&lt;/em&gt; YOLO works by explaining its grid-based prediction system and how it manages to predict bounding boxes and class probabilities at the same time. Throughout the guide we explored advanced tasks YOLO excels at like object counting, cropping, blurring, segmentation, tracking, and action recognition. These tasks show how versatile and powerful YOLO is in handling complex real-world situations.&lt;/p&gt;

&lt;p&gt;Finally, we gave practical advice on how to use Docker to deploy YOLO, making it easy to run YOLO applications in a consistent and reproducible environment. We used this to deploy and run the application on high-performance GPUS on Koyeb. As YOLO and real-time object detection continue to improve, they will become even more useful and have more applications. The ability to capitalize on these advancements with by executing on high-performance hardware may lead to exciting breakthroughs in many industries.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>ai</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
