bizvideoschool commited on
Commit
c3fad62
1 Parent(s): 9a83149

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -7,28 +7,37 @@ from io import BytesIO
7
  # Set up the OpenAI API key from Hugging Face Spaces secrets
8
  openai.api_key = st.secrets["OPENAI_API_KEY"]
9
 
10
- st.title("Background Image Generator for Real Estate Videos")
11
 
12
- # User inputs
13
- image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your image (e.g., modern living room)")
14
- color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., warm, cool)")
15
- additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image?")
16
- image_style = st.selectbox("Image Style", ["vivid", "natural"], index=0) # Select between vivid and natural styles
17
- image_quality = st.selectbox("Image Quality", ["standard", "hd"], index=0) # Select between standard and HD quality
 
 
 
 
 
 
 
 
 
 
18
 
19
  if st.button('Generate Image'):
20
  # Construct the prompt
21
- prompt = f"Create an image with the theme: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."
22
 
23
  # Call the DALL-E API
24
  try:
25
  response = openai.Image.create(
26
  model="dall-e-3", # Specify DALL-E 3 model
27
  prompt=prompt,
28
- n=1, # Number of images to generate
29
- size="1024x1024", # Image dimensions
30
- quality=image_quality, # Image quality parameter
31
- style=image_style # Image style parameter
32
  )
33
 
34
  # Assuming the response contains a URL to the image
@@ -39,7 +48,7 @@ if st.button('Generate Image'):
39
  image = Image.open(BytesIO(image_response.content))
40
 
41
  # Display the image
42
- st.image(image, caption='Generated Image')
43
 
44
  except Exception as e:
45
  st.error(f"An error occurred: {e}")
 
7
  # Set up the OpenAI API key from Hugging Face Spaces secrets
8
  openai.api_key = st.secrets["OPENAI_API_KEY"]
9
 
10
+ st.title("Holiday Video Backdrop Image Generator")
11
 
12
+ # User inputs for image generation
13
+ image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your holiday video backdrop (e.g., festive living room, snowy landscape)")
14
+ color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., red and green, white and blue)")
15
+ additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image (e.g., Christmas tree, snowflakes)")
16
+
17
+ # Dropdown for selecting image dimensions
18
+ video_format = st.selectbox("Video Format", ["16:9 (Standard HD - 1920x1080)", "16:9 (4K - 3840x2160)", "1:1 (Square - 1080x1080)", "4:5 (Portrait - 1080x1350)", "9:16 (Tall - 1080x1920)"])
19
+
20
+ # Mapping formats to DALL-E API size parameters
21
+ format_size_mapping = {
22
+ "16:9 (Standard HD - 1920x1080)": "1024x576", # Closest available size in DALL-E for 1080p
23
+ "16:9 (4K - 3840x2160)": "1792x1024", # Closest available size in DALL-E for 4K
24
+ "1:1 (Square - 1080x1080)": "1024x1024",
25
+ "4:5 (Portrait - 1080x1350)": "1024x1792", # Closest available vertical size
26
+ "9:16 (Tall - 1080x1920)": "1024x1792" # Closest available vertical size
27
+ }
28
 
29
  if st.button('Generate Image'):
30
  # Construct the prompt
31
+ prompt = f"A holiday-themed backdrop image depicting: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."
32
 
33
  # Call the DALL-E API
34
  try:
35
  response = openai.Image.create(
36
  model="dall-e-3", # Specify DALL-E 3 model
37
  prompt=prompt,
38
+ n=1,
39
+ size=format_size_mapping[video_format], # Set image dimensions based on selected video format
40
+ quality="hd" # Set image quality to high definition
 
41
  )
42
 
43
  # Assuming the response contains a URL to the image
 
48
  image = Image.open(BytesIO(image_response.content))
49
 
50
  # Display the image
51
+ st.image(image, caption='Generated Holiday Backdrop Image')
52
 
53
  except Exception as e:
54
  st.error(f"An error occurred: {e}")