Skip to content

Dinakar2329/ImageGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Image Generator using OpenAI DALL-E API and Streamlit

DALL-E Image Generator

Overview

Welcome to the Image Generator powered by OpenAI's DALL-E API and presented through Streamlit. This application allows you to generate high-quality images based on your textual input.

Prerequisites

Installation

Clone this repository:

 git clone https://github.com/dinakar2329/Image-generator.git
 cd image-generator

1.Install dependencies:

pip install streamlit openai

2.Set up your OpenAI API key:

Replace YOUR_API_KEY_HERE with your actual OpenAI API key in the api_key field.

Usage

1.Run the Streamlit app:

python -m streamlit run app.py

2.Enter a prompt in the input bar and click the "Generate Images" button.

Streamlit App Code

import streamlit as st
from openai import OpenAI

# API
api = OpenAI(api_key="YOUR_API_KEY_HERE")

# Function to Generate Image URLs
def Generate(user_input):
    response = api.images.generate(
        prompt=user_input,
        n=4,  # Generate 4 images
        size="1024x1024",
        quality="hd"
    )

    # Creating a list to store image URLs
    image_urls_list = []
    for image_data in response.data:
        image_url = image_data.url
        image_urls_list.append(image_url)

    # If no image URLs are generated
    if len(image_urls_list) == 0:
        raise ValueError("No images found in the API response.")

    return image_urls_list

# Streamlit UI
title = st.title("Image Generator")

container = st.container(border=True)
input_bar = st.text_input("Enter prompt to generate images")

button = st.button("Generate Images")
col1, col2, col3, col4 = st.columns(4)

# If button is clicked
if button or input_bar:
    try:
        image_urls1, image_urls2, image_urls3, image_urls4 = Generate(input_bar)
        col1.image(image_urls1, caption="Image 1")
        col2.image(image_urls2, caption="Image 2")
        col3.image(image_urls3, caption="Image 3")
        col4.image(image_urls4, caption="Image 4")
    except Exception as e:
        st.error(f"Error generating images: {e}") 

Make sure to replace "YOUR_API_KEY_HERE" with your actual OpenAI API key. Happy generating!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages