import base64 import streamlit as st import openai import os # openai.api_key = "" openai.api_key = os.environ.get("OPENAI_API_KEY") st.set_page_config( page_title="DALL·E Gerador de Imagens 🖼️", page_icon="🎨", layout="wide", ) # Custom CSS styles st.markdown( """ """, unsafe_allow_html=True ) st.title("DALL·E Gerador de Imagens 🖼️") # Prompt input prompt = st.text_area("Entre o prompt:👇", height=5) # Size selection size_options = ["256x256", "512x512", "1024x1024"] selected_size = st.selectbox("Selecione o tamanho da imagem:", size_options) # href = f'Download' # st.markdown(href, unsafe_allow_html=True) if st.button("Veja a mágica 🪄"): # Generate image try: response = openai.Image.create( prompt=prompt, n=1, size=selected_size, response_format="b64_json", ) # Display image if response["data"]: image_data = base64.b64decode(response["data"][0]["b64_json"]) st.image(image_data) # Download button b64_image = base64.b64encode(image_data).decode() href = f'Download' st.markdown(href, unsafe_allow_html=True) else: st.warning("No image generated.") except Exception as e: st.error(e) print(e)