Spaces:
Running
Running
File size: 2,469 Bytes
cf7cca5 a68a3ae cf7cca5 a68a3ae cf7cca5 6504b4e cf7cca5 6504b4e cf7cca5 a68a3ae cf7cca5 3837c32 cf7cca5 5784688 cf7cca5 7552856 cf7cca5 5784688 cf7cca5 3837c32 cf7cca5 3837c32 d47fc51 a68a3ae 3837c32 cf7cca5 7552856 b0362bf cf7cca5 7552856 ecc5c7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import os
from openai import OpenAI
import gradio as gr
from dotenv import load_dotenv
# Load environment variables from the .env file
load_dotenv()
# Ensure the OPENAI_API_KEY environment variable is set; it's automagically loaded into the client
client = OpenAI()
if client.api_key is None:
raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")
# Load the APP_PASSWORD from the environment
APP_PASSWORD = os.getenv("APP_PASSWORD")
def generate_image(hair_color, eye_color, person, age, style, password):
if password != APP_PASSWORD:
return "Incorrect password.", None
# Constructing the prompt based on user input
prompt = f"Create a beautiful artistic profile picture of a smiling {age} year-old {person} with {hair_color} hair, {eye_color} eyes. Style: {style}."
# Displaying the prompt to the user
print("Prompt:", prompt)
try:
response = client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
quality="standard",
n=1
)
# Get the image URL from the response
image_url = response.data[0].url
return prompt, image_url
except Exception as e:
print("An error occurred:", e)
return "An error occurred while generating the image.", None
hair_color_options = ["Black", "Brown", "Blonde", "Red", "Gray", "White", "Green", "Rainbow", "Blue"]
eye_color_options = ["Blue", "Brown", "Green", "Gray", "Hazel"]
person_options = ["Boy", "Girl"]
style_options = ["Fortnite Character", "3D Pixar Render", "Picasso Painting", "Van Gogh Painting", "Abstract Art", "Realistic Portrait"]
# Define the Gradio interface
iface = gr.Interface(
fn=generate_image,
inputs=[
gr.Dropdown(choices=hair_color_options, label="Hair Color"),
gr.Dropdown(choices=eye_color_options, label="Eye Color"),
gr.Dropdown(choices=person_options, label="Person"),
gr.Number(label="Age", value=12, minimum=8, maximum=120, step=1, precision=0),
gr.Dropdown(choices=style_options, label="Style"),
gr.Textbox(label="Password", type="password"),
],
outputs=[gr.Text(label="Prompt"), gr.Image(label="Generated Image")],
title="Profile Picture Generator",
description="Enter the attributes for your profile picture.",
concurrency_limit=1 # Set concurrency limit here
)
# Launch the Gradio app
iface.launch() |