PromptCanvas / PromptCanvas_ImageGenerator.py
ProfessorLeVesseur's picture
Upload 3 files
ad1818d verified
raw
history blame
1.53 kB
import streamlit as st
# import base64
import openai
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
# Streamlit page setup
st.set_page_config(page_title="Pixel Generator", layout="centered", initial_sidebar_state="collapsed")
#Add the image with a specified width
image_width = 300 # Set the desired width in pixels
# st.image('MTSS.ai_Logo.png', width=image_width)
st.image('/Users/cheynelevesseur/Desktop/Python_Code/LLM_Projects/LLM_Vision/MTSS.ai_Logo.png', width=image_width)
st.header('PromptCanvas™ | Images')
st.subheader('Image Generator')
# Retrieve the OpenAI API Key from secrets
# openai.api_key = st.secrets["openai_api_key"]
# Set the OpenAI API key
# Retrieve OpenAI API key from environment variables
openai_api_key = os.getenv('OPENAI_API_KEY')
if not openai_api_key:
raise ValueError("OPENAI_API_KEY not set in environment variables")
# Set the OpenAI API key
openai.api_key = openai_api_key
def generate_images(prompt): #def generate_images(image_description, num_images):
response = openai.images.generate(
model="dall-e-3",
prompt = prompt,
size="1024x1024",
quality="standard",
n = 1,
)
image_url = response.data[0].url
return image_url
prompt = st.text_area("Enter a description for the image you want to generate")
#create a button
if st.button("Generate Images"):
generate_image=generate_images(prompt) #generate_image=generate_images(prompt, num_of_images)
st.image(generate_image)