shukdevdatta123 commited on
Commit
19ef599
·
verified ·
1 Parent(s): 34feb65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -17,6 +17,13 @@ if api_key:
17
  # Prompt input field
18
  prompt = st.text_area("Enter your prompt:")
19
 
 
 
 
 
 
 
 
20
  # Variables to store the generated image
21
  image_url = None
22
  image_data = None
@@ -24,7 +31,7 @@ if api_key:
24
  # Button to generate image
25
  if st.button("Generate Image"):
26
  if prompt:
27
- st.write("Generating image with DALL-E 3...")
28
  try:
29
  # Call the OpenAI API to generate the image
30
  response = openai.Image.create(
@@ -32,7 +39,7 @@ if api_key:
32
  prompt=prompt,
33
  n=1, # Number of images to generate
34
  size="1024x1024", # Available sizes: 256x256, 512x512, or 1024x1024
35
- quality="standard" # Specify image quality: "standard" or "hd"
36
  )
37
  image_url = response['data'][0]['url']
38
 
@@ -42,7 +49,6 @@ if api_key:
42
 
43
  # Display the image
44
  st.image(image_url, caption="Generated Image", use_column_width=True)
45
- st.write("Image URL: " + image_url)
46
  except Exception as e:
47
  st.error(f"An error occurred: {e}")
48
  else:
@@ -53,7 +59,7 @@ if api_key:
53
  st.download_button(
54
  label="Download Image",
55
  data=image_data,
56
- file_name="generated_image.png",
57
  mime="image/png"
58
  )
59
  else:
 
17
  # Prompt input field
18
  prompt = st.text_area("Enter your prompt:")
19
 
20
+ # Quality selection dropdown
21
+ quality = st.selectbox(
22
+ "Select image quality:",
23
+ options=["standard", "hd"],
24
+ index=0 # Default to "standard"
25
+ )
26
+
27
  # Variables to store the generated image
28
  image_url = None
29
  image_data = None
 
31
  # Button to generate image
32
  if st.button("Generate Image"):
33
  if prompt:
34
+ st.write(f"Generating {quality}-quality image with DALL-E 3...")
35
  try:
36
  # Call the OpenAI API to generate the image
37
  response = openai.Image.create(
 
39
  prompt=prompt,
40
  n=1, # Number of images to generate
41
  size="1024x1024", # Available sizes: 256x256, 512x512, or 1024x1024
42
+ quality=quality # Use selected quality
43
  )
44
  image_url = response['data'][0]['url']
45
 
 
49
 
50
  # Display the image
51
  st.image(image_url, caption="Generated Image", use_column_width=True)
 
52
  except Exception as e:
53
  st.error(f"An error occurred: {e}")
54
  else:
 
59
  st.download_button(
60
  label="Download Image",
61
  data=image_data,
62
+ file_name=f"generated_image_{quality}.png",
63
  mime="image/png"
64
  )
65
  else: