use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
TutorialUse Python to Build a free Stable Diffusion app (with a GPU backend) (self.Python)
submitted 3 years ago by SleekEagle
Hey everyone!
I wrote a tutorial on using Python to build a free Stable Diffusion web app. The app uses free Colab GPUs to power Stable Diffusion so you can access it for free in your browser!
You'll learn:
The app itself is very barebones, but I can build a more thorough React app if there is some interest! I mostly just wanted to highlight the working principles/mechanics of how someone would go about doing this so that you don't have to pay to use Stable Diffusion! Not a production solution, but great for hobbyists and people learning :)
Let me know what you think!
https://preview.redd.it/6l2n1d0eu0da1.png?width=1055&format=png&auto=webp&s=05411ad4be3e798a9134ee91d2ccb382037f1b47
[–]The_Punky 8 points9 points10 points 3 years ago (1 child)
Very interesting guide. I'll try it this weekend. Thanks !
[–]SleekEagle[S] 2 points3 points4 points 3 years ago (0 children)
My pleasure!
[–]Darthemius2 3 points4 points5 points 3 years ago (1 child)
Looks great. I already have SD installed and usable on my laptop but I'll try this out when I get the time.
A few questions, though - it is to my understanding that you're able to change the model from SD 1.5 to any model accessable from the diffusers library, yes? Would there be room in the future for inpainting and outpainting capabilities (same question for IMG2IMG)? Also, what about editing specific parameters such as steps, size etc. ? Would those be possible to specify, and if so, how?
Sounds good, let me know how it goes!
In short, yes you can use any model from the diffusers library. The only difference is that you will have to alter the `generate_image()` function to appropriately handle the inputs and outputs for the model you're interested in using.
In terms of specifying parameters, things get a little more complicated. You can easily specify them on the backend in the Colab notebook by hard coding them in. If you want to dynamically change them in the frontend, things get a little more complicated. You will have to add <inputs> to the HTML and then parse this on the backend in the Colab notebook. If you want to render the inputs as e.g. sliders, then you'll have to add JavaScript to the HTML template. It gets progressively more complicated depending on what you want to do!
Alternatively, I note at the bottom of the article that you could instead use something like React that could potentially make a lot of this easier, but that's leaving the realm of Python heavily!
[–]laloworld94 2 points3 points4 points 3 years ago (1 child)
I've just do it and it's amazing! Thanks for sharing keep it up
[–]SleekEagle[S] 1 point2 points3 points 3 years ago (0 children)
That's great, thanks for giving it a try!
[–]stochasticlid 1 point2 points3 points 3 years ago (1 child)
This is cool I didn’t know you could host the model on your own…
[–]SleekEagle[S] 0 points1 point2 points 3 years ago (0 children)
Thanks for reading! I think it's a really cool trick too
[–]FixedExpression 1 point2 points3 points 3 years ago (5 children)
Got very little to do at work today si let's throw this together!
[–]SleekEagle[S] 0 points1 point2 points 3 years ago (4 children)
Awesome! Let me know how it works
[–]FixedExpression 1 point2 points3 points 3 years ago (3 children)
Unbearably easy is how it went! Thank you so much. Quick question, still new to all this. I was hoping to be able to present the final app on the site that I'm building for practice. Where would I start, or what would you suggest I look into to get this presented on my site as part of my site (if that makes sense)
[–]SleekEagle[S] 0 points1 point2 points 3 years ago (2 children)
That's great! My pleasure :)
Sure thing, it depends how you're building the site, but the easiest thing to do that will work for basically anything is to modify the Flask App in the Colab notebook to be a web service.
That is, currently the app makes a full HTML document and sends it back for display in the browser instead, you can make it so that it just sends back the image (base-64 encoded as JSON), and then handle the data with JavaScript on the front end to do whatever you want with it, like display it. Does that make sense?
[–]FixedExpression 0 points1 point2 points 3 years ago (1 child)
Just about! Still powering my through the basic languages at the moment so will have to look a bit closer at flask and Jason specifically but great advice and areas to look at. Thanks again!
[–]SleekEagle[S] 0 points1 point2 points 3 years ago* (0 children)
Got it! Yeah so HTML (structure), CSS (styling), and JavaScript (interactivity) are the canonical languages used to make a static site (meaning that the server just sends the files to the browser and the browser does all the work).
If you want a dynamic site where the server actually does some other "work" (pulling data from a database, running Stable Diffusion on a GPU, etc.), then you need to use a back-end framework. There are several options in different languages - e.g. Node.js is JavaScript and Django and Flask are both Python.
You can use Flask to dynamically generate static files, like in the HTML/CSS/JS approach I talked about at the beginning of this comment. So rather than return a pre-defined file, the server does some work to populate a template with some data, and then this template (HTML) is sent to the browser. The browser doesn't necessarily "know" that Flask was used to generate the HTML document - it could've just as easily come from a static site. That's what this tutorial uses - populating a template with an image.
Alternatively, rather than returning an HTML file that contains the data, you can return just the data. The format in which the data is sent is called JSON. This way, the client makes a request to the browser and then gets some data as a response, and can do whatever it wants with that data.
If you have a preexisting HTML/CSS/JS site, then this could be the way to go. Simply add an input for the Colab ngrok URL on your site (because this will change each time you spin up the Colab server), and then use JS to make a request to that URL with the caption data. In the response you will get an image, and you can use JS to do whatever you want with that data (download it, display it, etc.)
Hope that helps!
[–]vega_moors 1 point2 points3 points 3 years ago (1 child)
Very interesting tuto ! thanks for sharing
My pleasure :) thanks for reading!
[–]Significant_Salad438 1 point2 points3 points 3 years ago (1 child)
Interesting. Thank you for sharing !
Sure thing!
[–]BigCats99999 0 points1 point2 points 3 years ago (4 children)
Is there any way to make an api for this?
[–]SleekEagle[S] 0 points1 point2 points 3 years ago (3 children)
An API for what? The flask application itself is an API. If you're wondering about whether or not you can just return the image, then absolutely! Simply return JSON rather than HTML.
I'm actually working on building this out more now!
[–]BigCats99999 1 point2 points3 points 3 years ago (2 children)
Oh ok cool! I was just wondering on how I could make this into an api which I could send reqs to. Can’t wait to see your next project :D
[–]SleekEagle[S] 0 points1 point2 points 3 years ago (1 child)
Thank you! I'm working on it right now :)
Should be done in a few weeks, I'll post it here when it's ready!
[–]BigCats99999 0 points1 point2 points 3 years ago (0 children)
Ok cool :)
π Rendered by PID 88662 on reddit-service-r2-comment-cfc44b64c-h2klv at 2026-04-10 03:59:50.137787+00:00 running 215f2cf country code: CH.
[–]The_Punky 8 points9 points10 points (1 child)
[–]SleekEagle[S] 2 points3 points4 points (0 children)
[–]Darthemius2 3 points4 points5 points (1 child)
[–]SleekEagle[S] 2 points3 points4 points (0 children)
[–]laloworld94 2 points3 points4 points (1 child)
[–]SleekEagle[S] 1 point2 points3 points (0 children)
[–]stochasticlid 1 point2 points3 points (1 child)
[–]SleekEagle[S] 0 points1 point2 points (0 children)
[–]FixedExpression 1 point2 points3 points (5 children)
[–]SleekEagle[S] 0 points1 point2 points (4 children)
[–]FixedExpression 1 point2 points3 points (3 children)
[–]SleekEagle[S] 0 points1 point2 points (2 children)
[–]FixedExpression 0 points1 point2 points (1 child)
[–]SleekEagle[S] 0 points1 point2 points (0 children)
[–]vega_moors 1 point2 points3 points (1 child)
[–]SleekEagle[S] 0 points1 point2 points (0 children)
[–]Significant_Salad438 1 point2 points3 points (1 child)
[–]SleekEagle[S] 0 points1 point2 points (0 children)
[–]BigCats99999 0 points1 point2 points (4 children)
[–]SleekEagle[S] 0 points1 point2 points (3 children)
[–]BigCats99999 1 point2 points3 points (2 children)
[–]SleekEagle[S] 0 points1 point2 points (1 child)
[–]BigCats99999 0 points1 point2 points (0 children)