Spaces:
Running
Running
Fix error
Browse files5 unmodified lines6789101112131415161718192021222324252627281 unmodified line3031323334353637383940414243444546474849505152535455565758596061626364656667685 unmodified lines# Load environment variables from the .env fileload_dotenv()# Ensure the OPENAI_API_KEY environment variable is set; it's automagically loaded into the clientclient = OpenAI()if client.api_key is None:raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")# Load the APP_PASSWORD from the environmentAPP_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 inputprompt = 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 userprint("Prompt:", prompt)try:1 unmodified linemodel="dall-e-3",prompt=prompt,size="1024x1024",quality="standard",n=1)# Get the image URL from the responseimage_url = response.data[0].urlreturn prompt, image_urlexcept Exception as e:print("An error occurred:", e)return "An error occurred while generating the image.", Nonehair_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 interfaceiface = 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 appiface.launch()5 unmodified lines678910111213141516171819202122232425261 unmodified line28293031323334353637383940414243444546474849505152535455565758596061626364655 unmodified lines# Load environment variables from the .env fileload_dotenv()client = OpenAI()if client.api_key is None:raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")APP_PASSWORD = os.getenv("APP_PASSWORD")def generate_image(hair_color, eye_color, person, age, style, password):if password != APP_PASSWORD:return "Incorrect password.", Noneprompt = (f"Create a beautiful artistic profile picture of a smiling "f"{age} year-old {person} with {hair_color} hair, {eye_color} eyes. "f"Style: {style}.")print("Prompt:", prompt)try:1 unmodified linemodel="dall-e-3",prompt=prompt,size="1024x1024",n=1)image_url = response.data[0].urlreturn prompt, image_urlexcept Exception as e:print("An error occurred:", e)return "An error occurred while generating the image.", Nonehair_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"]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),gr.Dropdown(choices=style_options, label="Style"),gr.Textbox(label="Password", type="password"),],outputs=[gr.Textbox(label="Prompt"),gr.Image(label="Generated Image")],title="Profile Picture Generator",description="Enter the attributes for your profile picture.",concurrency_limit=1)if __name__ == "__main__":iface.launch()
app.py+20-23