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()