bluenevus commited on
Commit
0a0bb7f
·
verified ·
1 Parent(s): 5550052

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from openai import OpenAI
3
  import os
 
4
 
5
  # List of popular styles
6
  STYLES = [
@@ -10,6 +11,13 @@ STYLES = [
10
  "Art Nouveau", "Pop Art", "Minimalist"
11
  ]
12
 
 
 
 
 
 
 
 
13
  def enhance_prompt(client, prompt, style):
14
  enhanced_prompt_request = f"Enhance the following prompt for DALL-E 3 image generation in the style of {style}. Make it more detailed and vivid, while keeping the original intent: '{prompt}'"
15
 
@@ -23,14 +31,16 @@ def enhance_prompt(client, prompt, style):
23
 
24
  return response.choices[0].message.content.strip()
25
 
26
- def generate_image(api_key, prompt, style):
27
- client = OpenAI(api_key=api_key)
28
 
29
  enhanced_prompt = enhance_prompt(client, prompt, style)
30
 
 
 
31
  response = client.images.generate(
32
  model="dall-e-3",
33
- prompt=enhanced_prompt,
34
  size="1024x1024",
35
  quality="standard",
36
  n=1
@@ -46,6 +56,7 @@ with gr.Blocks() as demo:
46
  api_key = gr.Textbox(label="OpenAI API Key", type="password")
47
  prompt = gr.Textbox(label="Prompt")
48
  style = gr.Dropdown(label="Style", choices=STYLES)
 
49
  generate_btn = gr.Button("Generate Image")
50
 
51
  with gr.Column(scale=1):
@@ -54,7 +65,7 @@ with gr.Blocks() as demo:
54
 
55
  generate_btn.click(
56
  generate_image,
57
- inputs=[api_key, prompt, style],
58
  outputs=[image_output, enhanced_prompt_output]
59
  )
60
 
 
1
  import gradio as gr
2
  from openai import OpenAI
3
  import os
4
+ import httpx
5
 
6
  # List of popular styles
7
  STYLES = [
 
11
  "Art Nouveau", "Pop Art", "Minimalist"
12
  ]
13
 
14
+ # Default negative prompt
15
+ DEFAULT_NEGATIVE_PROMPT = """
16
+ ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame,
17
+ extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature,
18
+ cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face
19
+ """
20
+
21
  def enhance_prompt(client, prompt, style):
22
  enhanced_prompt_request = f"Enhance the following prompt for DALL-E 3 image generation in the style of {style}. Make it more detailed and vivid, while keeping the original intent: '{prompt}'"
23
 
 
31
 
32
  return response.choices[0].message.content.strip()
33
 
34
+ def generate_image(api_key, prompt, style, negative_prompt):
35
+ client = OpenAI(api_key=api_key, http_client=httpx.Client())
36
 
37
  enhanced_prompt = enhance_prompt(client, prompt, style)
38
 
39
+ full_prompt = f"{enhanced_prompt}\nNegative prompt: {negative_prompt}"
40
+
41
  response = client.images.generate(
42
  model="dall-e-3",
43
+ prompt=full_prompt,
44
  size="1024x1024",
45
  quality="standard",
46
  n=1
 
56
  api_key = gr.Textbox(label="OpenAI API Key", type="password")
57
  prompt = gr.Textbox(label="Prompt")
58
  style = gr.Dropdown(label="Style", choices=STYLES)
59
+ negative_prompt = gr.Textbox(label="Negative Prompt", value=DEFAULT_NEGATIVE_PROMPT)
60
  generate_btn = gr.Button("Generate Image")
61
 
62
  with gr.Column(scale=1):
 
65
 
66
  generate_btn.click(
67
  generate_image,
68
+ inputs=[api_key, prompt, style, negative_prompt],
69
  outputs=[image_output, enhanced_prompt_output]
70
  )
71