File size: 1,616 Bytes
6504b4e
cf7cca5
 
 
6504b4e
 
cf7cca5
6504b4e
cf7cca5
 
 
 
 
 
 
 
 
 
5784688
cf7cca5
 
6504b4e
cf7cca5
 
 
 
 
5784688
cf7cca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from openai import OpenAI
import os
import gradio as gr

# 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.")

def generate_image(hair_color, mood, eye_color):
    # Constructing the prompt based on user input
    prompt = f"Create a beautiful artistic profile picture of a person with {hair_color} hair, {eye_color} eyes, and looks {mood}."
    
    # Displaying the prompt to the user
    print("Prompt:", prompt)

    try:
        response = client.images.generate(
            model="dall-e-3",
            prompt=prompt,
            size="1024x1024",  # Choose from "1024x1024", "1024x1792", or "1792x1024"
            quality="standard",  # Choose "standard" or "hd" for higher quality
            n=1  # Number of images to generate
        )
        
        # 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

# Define the Gradio interface
iface = gr.Interface(
    fn=generate_image,
    inputs=[gr.Textbox(label="Hair Color"), gr.Textbox(label="Mood"), gr.Textbox(label="Eye Color")],
    outputs=[gr.Text(label="Prompt"), gr.Image(label="Generated Image")],
    title="Profile Picture Generator",
    description="Enter the hair color, mood, and eye color to generate a profile picture."
)

# Run the Gradio app
iface.launch()