How to use Stable Diffusion v2.0 on Colab with Gradio UI using Diffusers

1littlecoder · Beginner ·🎨 Image & Video AI ·3y ago

Key Takeaways

Uses Stable Diffusion v2.0 with Gradio UI on Google Colab to generate images

Full Transcript

what's up coders welcome to one little coder in this table diffusion tutorial we're going to learn how to use stable diffusion 2.0 on Google collab using hugging face diffusers at the end of this video you will have you would have learned to build a radio application that looks like this also if you don't want to build this by yourself this Google collab notebook will be linked in the YouTube description all you have to do is click the Google collab notebook and then enjoy your creativity through stable division 2.0 if you are not familiar with stable division 2.0 I've already made an overview video which I'll link into the YouTube description make sure that you check it out let's quickly see what this new radio application or a very simple Radio application does so it takes a text prompt and then it uses the latest stable diffusion 2.0 model via the diffusers hugging face diffusers library and then it generates an image so I'm going to quickly go to lexicon art where we have got a lot of prompts I'm going to copy a prompt here and then I'm going to come back to this and then I'm going to paste it so ideally the image wouldn't look exactly the same because stable diffusion 2.0 uses a different text encoder so which means it's it's not the previous encoder so a lot of prompts that we're giving good results for you in the previous version would not be true anymore and also I've read a lot of comments that they stripped artists from their training data which means most of this might not be useful at all but just for this simple exercise we are going to leave that out and then we are just going to use this as a reference point for us to understand how to generate images using stable division 2.0 but just because we are seeing the image I can actually see there is a huge difference in the way images are generated maybe this is certain parameters that we are not giving right now but that's that's what we have got so let's let's see the image that we have got so this is the image that we have got and we have got a prompt and we can generate image so now let's get into the details of how to do this by yourself the first step is this Google collab notebook will be in the YouTube description but if you're starting from scratch create a new Google collab notebook click file and then click new notebook once you click new notebook then make sure that you go to runtime Click Change runtime and then select GPU so you need GPU for faster inference so make sure that you have got a GPU once you have got the GPU just make sure that you can test whether the GPU is available and the easiest way to test an Nvidia gpus the bank Nvidia SMI that will tell you what is the type of GPU that you have got we have got a Tesla T4 with 16 gig machine which is good the next thing is we need to install the required libraries the most important is diffusers that is going to let us access stable diffusion the next thing is Transformers which is a dependency accelerate is to speed up as the name suggests but again um accelerate as a lot of usages but if you do not use accelerate in this this notebook will run much slower than what it is ideally right now and then some other dependencies and finally gradu for the UI development GUI graphical user interface once you install all these libraries the next thing that you have to do is from diffusers import stable diffusion Pipeline and Euler discrete scheduler in this particular stable diffusion 2.0 we're going to use a different scheduler from what we have been using before so then the next step is Define the model ID which directly goes to the model link from hugging face model Hub so this is where the new stable division 2.0 is added you don't have to accept terms of services or you don't have to do any check mark which also means that you don't need to authenticate or you don't have to have hugging face token this is a very important step ahead because that was creating a lot of friction for a lot of my users and they were getting stuck in the strip rather than they can you know instead of enjoying their Creative Juice they were actually stuck in the loop of creating a hugging face account and then the token and then everything else but right now good thing is model is available even if you have do not have any token or doesn't matter the next thing is Define the scheduler and then create pipe if you are familiar with stable diffusion pipeline you need to create a pipe from pre-chain model ID scheduler revision and torch type and which is which is just a just the data type to make it easier for memory usage then finally move the model to the GPU device in this case code and this is going to download all the models which will take a couple of minutes and the next thing is um it says make sure xformers is installed that's strange because I thought I installed explorers but it couldn't figure out but there's a game you can fix it when you are doing it by yourself the next step is Define a prompt in this case I have said a realistic photo of 3D cartoon style of a cat in a space suit with Milky Way background so the next thing is after you define a prompt the next thing you need to do is create a function I'm calling the function text to image and the argument is a prompt and then inside that we are using pipe prompt and the images thankfully are 768 by 768 I'm not giving any guidance scale here but you can also specify the guidance skill guidance scale equals maybe 10 or 7 whatever you want and once you get the output previously what we used to do is dot images of 0 but right now I'm just leaving it here and then save the image then return the image now let us once the function is defined which is not happening because we have the greedy application running stop to create your application just it's in my demo so I'm going to run this once again and I'm going to call the function which is going to create the image and the prompt is something that we have already created here and uh it's going to create the image using the function text to image and as you can see this is happening real time so you know how much time it takes for it to generate one image which is a 768 by 768 image and in this particular case we are using the stable division 2.0 model that got just released two days back and this is the image it looks pretty bad but like I'm not here to teach you prompt Engineering in this video this video scope is purely how you can access stable efficient 2.0 on Google collab on a free GPU of course so now we have got a successful creation at the end so what we can do now is if you have not installed radio installed radio and just in two lines of python code you may not believe me but this is true just in two lines of python code we are going to create this beautiful interface which is import gradu as gr and then gr dot interface greedy has two main classes one is interface the other one is blocks blocks is for more advanced UI for a very simplistic and easy UI I'm sticking to interface the first one is a function which you want to process when this input is triggered and this output is generated so as you can see for our function the input is a text prompt and the output is an image and as usual you've got the function the input and the output and finally launch that share is equal to true so that you can get a URL debug is equal to true you can trace if there is any error and run this and you're going to get this web interface so what does it mean it means you don't have to go to the stable diffusion default let's say the spaces and then when you try something it's going to say the server is busy or something like that you are not bound by what is available but what you are doing right now is if you follow this tutorial you have this available for you just click submit then you are not on a queue you are not waiting anywhere all you are doing is thanks to Google for its free GPU you can use and generate images using stable division 2.0 once again the image that you right now see may not be the perfect image because we are not playing with the prompts in fact I have not got enough time to play with the prompts to understand what kind of prompts are doing good like I said at the start of the video the problems that were working fine on stable division version 1.5 or 1.4 would not necessarily work fine here because this uses a totally different text encoder the training data set has been changed a lot of artists have been removed which means it's it's what it is so but at the end of this now we have got this image let me quickly go grab one more prompt so this looks nice let's copy this and then go back to our application and then paste this then click submit this is a very simple prompt this is a highly detailed three-dimensional retro futuristic Android Android is like the Android made out of pasta going for a walk outside very creative but I'm not sure if the image that is going to be generated will be as same as what we saw before in the previous stable diffusion model so let's wait it took about 25 26 seconds oh this looks pretty ugly at this point but yeah please please make sure that you feel you change the prompt and then find out what is working fine but the overall idea here is that we have successfully learned how to use hugging phase diffusers to use the latest stable division 2.0 not just you use as a as a like a code but also have a very good user interface you can give the prompt and then click submit if you want to improve certain parameters you can increase the number of steps like for example you can go here and then see what kind of what kind of parameters you can use also you can also go to the GitHub repository and then see what are all the options that are available why do we have to use particular scheduler and all those kind of details but until that this should keep you busy to create your new stable diffusion images if you have got any question let me know in the comment section otherwise I hope you find this video helpful in learning how to use stable division 2.0 on Google collab for free GPU see you in the next video

