Tobias Geisler commited on
Commit
a68a3ae
·
1 Parent(s): d47fc51

add queuing and password

Browse files
Files changed (2) hide show
  1. app.py +16 -4
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,6 +1,10 @@
1
- from openai import OpenAI
2
  import os
 
3
  import gradio as gr
 
 
 
 
4
 
5
  # Ensure the OPENAI_API_KEY environment variable is set; it's automagically loaded into the client
6
  client = OpenAI()
@@ -8,7 +12,13 @@ client = OpenAI()
8
  if client.api_key is None:
9
  raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")
10
 
11
- def generate_image(hair_color, eye_color, person, age, style):
 
 
 
 
 
 
12
  # Constructing the prompt based on user input
13
  prompt = f"Create a beautiful artistic profile picture of a smiling {age} year-old {person} with {hair_color} hair, {eye_color} eyes. Style: {style}."
14
 
@@ -45,11 +55,13 @@ iface = gr.Interface(
45
  gr.Dropdown(choices=eye_color_options, label="Eye Color"),
46
  gr.Dropdown(choices=person_options, label="Person"),
47
  gr.Number(label="Age", value=12, minimum=8, maximum=120, step=1, precision=0),
48
- gr.Dropdown(choices=style_options, label="style"),
 
49
  ],
50
  outputs=[gr.Text(label="Prompt"), gr.Image(label="Generated Image")],
51
  title="Profile Picture Generator",
52
- description="Enter the attributes for your profile picture."
 
53
  )
54
 
55
  # Run the Gradio app
 
 
1
  import os
2
+ from openai import OpenAI
3
  import gradio as gr
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from the .env file
7
+ load_dotenv()
8
 
9
  # Ensure the OPENAI_API_KEY environment variable is set; it's automagically loaded into the client
10
  client = OpenAI()
 
12
  if client.api_key is None:
13
  raise ValueError("Die Umgebungsvariable OPENAI_API_KEY ist nicht gesetzt.")
14
 
15
+ # Load the APP_PASSWORD from the environment
16
+ APP_PASSWORD = os.getenv("APP_PASSWORD")
17
+
18
+ def generate_image(hair_color, eye_color, person, age, style, password):
19
+ if password != APP_PASSWORD:
20
+ return "Incorrect password.", None
21
+
22
  # Constructing the prompt based on user input
23
  prompt = f"Create a beautiful artistic profile picture of a smiling {age} year-old {person} with {hair_color} hair, {eye_color} eyes. Style: {style}."
24
 
 
55
  gr.Dropdown(choices=eye_color_options, label="Eye Color"),
56
  gr.Dropdown(choices=person_options, label="Person"),
57
  gr.Number(label="Age", value=12, minimum=8, maximum=120, step=1, precision=0),
58
+ gr.Dropdown(choices=style_options, label="Style"),
59
+ gr.Textbox(label="Password", type="password"),
60
  ],
61
  outputs=[gr.Text(label="Prompt"), gr.Image(label="Generated Image")],
62
  title="Profile Picture Generator",
63
+ description="Enter the attributes for your profile picture.",
64
+ queue=True # Enable queuing for the image generation process
65
  )
66
 
67
  # Run the Gradio app
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  openai
2
- gradio
 
 
1
  openai
2
+ gradio
3
+ python-dotenv