samcoding5854 commited on
Commit
f0a1f4f
β€’
1 Parent(s): 47acebd

Final Changes

Browse files
{bgImages β†’ Assets/bgImages}/1.jpg RENAMED
File without changes
{bgImages β†’ Assets/bgImages}/2.jpg RENAMED
File without changes
{bgImages β†’ Assets/bgImages}/3.jpg RENAMED
File without changes
{bgImages β†’ Assets/bgImages}/4.jpg RENAMED
File without changes
Assets/output/images/overlay_image.png ADDED
Assets/saved_masks/Screenshot from 2024-05-29 00-48-50.png ADDED
{saved_masks β†’ Assets/saved_masks}/inverted_mask_0.png RENAMED
File without changes
Assets/uploaded_images/Screenshot from 2024-05-29 00-48-50.png ADDED
{uploaded_images β†’ Assets/uploaded_images}/download.png RENAMED
File without changes
Pages/AboutMe.py CHANGED
@@ -1,9 +1,9 @@
1
  import streamlit as st
2
 
3
  def ABOUTUS():
4
- st.title('About Us')
5
  st.write("""
6
- Welcome to our Streamlit app! We are a team of developers passionate about creating
7
  innovative solutions using Streamlit.
8
  """)
9
 
 
1
  import streamlit as st
2
 
3
  def ABOUTUS():
4
+ st.title('About Me')
5
  st.write("""
6
+ Welcome to the Streamlit app for making a photoshoot visual! We are a team of developers passionate about creating
7
  innovative solutions using Streamlit.
8
  """)
9
 
Pages/adScript.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+
4
+ def CREATEAD():
5
+ st.title("Create a script/idea")
6
+
7
+ prompt = st.text_input("Write about product/Advertisement Idea you already have.")
8
+
9
+ if prompt:
10
+
11
+ # Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
12
+ GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
13
+
14
+ genai.configure(api_key=GOOGLE_API_KEY)
15
+
16
+ model = genai.GenerativeModel('gemini-1.5-flash')
17
+
18
+ response = model.generate_content(f"Write a funny short advertisement script for this {prompt}", stream=True)
19
+ response.resolve()
20
+
21
+ st.write(response.text)
22
+
23
+
24
+ if __name__ == "__main__":
25
+ CREATEAD()
26
+
27
+
Pages/bgImages.py CHANGED
@@ -11,14 +11,13 @@ def load_images_from_folder(folder):
11
  images.append(os.path.join(folder, filename))
12
  return images
13
 
14
-
15
  # Main function
16
  def BGIMAGES():
17
  st.title("Background Images")
18
 
19
  st.header('Create a template', divider='orange')
20
 
21
- prompt = st.text_input("Movie title")
22
  if prompt:
23
  # Load the pipeline
24
  with st.spinner("Loading model..."):
@@ -35,7 +34,7 @@ def BGIMAGES():
35
  image = pipeline(image_prompt, generator=generator).images[0]
36
 
37
  # Save the image
38
- output_dir = "bgImages"
39
  os.makedirs(output_dir, exist_ok=True)
40
  image_path = os.path.join(output_dir, f"{prompt}.png")
41
  image.save(image_path)
@@ -46,21 +45,19 @@ def BGIMAGES():
46
  else:
47
  st.write("Please enter a movie title to generate an image.")
48
 
49
-
50
-
51
  # Path to the folder containing images
52
- image_folder = "bgImages"
53
 
54
  # Load images from the folder
55
  images = load_images_from_folder(image_folder)
56
 
57
  # Display images and information in a grid layout with three images per row
58
- col_width = 350 # Adjust this value according to your preference
59
  num_images = len(images)
60
  images_per_row = 3
61
  num_rows = (num_images + images_per_row - 1) // images_per_row
62
 
63
- st.header('Available Templates', divider = 'red')
64
 
65
  # Display images and information in a grid layout with three images per row
66
  for i in range(num_rows):
@@ -68,11 +65,10 @@ def BGIMAGES():
68
  for j in range(images_per_row):
69
  idx = i * images_per_row + j
70
  if idx < num_images:
71
- cols[j].image(images[idx], width=col_width)
72
- cols[j].write(images[idx])
73
-
 
74
 
75
  if __name__ == "__main__":
76
  BGIMAGES()
77
-
78
-
 
11
  images.append(os.path.join(folder, filename))
12
  return images
13
 
 
14
  # Main function
15
  def BGIMAGES():
16
  st.title("Background Images")
17
 
18
  st.header('Create a template', divider='orange')
19
 
20
+ prompt = st.text_input("Prompt for a Background")
21
  if prompt:
22
  # Load the pipeline
23
  with st.spinner("Loading model..."):
 
34
  image = pipeline(image_prompt, generator=generator).images[0]
35
 
36
  # Save the image