Original Description

This is a tutorial on how to use the Hugging Face's Diffusers library to run Stable Diffusion 2 in a simple and efficient manner. This tutorial also teaches you to build a Gradio UI for Stable Diffusion v2.0 on Google Colab Code - https://github.com/amrrs/stable-diffusion-v2-colab-ui Stable Diffusion - https://github.com/Stability-AI/stablediffusion #stablediffusion #aiart
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from 1littlecoder · 1littlecoder · 0 of 60

← Previous Next →
1 How to create your Free Data Science Blog on Github with Fastpages from Fastai
How to create your Free Data Science Blog on Github with Fastpages from Fastai
1littlecoder
2 Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
1littlecoder
3 Create your first Data Science Web App using R Shiny
Create your first Data Science Web App using R Shiny
1littlecoder
4 How to create a Reproducible Example in R using reprex
How to create a Reproducible Example in R using reprex
1littlecoder
5 No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
1littlecoder
6 Scrape HTML Table using rvest and Process them for insights using tidyverse in R
Scrape HTML Table using rvest and Process them for insights using tidyverse in R
1littlecoder
7 Google Teachable Machine Learning Build No Code AI solution
Google Teachable Machine Learning Build No Code AI solution
1littlecoder
8 Create meaningful fake tidy datasets in R using fakir [#rstats Package]
Create meaningful fake tidy datasets in R using fakir [#rstats Package]
1littlecoder
9 How to enable using R Programming with Visual Studio VS Code
How to enable using R Programming with Visual Studio VS Code
1littlecoder
10 Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
1littlecoder
11 Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
1littlecoder
12 Intro to Google Colab - How to use Colab
Intro to Google Colab - How to use Colab
1littlecoder
13 Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
1littlecoder
14 Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
1littlecoder
15 Do you want a career in Data Science - Tamil Webinar
Do you want a career in Data Science - Tamil Webinar
1littlecoder
16 Android Smartphone Analysis in R [Live Coding Screencast]
Android Smartphone Analysis in R [Live Coding Screencast]
1littlecoder
17 Programmatically create Images, Memes, Watermarks using Python with imgmaker
Programmatically create Images, Memes, Watermarks using Python with imgmaker
1littlecoder
18 Kaggle Walkthrough to get you started with Data Science - Webinar
Kaggle Walkthrough to get you started with Data Science - Webinar
1littlecoder
19 Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
1littlecoder
20 Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
1littlecoder
21 Excel to R - Pivot + Bar Chart in Excel  & R using tidyverse [Live Coding]
Excel to R - Pivot + Bar Chart in Excel & R using tidyverse [Live Coding]
1littlecoder
22 Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
1littlecoder
23 5 websites to get Free Real-World Datasets for Data Science/ML Projects
5 websites to get Free Real-World Datasets for Data Science/ML Projects
1littlecoder
24 Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
1littlecoder
25 Correlation-alternative PPS (Predictive Power Score) Python Package Demo
Correlation-alternative PPS (Predictive Power Score) Python Package Demo
1littlecoder
26 Automated Website Screenshots in R using {webshot}
Automated Website Screenshots in R using {webshot}
1littlecoder
27 Installing Custom RStudio Theme (Synthwave85)
Installing Custom RStudio Theme (Synthwave85)
1littlecoder
28 Analyse Google Trends Search Data in R using {gtrendsR}
Analyse Google Trends Search Data in R using {gtrendsR}
1littlecoder
29 3 Tips to ask question on Stack Overflow the right way to get answers
3 Tips to ask question on Stack Overflow the right way to get answers
1littlecoder
30 Learn Data Science with R - Mini Projects - Web Scraping Zomato
Learn Data Science with R - Mini Projects - Web Scraping Zomato
1littlecoder
31 Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
1littlecoder
32 GET Hackernews Front Page Results using REST API in R
GET Hackernews Front Page Results using REST API in R
1littlecoder
33 Quickly deploy ML WebApps from Google Colab using ngrok
Quickly deploy ML WebApps from Google Colab using ngrok
1littlecoder
34 Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
1littlecoder
35 Plotly Interactive Plots as Pandas Plotting Backend df.plot()
Plotly Interactive Plots as Pandas Plotting Backend df.plot()
1littlecoder
36 Stack Overflow Developer Survey 2020 Highlights for New Programmers
Stack Overflow Developer Survey 2020 Highlights for New Programmers
1littlecoder
37 Matplotlib Animation Charts in Python using Celluloid
Matplotlib Animation Charts in Python using Celluloid
1littlecoder
38 Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
1littlecoder
39 Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
1littlecoder
40 Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
1littlecoder
41 Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
1littlecoder
42 Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
1littlecoder
43 ggplot2 Text Customization with ggtext | Data Visualization in R
ggplot2 Text Customization with ggtext | Data Visualization in R
1littlecoder
44 Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
1littlecoder
45 YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
1littlecoder
46 Matplotlib Animated Bar Chart Race in Python | Data Visualization
Matplotlib Animated Bar Chart Race in Python | Data Visualization
1littlecoder
47 Simple Python GUI Development using {guietta}
Simple Python GUI Development using {guietta}
1littlecoder
48 #8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
#8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
1littlecoder
49 Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
1littlecoder
50 Github New Feature Profile Summary/Mini-Resume - Profile Views
Github New Feature Profile Summary/Mini-Resume - Profile Views
1littlecoder
51 Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
1littlecoder
52 What is OpenAI GPT-3 - Hype, Examples, Worries
What is OpenAI GPT-3 - Hype, Examples, Worries
1littlecoder
53 Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
1littlecoder
54 Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
1littlecoder
55 GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
1littlecoder
56 How to use Advanced Google Search to extract Email Ids from Linkedin
How to use Advanced Google Search to extract Email Ids from Linkedin
1littlecoder
57 Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
1littlecoder
58 Flow - R Package to visualize code logic, functions as a Flow Diagram
Flow - R Package to visualize code logic, functions as a Flow Diagram
1littlecoder
59 Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
1littlecoder
60 Create a Pencil Sketch Portrait with Python OpenCV
Create a Pencil Sketch Portrait with Python OpenCV
1littlecoder

Related Reads

📰
The Best Free AI Image Generators Better Than ChatGPT and Gemini
Discover free AI image generators that outperform ChatGPT and Gemini for specific workflows, offering superior photorealism and graphic design capabilities
Dev.to AI
📰
50+ Sequential Images, One Prompt in Codex
Learn to generate sequential images with Codex using a single prompt and understand the limitations of this approach
Medium · ChatGPT
📰
How can I batch-generate 3D assets from prompts or images using an API, and which 3D generation APIs support batch generation?
Learn to batch-generate 3D assets from prompts or images using APIs for efficient pipeline creation
Reddit r/artificial
📰
How AI Head Swap Works: The Technology Behind Realistic AI Image Replacement
Learn how AI head swap technology works and its applications in image editing
Dev.to AI
Up next
Sora Shutdown! Best AI Video Replacements Right Now
LoverFighterWriter
Watch →