Spaces:
Running
Running
Tobias Geisler
commited on
Commit
·
cf7cca5
1
Parent(s):
da70a8d
app init
Browse files- app.py +45 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Ensure the OPENAI_API_KEY environment variable is set
|
| 6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
+
|
| 8 |
+
if openai.api_key is None:
|
| 9 |
+
raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")
|
| 10 |
+
|
| 11 |
+
def generate_image(hair_color, mood, eye_color):
|
| 12 |
+
# Constructing the prompt based on user input
|
| 13 |
+
prompt = f"Create a beautiful artistic profile picture of a person with {hair_color} hair, {eye_color} eyes, and looks {mood}."
|
| 14 |
+
|
| 15 |
+
# Displaying the prompt to the user
|
| 16 |
+
print("Prompt:", prompt)
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
response = openai.ImageGeneration.create(
|
| 20 |
+
model="dall-e-3",
|
| 21 |
+
prompt=prompt,
|
| 22 |
+
size="512x512", # Choose from "1024x1024", "1024x1792", or "1792x1024"
|
| 23 |
+
quality="standard", # Choose "standard" or "hd" for higher quality
|
| 24 |
+
n=1 # Number of images to generate
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Get the image URL from the response
|
| 28 |
+
image_url = response['data'][0]['url']
|
| 29 |
+
|
| 30 |
+
return prompt, image_url
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print("An error occurred:", e)
|
| 33 |
+
return "An error occurred while generating the image.", None
|
| 34 |
+
|
| 35 |
+
# Define the Gradio interface
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=generate_image,
|
| 38 |
+
inputs=[gr.Textbox(label="Hair Color"), gr.Textbox(label="Mood"), gr.Textbox(label="Eye Color")],
|
| 39 |
+
outputs=[gr.Text(label="Prompt"), gr.Image(label="Generated Image")],
|
| 40 |
+
title="Profile Picture Generator",
|
| 41 |
+
description="Enter the hair color, mood, and eye color to generate a profile picture."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Run the Gradio app
|
| 45 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
gradio
|