37
+ output_dir = "Assets/bgImages"
38
  os.makedirs(output_dir, exist_ok=True)
39
  image_path = os.path.join(output_dir, f"{prompt}.png")
40
  image.save(image_path)
 
45
  else:
46
  st.write("Please enter a movie title to generate an image.")
47
 
 
 
48
  # Path to the folder containing images
49
+ image_folder = "Assets/bgImages"
50
 
51
  # Load images from the folder
52
  images = load_images_from_folder(image_folder)
53
 
54
  # Display images and information in a grid layout with three images per row
55
+ col_width = 350 # Adjust this value according to your preference
56
  num_images = len(images)
57
  images_per_row = 3
58
  num_rows = (num_images + images_per_row - 1) // images_per_row
59
 
60
+ st.header('Available Templates', divider='red')
61
 
62
  # Display images and information in a grid layout with three images per row
63
  for i in range(num_rows):
 
65
  for j in range(images_per_row):
66
  idx = i * images_per_row + j
67
  if idx < num_images:
68
+ image_path = images[idx]
69
+ image_name = os.path.splitext(os.path.basename(image_path))[0] # Get the file name without extension
70
+ cols[j].image(image_path, width=col_width)
71
+ cols[j].write(image_name)
72
 
73
  if __name__ == "__main__":
74
  BGIMAGES()
 
 
Pages/createVideo.py CHANGED
@@ -12,13 +12,13 @@ def CREATEGIF():
12
  )
13
  pipeline.enable_model_cpu_offload()
14
 
15
- image = load_image("output/overlay_image.png")
16
  image = image.resize((1024, 576))
17
 
18
  generator = torch.manual_seed(42)
19
  frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
20
- export_to_video(frames, "output/generated.mp4", fps=7)
21
- video_file = open('output/generated.mp4', 'rb')
22
  video_bytes = video_file.read()
23
 
24
  st.video(video_bytes)
 
12
  )
13
  pipeline.enable_model_cpu_offload()
14
 
15
+ image = load_image("Assets/output/images/overlay_image.png")
16
  image = image.resize((1024, 576))
17
 
18
  generator = torch.manual_seed(42)
19
  frames = pipeline(image, decode_chunk_size=8, generator=generator).frames[0]
20
+ export_to_video(frames, "Assets/output/videos/generated.mp4", fps=7)
21
+ video_file = open('Assets/output/videos/generated.mp4', 'rb')
22
  video_bytes = video_file.read()
23
 
24
  st.video(video_bytes)
Pages/createVisual.py CHANGED
@@ -8,14 +8,14 @@ def CREATEVISUALS():
8
  st.title("Create photoshoot visual")
9
 
10
  # Set the directory where the uploaded images will be saved
11
- UPLOAD_DIR = 'uploaded_images'
12
 
13
  # Create the directory if it doesn't exist
14
  if not os.path.exists(UPLOAD_DIR):
15
  os.makedirs(UPLOAD_DIR)
16
 
17
  # Streamlit app title
18
- st.header("Image Upload and Save App")
19
 
20
  # File uploader allows user to upload an image
21
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
 
8
  st.title("Create photoshoot visual")
9
 
10
  # Set the directory where the uploaded images will be saved
11
+ UPLOAD_DIR = 'Assets/uploaded_images'
12
 
13
  # Create the directory if it doesn't exist
14
  if not os.path.exists(UPLOAD_DIR):
15
  os.makedirs(UPLOAD_DIR)
16
 
17
  # Streamlit app title
18
+ st.header("Upload image")
19
 
20
  # File uploader allows user to upload an image
21
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
Pages/createdVisuals.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+
4
+ def load_images_from_folder(folder):
5
+ images = []
6
+ for filename in os.listdir(folder):
7
+ if filename.endswith(".jpg") or filename.endswith(".png"):
8
+ images.append(os.path.join(folder, filename))
9
+ return images
10
+
11
+
12
+ # Main function
13
+ def CREATEDIMAGES():
14
+ st.title("Created Images")
15
+
16
+ # Path to the folder containing images
17
+ image_folder = "Assets/output/images"
18
+
19
+ # Load images from the folder
20
+ images = load_images_from_folder(image_folder)
21
+
22
+ # Display images and information in a grid layout with three images per row
23
+ col_width = 350 # Adjust this value according to your preference
24
+ num_images = len(images)
25
+ images_per_row = 3
26
+ num_rows = (num_images + images_per_row - 1) // images_per_row
27
+
28
+ st.header('Available Templates', divider = 'red')
29
+
30
+ # Display images and information in a grid layout with three images per row
31
+ for i in range(num_rows):
32
+ cols = st.columns(images_per_row)
33
+ for j in range(images_per_row):
34
+ idx = i * images_per_row + j
35
+ if idx < num_images:
36
+ cols[j].image(images[idx], width=col_width)
37
+ cols[j].write(images[idx])
38
+
39
+
40
+ if __name__ == "__main__":
41
+ CREATEDIMAGES()
42
+
43
+
Pages/imageBB.py CHANGED
@@ -51,7 +51,7 @@ def run(img_path):
51
  rects = st_img_label(resized_img, box_color="red", rects=st.session_state.rects)
