![]() |
Let’s take a brief look at the field of diffusion models, which are used to text to create images. Using a Markov chain, a diffusion model gradually adds noise to the data before reversing the process and creating the necessary data sample from the noise. Notable diffusion models are StabilityAI’s Stable diffusion, Google’s Imagen, and OpenAI’s DALLE2. Build an AI Image Generator App With TkinterHere, We’ll look at how to create an app using Tkinter and Stable Diffusion from Stability AI. While generative models like Flow-based models, Variational Autoencoders (VAEs), and Generative Adversarial Networks (GANs) are well-known, diffusion models are more advanced, effective, and produce better results. Building the AppWe’ll walk through creating a basic GUI application using a custom Tkinter. The goal is to set up an application window that can serve as the foundation for the “Text to Image” converter. Below is a snippet of Python code that demonstrates the creation of a basic GUI application:
Output: ![]() Output of the above code Setting Up the Inline Text Bar and Clickable ButtonBy using customtkinter to build upon our basic GUI design, we can improve the user interface by including interactive elements like buttons and input fields. This is an upgrade to our earlier code that adds an action-triggering button and an entry widget for text input.
Output ![]() Inline text bar and generate button Adding a Label to Display ImagesLet’s add a label widget to our GUI application to enhance it even more. It will act as a placeholder for images that are created based on the text input.
Output ![]() Label for Image holding and displaying (Orange color is illustrated only for displaying purpose later it will be replaced by the Image) Setup the Access token in hugging faceHugging face gives us access to a stable diffusion model. Hugging Face is a platform and community that offers free and open-source machine learning datasets and models. Hugging Face is free, yet there is a paid tier as the models are open source. If you don’t already have one, you must make a profile on hugging face. You require a “Access token” after registering. Steps to Setup the Access token in hugging face:
Image GenerationWe Import a pre-trained Stable Diffusion model and is identified by modelid. The model is loaded using the pipe variable with the provided authentication token, and the encoder part of the model is deleted to save memory. Using the Stable Diffusion model, we develop a generate() method that reads the text prompt from the entry field, creates an image, saves it, and modifies the image_label to show the updated image. When the “Generate” button is hit, the generate() function is supposed to be called.
The guidance_scale parameter is set to 8.5. In order to produce a picture that closely resembles the text prompt, the guidance scale regulates the strength of the guiding signal sent to the model. Images that more closely fit the prompt but might be less varied are produced by a higher guiding scale value. Once the code has been executed, give it some time to download the Stable Diffusion model prerequisites. Depending on your internet speed and system specifications, this could take a few minutes. Note: This model will operate on the CPU if you don’t have access to a GPU. This will work, but depending on the capacity of your CPU, it might take longer to generate photos. Output ![]() Images Generated by the model ConclusionIn conclusion, this article offers a thorough walkthrough for developing an application that integrates AI for image production and uses Python’s Tkinter framework. It includes crucial topics including configuring the development environment, putting the user interface in place, and adding AI models to produce images. |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |