Git Product home page Git Product logo

dalle2-webapp's Introduction

dalle2-webapp

Prerequisite


Step-by-step Guide (Run Locally)

  • Create a new folder dalle2-webapp
  • Change directory cd dalle2-webapp
  • Create a new file auth.py inside dalle2-webapp folder
  • Create a new file app.py inside dalle2-webapp folder
  • Create a new folder img inside dalle2-webapp folder

Install Python Module

  • Install Python OpenAI Module (using pip)
  pip install openai
  • Install Python customtkinter Module (using pip)
  pip install customtkinter
  • Incase any other modules are missing locally, use:
  pip install <MODULE_NAME> 

auth.py file

  • Open the auth.py file and add:
  auth_token = "YOUR_AUTH_TOKEN"

Create, Copy & Replace the API Key from OpenAI website under 'User the Setting > View API Keys'. The 'auth.py' file would look like this: auth_token = "sk-7yGeq3lkQoNXFw8yZvdjkb&DVJSJBD798yUBDNKNSdss"


app.py file

  • Open the app.py file

  • ADD IMPORTS:

from auth import auth_token
import tkinter as tk
import customtkinter as ctk
from PIL import Image, ImageTk
import requests

jnn

  • IMPORT OpenAI + CONNECT API:
import openai
openai.api_key = auth_token
  • CREATE APP CODE (Paste below all above code):
app = tk.Tk()
app.geometry("532x632")
app.title("DALL•E 2 Text-to-Image App")
ctk.set_appearance_mode("dark")

main_image = tk.Canvas(app, width=512, height=512)
main_image.place(x=10, y=110)
  • ADD PROMPT INPUT CODE
promt_input = ctk.CTkEntry(
    height=40,
    width=512,
    text_font=("Arial", 20),
    text_color="black",
    fg_color="white",
    placeholder_text="Enter a prompt ",
)
promt_input.place(x=10, y=10)
  • ADD PROMPT API REQUEST FUNCTION
def apply_dalle():
    global tk_img
    global img

    prompt = promt_input.get()
    response = openai.Image.create(prompt=prompt, n=1, size="512x512")
    image_url = response["data"][0]["url"]
    img = Image.open(requests.get(image_url, stream=True).raw)
    tk_img = ImageTk.PhotoImage(img)
    main_image.create_image(0, 0, anchor=tk.NW, image=tk_img)
  • ADD SAVE IMAGE FUNCTION
def save_image():
    prompt = promt_input.get().replace(" ", "_")
    img.save(f"img/{prompt}.png")
  • ADD IMAGES GENERATION BUTTON
dalle_button = ctk.CTkButton(
    height=40,
    width=120,
    text_font=("Arial", 20),
    text_color="white",
    fg_color=("white", "gray38"),
    command=apply_dalle,
)
dalle_button.configure(text="Apply DALL•E 2")
dalle_button.place(x=100, y=60)
  • ADD SAVE IMAGE BUTTON
save_button = ctk.CTkButton(
    height=40,
    width=120,
    text_font=("Arial", 20),
    text_color="white",
    fg_color=("white", "gray38"),
    command=save_image,
)
save_button.configure(text="Save image")
save_button.place(x=266, y=60)
  • RUN APP FUNCTION
app.mainloop()

Run The App

  • From the root directory of 'app.py', run in terminal"
  python app.py

or

  python3 app.py

dalle2-webapp's People

Contributors

aaronsimca avatar

Stargazers

GAURAV KUMAR avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.