52
  st.session_state.rects = rects
53
  else:
54
- st.image(resized_img, caption="Annotated Image",width=300, use_column_width=True)
55
 
56
  for rect in st.session_state.rects:
57
  # st.write(f"Rectangle: {rect}")
@@ -60,7 +60,7 @@ def run(img_path):
60
 
61
  masks = get_masks(rect,img_path)
62
 
63
- save_dir = "saved_masks"
64
  if not os.path.exists(save_dir):
65
  os.makedirs(save_dir)
66
 
@@ -71,7 +71,7 @@ def run(img_path):
71
 
72
  print(f"Inverted masks saved to directory: {save_dir}")
73
 
74
- image_files = [f for f in os.listdir("bgImages") if os.path.isfile(os.path.join("bgImages", f))]
75
 
76
  st.header("Template Selection")
77
  # Create a dropdown with the list of image files
@@ -79,7 +79,7 @@ def run(img_path):
79
 
80
  if selected_image:
81
  # Display the selected image
82
- image_pathBG = os.path.join("bgImages", selected_image)
83
  image = Image.open(image_pathBG)
84
  st.image(image, width=300, caption=f"Selected image: {selected_image}")
85
 
@@ -153,7 +153,7 @@ def run(img_path):
153
  overlay_image[:, :, 3] = np.clip(overlay[:, :, 3] + background_bgra[:, :, 3], 0, 255)
154
 
155
  # Save the result
156
- output_path = 'output/overlay_image.png'
157
  cv2.imwrite(output_path, overlay_image)
158
 
159
  # Display the overlay image
 
51
  rects = st_img_label(resized_img, box_color="red", rects=st.session_state.rects)
52
  st.session_state.rects = rects
53
  else:
54
+ st.image(resized_img, caption="Uploaded Image",width=300, use_column_width=True)
55
 
56
  for rect in st.session_state.rects:
57
  # st.write(f"Rectangle: {rect}")
 
60
 
61
  masks = get_masks(rect,img_path)
62
 
63
+ save_dir = "Assets/saved_masks"
64
  if not os.path.exists(save_dir):
65
  os.makedirs(save_dir)
66
 
 
71
 
72
  print(f"Inverted masks saved to directory: {save_dir}")
73
 
74
+ image_files = [f for f in os.listdir("Assets/bgImages") if os.path.isfile(os.path.join("Assets/bgImages", f))]
75
 
76
  st.header("Template Selection")
77
  # Create a dropdown with the list of image files
 
79
 
80
  if selected_image:
81
  # Display the selected image
82
+ image_pathBG = os.path.join("Assets/bgImages", selected_image)
83
  image = Image.open(image_pathBG)
84
  st.image(image, width=300, caption=f"Selected image: {selected_image}")
85
 
 
153
  overlay_image[:, :, 3] = np.clip(overlay[:, :, 3] + background_bgra[:, :, 3], 0, 255)
154
 
155
  # Save the result
156
+ output_path = 'Assets/output/images/overlay_image.png'
157
  cv2.imwrite(output_path, overlay_image)
158
 
159
  # Display the overlay image
Pages/objectRecognize.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import PIL.Image
2
+ import streamlit as st
3
+ import google.generativeai as genai
4
+ import os
5
+ from PIL import Image
6
+
7
+ def DETECTIMAGE():
8
+ st.title("Create photoshoot visual")
9
+
10
+ # Set the directory where the uploaded images will be saved
11
+ UPLOAD_DIR = 'Assets/uploaded_images'
12
+
13
+ # Create the directory if it doesn't exist
14
+ if not os.path.exists(UPLOAD_DIR):
15
+ os.makedirs(UPLOAD_DIR)
16
+
17
+ # Streamlit app title
18
+ st.header("Upload Image")
19
+
20
+ # File uploader allows user to upload an image
21
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
+
23
+ if uploaded_file is not None:
24
+ with st.spinner('Processing the image...'):
25
+ # Open the uploaded image
26
+ image = Image.open(uploaded_file)
27
+
28
+ # Save the uploaded image to the specified directory
29
+ image_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
30
+ image.save(image_path)
31
+
32
+ img = PIL.Image.open(image_path)
33
+ st.image(img, caption="Uploaded Image")
34
+
35
+ # Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
36
+ GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
37
+
38
+ genai.configure(api_key=GOOGLE_API_KEY)
39
+
40
+ model = genai.GenerativeModel('gemini-1.5-flash')
41
+
42
+ # Generate content
43
+ response = model.generate_content(["Is the image anything from this list? (Shoe,Sneaker, Bottle, Cup, Sandal, Perfume, Toy, Sunglasses, Car, Water Bottle,Chair, Office Chair, Can, Cap, Hat, Couch, Wristwatch, Glass, Bag, Handbag, Baggage, Suitcase, Headphones, Jar, Vase) If yes then give only the object name, if no simply say 'Not Recognized' and dont give any fullstop at the end.", img], stream=True)
44
+ response.resolve()
45
+
46
+ st.subheader(f"Output: {response.text}")
47
+
48
+ if __name__ == "__main__":
49
+ DETECTIMAGE()
Pages/utils.py DELETED
File without changes
app.py CHANGED
@@ -3,7 +3,10 @@ import streamlit as st
3
  from Pages.createVisual import CREATEVISUALS
