├── Img1.jpg ├── Img2.jpg ├── Img3.jpg ├── generate_image.py ├── README.md └── main.py /Img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dheeraj-02NK/AI-Image-Generator/HEAD/Img1.jpg -------------------------------------------------------------------------------- /Img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dheeraj-02NK/AI-Image-Generator/HEAD/Img2.jpg -------------------------------------------------------------------------------- /Img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dheeraj-02NK/AI-Image-Generator/HEAD/Img3.jpg -------------------------------------------------------------------------------- /generate_image.py: -------------------------------------------------------------------------------- 1 | import os 2 | import openai 3 | 4 | # Set your OpenAI API key here 5 | openai.api_key = "YOUR_API_KEY" 6 | 7 | user_prompt = "cat wearing red cape" 8 | 9 | response = openai.Image.create( 10 | prompt=user_prompt, 11 | n=1, 12 | size="1024x1024" 13 | ) 14 | 15 | image_url = response['data'][0]['url'] 16 | print(image_url) 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI Image Generator 2 | 3 | AI Image Generator is a Python application that utilizes OpenAI's GPT-3 to generate images based on user prompts and style preferences. This application provides a graphical user interface (GUI) built using Tkinter for a seamless user experience. 4 | 5 | ## Features 6 | 7 | - Generate images from textual prompts. 8 | - Choose from different art styles such as Realistic, Cartoon, 3D Illustration, and Flat Art. 9 | - Control the number of images generated with a slider. 10 | - Display the generated images directly in the GUI. 11 | 12 | ## Requirements 13 | 14 | - Python 3.x 15 | - `customtkinter` library (Install with `pip install customtkinter`) 16 | - `openai` library (Install with `pip install openai`) 17 | - `PIL` library (Install with `pip install Pillow`) 18 | - `requests` library (Install with `pip install requests`) 19 | 20 | ## Usage 21 | 22 | 1. Set up your OpenAI API key. 23 | 24 | 2. Run the `main.py` script to launch the application. 25 | 26 | 3. Enter a prompt in the "Prompt" text box. 27 | 28 | 4. Select a style from the "Style" dropdown menu. 29 | 30 | 5. Adjust the number of images to generate using the slider. 31 | 32 | 6. Click the "Generate" button to create and display the images. 33 | 34 | ## Customization 35 | 36 | - You can further customize the GUI's appearance and layout by modifying the code in `main.py`. 37 | - Adjust the initial window size by changing the `root.geometry` line. 38 | 39 | 40 | ## Acknowledgments 41 | 42 | - [OpenAI](https://openai.com) for their powerful GPT-3 model. 43 | - [customtkinter](https://pypi.org/project/customtkinter/) for enhanced Tkinter widgets. 44 | 45 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # Author: Dheeraj N Kashyap 2 | 3 | import customtkinter as ctk 4 | import tkinter 5 | import os 6 | import openai 7 | from PIL import Image, ImageTk 8 | import requests 9 | import io 10 | 11 | # Set your OpenAI API key here 12 | openai.api_key = "YOUR_API_KEY" 13 | 14 | def generate(): 15 | user_prompt = prompt_entry.get("0.0", tkinter.END) 16 | user_prompt += " in style: " + style_dropdown.get() 17 | 18 | response = openai.Image.create( 19 | prompt=user_prompt, 20 | n=int(number_slider.get()), 21 | size="512x512" 22 | ) 23 | 24 | image_urls = [] 25 | for i in range(len(response['data'])): 26 | image_urls.append(response['data'][i]['url']) 27 | print(image_urls) 28 | 29 | images = [] 30 | for url in image_urls: 31 | response = requests.get(url) 32 | image = Image.open(io.BytesIO(response.content)) 33 | photo_image = ImageTk.PhotoImage(image) 34 | images.append(photo_image) 35 | 36 | def update_image(index=0): 37 | label.config(image=images[index]) 38 | label.image = images[index] 39 | index = (index + 1) % len(images) 40 | label.after(3000, update_image, index) 41 | 42 | update_image() 43 | 44 | root = ctk.CTk() 45 | root.title("AI Image Generator") 46 | 47 | ctk.set_appearance_mode("dark") 48 | 49 | # Create two frames to divide the window 50 | input_frame = ctk.CTkFrame(root) 51 | input_frame.pack(side="top", expand=True, padx=20, pady=20, fill='both') 52 | 53 | output_frame = ctk.CTkFrame(root) 54 | output_frame.pack(side="top", expand=True, padx=20, pady=20, fill='both') 55 | 56 | prompt_label = ctk.CTkLabel(input_frame, text="Prompt") 57 | prompt_label.grid(row=0, column=0, padx=10, pady=10) 58 | prompt_entry = ctk.CTkTextbox(input_frame, height=10) 59 | prompt_entry.grid(row=0, column=1, padx=10, pady=10) 60 | 61 | style_label = ctk.CTkLabel(input_frame, text="Style") 62 | style_label.grid(row=1, column=0, padx=10, pady=10) 63 | style_dropdown = ctk.CTkComboBox(input_frame, values=["Realistic", "Cartoon", "3D Illustration", "Flat Art"]) 64 | style_dropdown.grid(row=1, column=1, padx=10, pady=10) 65 | 66 | number_label = ctk.CTkLabel(input_frame, text="# Images") 67 | number_label.grid(row=2, column=0) 68 | number_slider = ctk.CTkSlider(input_frame, from_=1, to=10, number_of_steps=9) 69 | number_slider.grid(row=2, column=1) 70 | 71 | generate_button = ctk.CTkButton(input_frame, text="Generate", command=generate) 72 | generate_button.grid(row=3, column=0, columnspan=2, sticky="news", padx=10, pady=10) 73 | 74 | # Create a Label widget to display the generated image 75 | label = tkinter.Label(output_frame) 76 | label.pack() 77 | 78 | root.mainloop() 79 | --------------------------------------------------------------------------------