<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Jarvislabs.ai - Medium]]></title>
        <description><![CDATA[Accelerating AI adoption - Medium]]></description>
        <link>https://medium.com/jarvislabs-ai?source=rss----f67efe9184c9---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Jarvislabs.ai - Medium</title>
            <link>https://medium.com/jarvislabs-ai?source=rss----f67efe9184c9---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:14:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/jarvislabs-ai" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Langchain: A Practical Guide to Implementing a Chat App with your documentation]]></title>
            <link>https://medium.com/jarvislabs-ai/langchain-a-practical-guide-to-implementing-a-chat-app-with-your-documentation-b82a3a66a497?source=rss----f67efe9184c9---4</link>
            <guid isPermaLink="false">https://medium.com/p/b82a3a66a497</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Vishnu Subramanian]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 15:32:59 GMT</pubDate>
            <atom:updated>2023-06-20T05:58:05.949Z</atom:updated>
            <content:encoded><![CDATA[<p>The last few months have been crazy in the world of AI.</p><p>Applications like OpenAI ChatGPT, Google Bard, and Github Copilot are becoming integral parts of our day-to-day lives. These tools are powerful to answer many questions, but they fail to offer the right answers on topics they were not usually trained on. Let&#39;s look at a few examples</p><ol><li>They cannot answer questions based on recent knowledge.</li><li>Ability to answer questions based on private data like company documentation, and code.</li><li>If you want to know about a company&#39;s latest financials.</li></ol><p>In this blog let&#39;s build a simple chat application that can take a given documentation and answers question based on that. We will use tools like LangChain, OpenAI, and ChromaDB to do this.</p><p>You can find the notebook <a href="https://github.com/jarvislabsai/notebooks/blob/main/Langchain_fastai_docs.ipynb">here</a>.</p><h3>Finetuning vs Prompting</h3><p>There are 2 ways in which we can use custom data with LLMs.</p><p>The traditional approach is fintuning the LLM model which could be complex and expensive based on the use case.</p><p>Prompting has become popular in recent years which let us trick the LLM model to do tasks like classification or inject new knowledge into it.</p><p>Let&#39;s say we want to classify a movie review using LLM which was not trained for classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nu835E9vJ80QxfdI5wdkSQ.png" /></figure><p>Let&#39;s also check what happens when we ask questions based on recent events like, you want to understand who is the protagonist in the movie Extraction 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhO4JezxASOKrn6ok-4AnQ.png" /></figure><p>As expected the AI/LLM will not be able to answer it. What if we give some context so that it can use that? So I instructed it to answer based on the knowledge I shared. A description from the IMDB website about the movie.</p><p>The LLM model can answer the question based on the new knowledge without ever training/fine-tuning on updated data.</p><h3>Limitations of the above approach</h3><p>In the above example, we passed on the additional knowledge manually. Let&#39;s look at how we can automate the process of</p><ol><li>Searching for relevant information, like getting the piece from Imdb.</li><li>Adding the relevant information to the prompt, like the description of the movie</li></ol><p>To do this, let&#39;s build a simple app that allows us to chat with the latest FastAPI docs.</p><blockquote><strong>FastAPI</strong> is a modern, fast (high-performance), web framework for building APIs</blockquote><p>The high-level steps of building our app will look like</p><ol><li>Data preparation</li><li>Creating a knowledge base</li><li>Use a popular LLM model to answer your questions based using the knowledge base</li></ol><p>LangChain provides a lot of helper classes to handle the above, so we will leverage them to build our small AI app.</p><h3>Data Preparation</h3><p>I took a smile approach of extracting all the useful links from <a href="https://fastapi.tiangolo.com/sitemap.xml">FastAPI</a> sitemap.xml. Then use <strong>UnstructuredURLLoader</strong> from LangChain to download and extract the text content from these URLs.</p><pre># Download sitemap.xml file from a website and extract all the links<br>def get_links(url):<br>    url = f&#39;{url}/sitemap.xml&#39;<br>    response = requests.get(url)<br>    if response.status_code == 200:<br>        soup = BeautifulSoup(response.text, &#39;lxml&#39;)<br>        links = [link.text for link in soup.find_all(&#39;loc&#39;)]<br>        return links<br>    else:<br>        print(f&#39;Error: {response.status_code}&#39;)<br>        return None<br><br># Download the contents of a webpage given its urls<br>def download_pages(urls: list[str]):<br>    data = UnstructuredURLLoader(urls=urls).load()<br>    return data  </pre><h3>Creating a Knowledge base using Chroma DB</h3><p>Once we have the data, we need to store it in some form of database, so that we can retrieve the relevant text when required. Since it is all text data, SQL databases may not be the right choice for storage.</p><p>Vector DBs like Chroma DB and Pinecone are built exclusively for this. Let&#39;s understand at a high level what it does.</p><ol><li>Convert all the text to smaller portions called chunks.</li><li>Convert these chunks to numerical representations called embeddings.</li><li>Given a search query, it will return the <strong>N(3)</strong> relevant pieces of text.</li></ol><pre># Index and Store data to Chroma<br>text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=20)<br>split_docs = text_splitter.split_documents(docs)<br>embeddings = OpenAIEmbeddings()<br>db = Chroma.from_documents(collection_name=&#39;webdata&#39;,<br>                           documents=split_docs,<br>                           embedding=embeddings,persist_directory=&#39;index_data&#39;)<br>db.persist()<br><br># Load the stored embeddings<br>db = Chroma(collection_name=&#39;webdata&#39;,<br>            embedding_function=embeddings,<br>            persist_directory=&#39;index_data/&#39;)<br>query = &quot;What is async code?&quot;<br><br># Fetch similar docs<br>docs = db.similarity_search(query,k=3)</pre><h3>LLMs answer using the knowledge base</h3><p>We have prepared our knowledge base, based on the fastapi docs. We can pass any question to an LLM model, query the index from Chroma DB to add relevant docs to the prompt, and answer them using the below simple code.</p><pre>llm = ChatOpenAI(model_name=&#39;gpt-3.5-turbo&#39;,temperature=0.0)<br>qa = RetrievalQA.from_chain_type(llm=llm, <br>                                 retriever=db.as_retriever(),<br>                                 chain_type=&#39;stuff&#39;)<br>qa.run(&#39;How is async used in fastai&#39;)</pre><blockquote>You can replace FastAPI docs with your own docs.</blockquote><h3>Things we can try:</h3><ol><li>How to use tools like Gradio or Streamlit to build a simple chat application, and connect to our app.</li><li>Let&#39;s explore how to use open-source LLMs on your GPUs. It helps in handling confidential data, that you do not want to share with OpenAI or a third-party provider.</li></ol><h3>Useful resources:</h3><p>Langchain is still new, the tool and its documentation are evolving fast. So the best place to check is their <a href="https://docs.langchain.com/docs/">docs</a>.</p><p>I also found this <a href="https://www.pinecone.io/learn/langchain-intro/">book</a> very useful to get an introduction to LangChain and several of its key concepts.</p><h4><strong>Hope you find the blog useful.</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b82a3a66a497" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jarvislabs-ai/langchain-a-practical-guide-to-implementing-a-chat-app-with-your-documentation-b82a3a66a497">Langchain: A Practical Guide to Implementing a Chat App with your documentation</a> was originally published in <a href="https://medium.com/jarvislabs-ai">Jarvislabs.ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invoke AI on Jarvislabs: Generate Beautiful Images Effortlessly in seconds.]]></title>
            <link>https://medium.com/jarvislabs-ai/invoke-ai-on-jarvislabs-generate-beautiful-images-effortlessly-in-seconds-45c07b4f78e?source=rss----f67efe9184c9---4</link>
            <guid isPermaLink="false">https://medium.com/p/45c07b4f78e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[art]]></category>
            <category><![CDATA[artist]]></category>
            <dc:creator><![CDATA[Vishnu Subramanian]]></dc:creator>
            <pubDate>Wed, 24 May 2023 06:36:27 GMT</pubDate>
            <atom:updated>2023-05-23T13:56:54.044Z</atom:updated>
            <content:encoded><![CDATA[<p>As an AI enthusiast, I’m always on the lookout for open-source tools that can help artists and designers create captivating visuals with ease. Invoke AI, an image generation tool powered by Stable Diffusion caught my attention recently. In this post, I’ll show how you can launch this fascinating tool on <a href="https://jarvislabs.ai/">Jarvislabs.ai</a> in less than a minute and generate images using some of the popular models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TiaSK6NoQahLUuCsmVwjcA.png" /></figure><h3>Understanding Invoke AI and Stable Diffusion</h3><p>InvokeAI is a cutting-edge creative platform designed to assist both professionals and enthusiasts in producing breathtaking visual content. Harness the power of advanced AI-driven technologies to generate and craft striking visual media.</p><p>Some of the key features :</p><ol><li>Text-to-Image: Transform written text into visually captivating images.</li><li>Image-to-Image: Modify a provided initial image (sketch or photograph) by generating a new version influenced by a textual prompt.</li><li>Unified Canvas: Interactively merges multiple images, expands them through outpainting, and alters specific parts of the image using inpainting. Erase sections of a starting image and let the AI complete the erased region based on a text prompt.</li></ol><h3>Getting Started with Invoke AI on Jarvislabs Platform</h3><p>To begin generating images with Invoke AI on the Jarvislabs platform, follow these straightforward steps:</p><ol><li>Create an account on the Jarvislabs platform (<a href="https://www.jarvislabs.ai/">https://www.jarvislabs.ai/</a>). If you’re an existing user, simply log in.</li><li>Once logged in, create an instance by choosing Invoke AI in the framework list. You can also choose GPU type and storage. We recommend trying it out with A5000 or A6000 GPUs.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-xk8wrb6wX0Sv0Cdo79Ew.png" /></figure><p>3. In less than 45 seconds, you will have your instance up and running. Access the Invoke AI web console by right-clicking on your running instance and choosing the API endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5QZn4DUpRCx74IJJ7FlhQ.png" /></figure><p>The web UI may take a few seconds to load. If you do not see it, please refresh the page after a few seconds.</p><h3>Advanced options</h3><p>If you want more flexibility, you can easily stop the Invoke AI server and start tweaking it. To do that, please open a <a href="https://jupyterlab.readthedocs.io/en/stable/user/terminal.html">terminal</a> from Jupyter Lab, which can be accessed by pressing the green play button on your running instance. From the terminal, you can run the below commands to access the Invoke AI server.</p><pre>tmux attach -t invoke<br><br></pre><h3>Conclusion</h3><p>Invoke AI and the Jarvislabs platform provide a robust, accessible solution for generating visually stunning images. Whether you’re a seasoned artist or simply looking to enhance your projects with captivating visuals, Invoke AI can help you achieve the perfect image quickly and effortlessly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45c07b4f78e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jarvislabs-ai/invoke-ai-on-jarvislabs-generate-beautiful-images-effortlessly-in-seconds-45c07b4f78e">Invoke AI on Jarvislabs: Generate Beautiful Images Effortlessly in seconds.</a> was originally published in <a href="https://medium.com/jarvislabs-ai">Jarvislabs.ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide for finetuning Stablediffusion with your images]]></title>
            <link>https://medium.com/jarvislabs-ai/guide-for-finetuning-stablediffusion-with-your-images-fc6856c0c2a7?source=rss----f67efe9184c9---4</link>
            <guid isPermaLink="false">https://medium.com/p/fc6856c0c2a7</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai-art]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Vishnu Subramanian]]></dc:creator>
            <pubDate>Wed, 24 May 2023 04:20:12 GMT</pubDate>
            <atom:updated>2023-01-28T06:59:59.010Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create personalized images of you, your favorite character, or your cat</h4><p>Have you dreamt of being a spiderman or iron man, I did while growing up (I want to keep it a secret that I still do😁). In the last few months, algorithms like Dall-E and Stable Diffusions have been able to generate beautiful images, and we can guide them through simple text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bYtYXJTYYKCRLnFXpJ0lQQ.png" /></figure><p>Though it generates random images, they struggle to generate images of certain persons, animals, or objects.</p><p>Let&#39;s take a look at some examples of outputs generated from SD, they get it slightly right but are not realistic for our favorite characters.</p><p>These are some of the popular Indian movie stars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GOfdrakCdoTx2PUpBHphA.png" /></figure><p>Let&#39;s use a technique called <a href="https://dreambooth.github.io/">Dreambooth</a> a technique proposed by researchers at google that let&#39;s fine-tune these large image generation models to generate images of a specific object/person.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9kPaJ_jifl2iOKRficPdw.png" /></figure><p>Let&#39;s take the example of a famous Indian actor “<a href="https://en.wikipedia.org/wiki/Mahesh_Babu">Mahesh Babu</a>” and walk through how to fine-tune the SD model and generate images like these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sk34uR8VW16RhACUCaWq-g.jpeg" /><figcaption>Photos generated by SD and Automatic 1111 on Jarvislabs</figcaption></figure><h3>Quick steps to finetune SD</h3><ul><li>Setup the env and code required</li><li>Get images of your favorite character/object</li><li>Train the model, and understand key hyperparameters that may help in getting better results.</li><li>Convert the weights to a format compatible with Automatic 1111</li><li>Start generating images</li><li>Tips for prompt ideas</li></ul><h4>Setup environment</h4><p>For this post, I am using an Nvidia A6000 GPU instance from <a href="https://jarvislabs.ai/">Jarvislabs.ai</a>. It comes with <a href="https://jarvislabs.ai/docs/automatic/">Automatic 1111</a> prebuilt, making our lives easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyUc7ily23BV8e9GXb5jtg.png" /></figure><p>Note: You should be able to do most of the steps on your workstation.</p><p>Open the terminal from Jupyter Lab and run the below commands</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*Xky6GQK9bAJt6Nbfww1avg.png" /></figure><pre><br>wget https://gist.githubusercontent.com/svishnu88/f17d3b4233db69dfc119f77942104a91/raw/fd16254e5e78fe69c22ca06314c2c980c9c5cb61/setup_db_env.sh<br>bash setup_db_env.sh</pre><p>The script will take a few minutes to run. While it is getting executed, let&#39;s try to understand what the script does. It is completely optional to understand it 😊.</p><pre>#Create a python environment<br>python3 -m venv env_dream<br><br>#Activate the environment<br>source env_dream/bin/activate<br><br># Install libraries required to train StableDiffusion model<br>pip install ipykernel ipywidgets<br>python -m ipykernel install --user --name=dreambooth<br><br>#Clone the diffusers library and install the required libraries<br>git clone https://github.com/huggingface/diffusers.git<br>cd /home/diffusers/<br>pip install -e .<br>cd /home/diffusers/examples/dreambooth/<br>pip install -r requirements.txt<br>pip install datasets</pre><p>We create a separate python env, in which we install all the required libraries. If running the script does not throw any error, then we are good to train the model.</p><h4>Get Images of your favorite character</h4><p>We need to be careful while we pick the images we are using to train the model. Some of the tips to pick your input images.</p><ul><li>Pick a few close-up photos</li><li>Few photos with different sides of the face and body</li><li>Avoid objects or other people in the background.</li><li>Choose different locations.</li><li>Avoid photos with heavy makeup/ornaments.</li></ul><p>I took 9 images for this post, all from the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jA5vf1H602MubvqLhGvecw.jpeg" /></figure><p>Create a folder called input_imgs under the home directory and upload all your input images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1mPHNjFerRjl5zop4Ggjw.jpeg" /></figure><h4>Train Model</h4><p>From a terminal, you can run the below commands to start the model training. It could take close to 15+ minutes when you run the first time.</p><p>It would be faster the second time as it will skip some of the steps like downloading model weights and creating class images.</p><pre>source env_dream/bin/activate<br>wget https://gist.githubusercontent.com/svishnu88/9adbd8ccdfd679a991d7696ef753a175/raw/17990e718487910cd08df3ace48bb231b7d82587/train_dreambooth.sh<br>bash train_dreambooth.sh</pre><p>Let&#39;s look at what is happening inside the script so that you can tweak it for your needs.</p><pre>export MODEL_NAME=&quot;runwayml/stable-diffusion-v1-5&quot;<br>export CLASS_DIR=&quot;class_images&quot;<br>export INSTANCE_DIR=&quot;input_imgs&quot;<br>export OUTPUT_DIR=&quot;output&quot;<br><br>accelerate launch diffusers/examples/dreambooth/train_dreambooth.py \<br>  --pretrained_model_name_or_path=$MODEL_NAME  \<br>  --instance_data_dir=$INSTANCE_DIR \<br>  --class_data_dir=$CLASS_DIR \<br>  --output_dir=$OUTPUT_DIR \<br>  --with_prior_preservation --prior_loss_weight=1.0 \<br>  --instance_prompt=&quot;a photo of sks person&quot; \<br>  --class_prompt=&quot;Photo of Tom cruise&quot; \<br>  --resolution=512 \<br>  --train_batch_size=1 \<br>  --train_text_encoder \<br>  --gradient_accumulation_steps=1 \<br>  --learning_rate=1e-6 \<br>  --lr_scheduler=&quot;constant&quot; \<br>  --lr_warmup_steps=0 \<br>  --num_class_images=200 \<br>  --max_train_steps=1200 \<br>  --mixed_precision=&#39;bf16&#39; \<br>  --sample_batch_size=3</pre><p>Some of the key things you may need to tweak are</p><ul><li>instance_prompt</li><li>class_prompt</li><li>max_train_steps</li><li>mixed_precision</li></ul><p><strong>Instance prompt</strong>: &lt;sks&gt; is the keyword we assign to our character. We will be using it to generate images once our model is trained. &lt;person&gt; is the class to which our character/object belongs too. If we choose photos of a dog, then we replace “person” with “dog”.</p><p><strong>Class prompt</strong>: To avoid overfitting we need to pass images of the class in our case it is the person. You can upload your images, or let SD generate images. In this case, I am asking SD to generate images of Tom Cruise. If you want to train the model on a female character, then we can choose a popular actress instead of Tom cruise.</p><p>If you are using your images, then you can create a folder called class_images and upload your relevant images.</p><p><strong>Max train steps</strong>: This number would play an important role in the quality of the images generated. You can tweak the number based on the number of input images you choose. For a higher number of images, you may need to increase it and vice versa.</p><p><strong>Mixed precision</strong>: You can use ‘bf16’ if you are using Nvidia GPUs with Ampere generation, for example, A100, A6000, and A5000 belong to these. This helps in training the models faster. If you are using older generation GPUs, then you can replace it with ‘fp16’ or remove the flag.</p><h4>Convert model weights to .ckpt and use it with Automatic 1111</h4><p>Once the model training is completed let&#39;s convert the model weights to a suitable weight and use it with Automatic 1111 a popular UI for SD.</p><pre>python diffusers/scripts/convert_diffusers_to_original_stable_diffusion.py --model_path output/ --checkpoint_path my_model.ckpt</pre><p>Once we have our custom weights let&#39;s move the weights to a place where Automatic 1111 can pick them up.</p><p>Run the below commands from a new terminal and do not activate the environment we created earlier.</p><pre>mv my_model.ckpt /home/stable-diffusion-webui/models/Stable-diffusion/<br>cd stable-diffusion-webui<br>python launch.py</pre><p>The above command could take a few minutes, once done we can access the Automatic UI in the <a href="https://jarvislabs.ai/">Jarvislabs</a> platform like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zxc7B-8rOFQui5Pa6JgPw.png" /></figure><p>Time to generate images using our custom model 😀.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGy6a8fvdl6jljOCO9py3w.png" /></figure><h4><strong>Tips to get your prompts</strong>:</h4><p>This is where I struggle. I am no artist and have very little idea about the domain of art. So I take help from another <a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion">AI application</a> that can help us in generating initial prompts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WuuG4jsYDWyxaXkcPyB2KQ.png" /></figure><h3>See you soon</h3><p>Hope you found the blog helpful, would love to see what cool things you create. Have suggestions or need help, let me know will be happy to help.</p><p>If you are running it on Jarvislabs, you can also talk to the team using the chat window. We will love to help you. Happy New Year.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc6856c0c2a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jarvislabs-ai/guide-for-finetuning-stablediffusion-with-your-images-fc6856c0c2a7">Guide for finetuning Stablediffusion with your images</a> was originally published in <a href="https://medium.com/jarvislabs-ai">Jarvislabs.ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stable Diffusion with Automatic 1111 on Jarvislabs]]></title>
            <link>https://medium.com/jarvislabs-ai/stable-diffusion-with-automatic-1111-on-jarvislabs-1cd281eb57f9?source=rss----f67efe9184c9---4</link>
            <guid isPermaLink="false">https://medium.com/p/1cd281eb57f9</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[generative-art]]></category>
            <category><![CDATA[stable-diffusion]]></category>
            <dc:creator><![CDATA[Vishnu Subramanian]]></dc:creator>
            <pubDate>Wed, 24 May 2023 04:20:03 GMT</pubDate>
            <atom:updated>2023-04-03T01:31:06.319Z</atom:updated>
            <content:encoded><![CDATA[<p>Generating images with Stable diffusion(SD) has gotten super easy over the last few months. <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">Automatic 1111</a> is a popular open-source UI tool built to help enthusiasts and artists play around with SD and apply many advanced features.</p><p>In this blog post, we will delve into, how you can use Automatic1111 a powerful platform on <a href="https://jarvislabs.ai/">Jarvislabs.ai</a> in a few clicks and transform your creative process. Create stunning visuals with ease, with 10+ preloaded models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nWio5xSrKnfWSCLs.png" /></figure><h3>What is AUTOMATIC1111 — Stablediffusion UI?</h3><p>Automatic 1111 provides an open-source UI dashboard built on top of <a href="https://gradio.app/">Gradio</a>. With more than 350 active contributors, it brings in some of the latest advancements in Generative AI space to its users.</p><p>Key features of Automatic 1111:</p><ul><li>txt2img and img2img modes</li><li>Inpainting and Outpainting</li><li>Textual Inversion</li><li>CLIP interrogator, a button that tries to guess a prompt from an image</li></ul><p>There is a ton of features available and they are growing. Check <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features">here</a> for features with examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/0*51S4fVKm8cRTyzL4.png" /></figure><h3>Setting up AUTOMATIC1111 on JarvisLabs.ai</h3><p>Getting started with AUTOMATIC1111 is a breeze. Get started in less than 60+ seconds ⏰. It comes with 10+ preloaded models.</p><p>Launch an instance, choose</p><ul><li>Choose Automatic 1111 as a framework</li><li>GPU Typ — (Recommended A5000, A6000)</li><li>Storage — (You can increase or decrease it anytime)</li><li>Number of GPUs — (1 GPU should be ideal for most of the cases)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*33yDOR2clcFwhaIS.png" /></figure><p>Easily access the AUTOMATIC1111 application by right-clicking on the instance and selecting the API endpoint for a smooth creative experience on JarvisLabs.ai.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tx5ecTkMFNnWNfX2.png" /></figure><p>Note: The UI may need a few seconds to load, please refresh the UI if you don’t get the UI.</p><p>Keep an 👀 on the <a href="https://jarvislabs.ai/docs/automatic/">docs</a> for updated information.</p><h3>Exploring with 10+ Preloaded Models</h3><p>The first step in using Automatic 1111 is to choose the right model and place it in the right location. We have done the hard work of picking some of the most popular models and have placed them in the Automatic 1111 models directory. So you can focus on Image generation.</p><p>You can choose from one of the popular models and start generating images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc7c43a6da2bcd1734ba02d80851b7a6/href">https://medium.com/media/fc7c43a6da2bcd1734ba02d80851b7a6/href</a></iframe><h3>Download model weights and config</h3><p>It is super simple to add any new models or custom pretrained models. You can follow these simple steps.</p><ul><li>Once your instance is launched, clicking the play button will start a Jupyter Lab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0eeAY__mrIVJal1_NTmlA.png" /></figure><ul><li>From the Jupyter lab, let&#39;s open a terminal to download the model weights and config.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXOfVhrbollvXJxzgCXd9A.png" /></figure><ul><li>Download your favorite model from places like <a href="https://huggingface.co/models">Hugging face</a> or <a href="https://civitai.com/">civitai</a> and place it under</li></ul><pre>/home/stable-diffusion-webui/models/Stable-diffusion/</pre><p>To try SD 2.1, we need to download the weights and config.</p><pre>#Download weights<br>wget https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.ckpt<br><br>#Download config<br>wget https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml<br></pre><p>Let&#39;s rename the config file and place it in the model&#39;s directory.</p><pre>mv v2-inference-v.yaml v2-1_768-ema-pruned.yaml<br>mv v2-1_768-ema-pruned* stable-diffusion-webui/models/Stable-diffusion/</pre><p>You do not need a config file for all the models.</p><h3>What&#39;s next</h3><p>In the coming weeks, I will create blogs that show</p><ul><li>How you can train models that create images of you, your pet, or any object.</li><li>How to use a technique called Textual Inversion to generate images in different styles.</li><li>How to upscale generated images and more.</li><li>Try another popular UI for SD called <a href="https://github.com/invoke-ai/InvokeAI">InvokeAI</a></li></ul><p>I hope you find the blog useful, would love to know your thoughts on how we can improve it. In case you have any suggestions/challenges you can comment or ping us on the chat available on <a href="https://jarvislabs.ai/">Jarvislabs.ai</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cd281eb57f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jarvislabs-ai/stable-diffusion-with-automatic-1111-on-jarvislabs-1cd281eb57f9">Stable Diffusion with Automatic 1111 on Jarvislabs</a> was originally published in <a href="https://medium.com/jarvislabs-ai">Jarvislabs.ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy stable diffusion on GPU instance using FastAPI]]></title>
            <link>https://medium.com/jarvislabs-ai/deploy-stable-diffusion-on-gpu-instance-using-fastapi-d0743eeb735d?source=rss----f67efe9184c9---4</link>
            <guid isPermaLink="false">https://medium.com/p/d0743eeb735d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-art]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[stable-diffusion]]></category>
            <dc:creator><![CDATA[Vishnu Subramanian]]></dc:creator>
            <pubDate>Wed, 24 May 2023 04:19:52 GMT</pubDate>
            <atom:updated>2022-10-31T12:39:37.370Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, let’s explore how we can deploy a Stable diffusion model on a GPU and expose it as an API. To do this we will use</p><ul><li>GPU instance using <a href="https://jarvislabs.ai/">Jarvislabs</a></li><li>FastAPI for developing API</li><li>Gunicorn to run the FastAPI application</li></ul><p>The demo code is available in the GitHub <a href="https://github.com/jarvislabsai/fastapi-sd-template">repo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_tXCE5wONm-P1_0G" /><figcaption>Photo by <a href="https://unsplash.com/@spencerdavis?utm_source=medium&amp;utm_medium=referral">Spencer Davis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>GPU instance</h3><p>I will be using <a href="https://jarvislabs.ai/">Jarvislabs</a> GPU instances, which come with</p><ul><li>Cuda, Nvidia, and Pytorch libraries are preinstalled.</li><li>Build applications using your favorite IDE like JupyterLab and VScode.</li><li>Expose API using FastAPI in clicks.</li></ul><p>For this blog, let&#39;s use a PyTorch-powered instance.</p><p>Most of the below steps are applicable to local or other cloud platforms.</p><h4>Setting up environment</h4><p>Let&#39;s install some of the additional software required for FastAPI, stable diffusion, and diffusers (Hugging face library).</p><p>Run the below command from a terminal.</p><pre>pip install -r requirements.txt</pre><p>Which installs the below libraries.</p><pre>fastapi==0.85.0<br>uvicorn==0.18.3<br>diffusers==0.6.0<br>gunicorn==20.1.0<br>boto3==1.24.90<br>transformers==4.23.1<br>ftfy==6.1.1</pre><h3>Expose the Stable diffusion model as a rest API</h3><p>Let&#39;s explore the main.py from <a href="https://github.com/jarvislabsai/fastapi-sd-template/blob/main/main.py">here</a>.</p><p>It primarily contains code to:</p><h4>Load the Stable diffusion model</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f58749da4655ecdb63d1db47deee66e3/href">https://medium.com/media/f58749da4655ecdb63d1db47deee66e3/href</a></iframe><p>The above code is responsible for downloading the model weights and pushing the model to the GPU. I am using float16 as it is faster to download and also runs faster on most modern GPUs. Ensure that you do not include this code inside your API code, as it will cause the creation of new models which can fill your GPU memory in no time.</p><p>We want the model to be loaded once per application/worker.</p><p>In order to download the Stable diffusion model, you need to accept the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5">user agreement</a> and should have logged in. You can find/create the token for login <a href="https://huggingface.co/settings/tokens">here</a></p><pre>huggingface-cli login</pre><h4>Expose the Stable diffusion model as a RestAPI</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d122204b95800a2e736000611640a1c/href">https://medium.com/media/1d122204b95800a2e736000611640a1c/href</a></iframe><p>We are creating a rest API genimagewhich is responsible for accepting an input request containing prompt and guidance_scale. The model(pipe) uses the prompt text and guidance_scale values to generate the image.</p><p>You can modify the GenImage to include other parameters in the model like</p><ul><li>height</li><li>width</li><li>seed</li><li>num_inference_steps</li></ul><p>The generated image can be shared back to the client in multiple ways, in our case we upload the image and share the URL as a response.</p><h3>Deploy the FastAPI application using Gunicorn</h3><p>Once we are done with the code, we can either use unicorn or gunicorn to deploy the application.</p><p>Gunicorn lets us run the application on multiple workers and also queues the requests. So let&#39;s deploy our FastAPI app on gunicorn.</p><pre>gunicorn main:app --bind=0.0.0.0:6006 -w 4 -k uvicorn.workers.UvicornWorker --timeout 120</pre><p>The port number 6006 could vary depending on where you are running the application.</p><p>-w 4 We are using 4 workers for demonstration, which you may have to tweak depending on the GPU memory needed. Each worker could take 8–10GB for a float16 model.</p><p>If you are trying this on Jarvislabs.ai, you can quickly get your API link by right-clicking on your running instance to use it in your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*_uoQA5ke0QreQ8mC-_NEsA.png" /></figure><p>I hope you find the blog useful, in case you face any challenges let me know in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0743eeb735d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jarvislabs-ai/deploy-stable-diffusion-on-gpu-instance-using-fastapi-d0743eeb735d">Deploy stable diffusion on GPU instance using FastAPI</a> was originally published in <a href="https://medium.com/jarvislabs-ai">Jarvislabs.ai</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>