4
  from Pages.AboutMe import ABOUTUS
5
  from Pages.bgImages import BGIMAGES
 
6
  from Pages.createVideo import CREATEGIF
 
 
7
 
8
 
9
  st.set_page_config(
@@ -13,19 +16,24 @@ st.set_page_config(
13
  initial_sidebar_state="expanded" # 'auto', 'expanded', 'collapsed'
14
  )
15
 
 
 
 
16
 
17
- def MAIN():
 
 
 
 
 
 
 
18
 
19
- folder_Command = "mkdir -p weights"
20
-
21
- # Define the download command
22
- download_command = "wget -q https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth -P weights"
23
-
24
- # Execute the command
25
-
26
- os.system(folder_Command)
27
-
28
- os.system(download_command)
29
 
30
  # Verify the file is downloaded
31
  file_path = os.path.expanduser("~/weights/sam_vit_h_4b8939.pth")
@@ -37,7 +45,7 @@ def MAIN():
37
  # Rest of your application code
38
 
39
  st.sidebar.title('LumiereIQ')
40
- app = st.sidebar.selectbox('', ['Create Visuals','Background Images','Create Video', 'About Me'])
41
  if app == "Create Visuals":
42
  CREATEVISUALS()
43
  elif app == "About Me":
@@ -46,6 +54,11 @@ def MAIN():
46
  BGIMAGES()
47
  elif app == "Create Video":
48
  CREATEGIF()
49
-
 
 
 
 
 
50
 
51
  MAIN()
 
3
  from Pages.createVisual import CREATEVISUALS
4
  from Pages.AboutMe import ABOUTUS
5
  from Pages.bgImages import BGIMAGES
6
+ from Pages.createdVisuals import CREATEDIMAGES
7
  from Pages.createVideo import CREATEGIF
8
+ from Pages.objectRecognize import DETECTIMAGE
9
+ from Pages.adScript import CREATEAD
10
 
11
 
12
  st.set_page_config(
 
16
  initial_sidebar_state="expanded" # 'auto', 'expanded', 'collapsed'
17
  )
18
 
19
+ def MAIN():
20
+ weights_dir = 'weights'
21
+ weights_file = os.path.join(weights_dir, 'sam_vit_h_4b8939.pth')
22
 
23
+ # Check if the weights file already exists
24
+ if not os.path.exists(weights_file):
25
+ # Create the directory if it doesn't exist
26
+ if not os.path.exists(weights_dir):
27
+ os.makedirs(weights_dir)
28
+
29
+ # Define the download command
30
+ download_command = f"wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth -P {weights_dir}"
31
 
32
+ # Execute the download command
33
+ os.system(download_command)
34
+ print("Weights downloaded.")
35
+ else:
36
+ print("Weights file already exists. No download needed.")
 
 
 
 
 
37
 
38
  # Verify the file is downloaded
39
  file_path = os.path.expanduser("~/weights/sam_vit_h_4b8939.pth")
 
45
  # Rest of your application code
46
 
47
  st.sidebar.title('LumiereIQ')
48
+ app = st.sidebar.selectbox('', ['Create Visuals','Background Images','Recognize Object', 'Create Script', 'Created Images','Create Video', 'About Me'])
49
  if app == "Create Visuals":
50
  CREATEVISUALS()
51
  elif app == "About Me":
 
54
  BGIMAGES()
55
  elif app == "Create Video":
56
  CREATEGIF()
57
+ elif app == "Created Images":
58
+ CREATEDIMAGES()
59
+ elif app == "Recognize Object":
60
+ DETECTIMAGE()
61
+ elif app == "Create Script":
62
+ CREATEAD()
63
 
64
  MAIN()
output/overlay_image.png DELETED
Binary file (79.8 kB)
 
requirements.txt CHANGED
@@ -8,3 +8,4 @@ roboflow
8
  dataclasses-json
9
  supervision
10
  torchvision
 
 
8
  dataclasses-json
9
  supervision
10
  torchvision
11
+ google-generativeai