Akash473 commited on
Commit
f530571
·
1 Parent(s): fe4798f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +202 -149
app.py CHANGED
@@ -36,7 +36,7 @@ def parse_args():
36
  args = parser.parse_args()
37
  return args
38
 
39
- def capture_frame_from_webcam(duration=7):
40
  data_transforms = transforms.Compose([
41
  transforms.Resize((224, 224)),
42
  transforms.ToTensor(),
@@ -108,21 +108,18 @@ class GenderClassifier:
108
 
109
  return predicted_label
110
 
111
- def classify_from_frames(self, frames):
112
- predictions = []
113
-
114
- for frame in frames:
115
- with torch.no_grad():
116
- predictions_frame = self.model(frame.unsqueeze(0))
117
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
118
- predicted_class = torch.argmax(probabilities).item()
119
- predicted_label = self.class_names[predicted_class]
120
- predictions.append(predicted_label)
121
-
122
- # Return a single prediction for the entire video
123
- # You can choose to use the majority vote or any other method to determine the final prediction
124
- final_prediction = max(set(predictions), key=predictions.count)
125
- return final_prediction
126
 
127
 
128
  class WomenHairStyleClassifier:
@@ -162,16 +159,18 @@ class WomenHairStyleClassifier:
162
  predicted_label = self.class_names[predicted_class]
163
 
164
  return predicted_label
165
- def classify_from_frames(self, frames):
166
- predictions = []
167
-
168
- for frame in frames:
169
- with torch.no_grad():
170
- predictions_frame = self.model(frame.unsqueeze(0))
171
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
172
- predicted_class = torch.argmax(probabilities).item()
173
- predicted_label = self.class_names[predicted_class]
174
- predictions.append(predicted_label)
 
 
175
 
176
  # Return a single prediction for the entire video
177
  # You can choose to use the majority vote or any other method to determine the final prediction
@@ -217,21 +216,18 @@ class WomenHairColorClassifier:
217
 
218
  return predicted_label
219
 
220
- def classify_from_frames(self, frames):
221
- predictions = []
222
-
223
- for frame in frames:
224
- with torch.no_grad():
225
- predictions_frame = self.model(frame.unsqueeze(0))
226
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
227
- predicted_class = torch.argmax(probabilities).item()
228
- predicted_label = self.class_names[predicted_class]
229
- predictions.append(predicted_label)
230
-
231
- # Return a single prediction for the entire video
232
- # You can choose to use the majority vote or any other method to determine the final prediction
233
- final_prediction = max(set(predictions), key=predictions.count)
234
- return final_prediction
235
 
236
  # Function to classify beard style
237
  class BeardClassifier:
@@ -269,21 +265,18 @@ class BeardClassifier:
269
  predicted_label = self.class_names[predicted_class]
270
  return predicted_label
271
 
272
- def classify_from_frames(self, frames):
273
- predictions = []
274
-
275
- for frame in frames:
276
- with torch.no_grad():
277
- predictions_frame = self.model(frame.unsqueeze(0))
278
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
279
- predicted_class = torch.argmax(probabilities).item()
280
- predicted_label = self.class_names[predicted_class]
281
- predictions.append(predicted_label)
282
-
283
- # Return a single prediction for the entire video
284
- # You can choose to use the majority vote or any other method to determine the final prediction
285
- final_prediction = max(set(predictions), key=predictions.count)
286
- return final_prediction
287
 
288
 
289
  # Function to classify beard color
@@ -322,21 +315,18 @@ class BeardColorClassifier:
322
  predicted_label = self.class_names[predicted_class]
323
  return predicted_label
324
 
325
- def classify_from_frames(self, frames):
326
- predictions = []
327
-
328
- for frame in frames:
329
- with torch.no_grad():
330
- predictions_frame = self.model(frame.unsqueeze(0))
331
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
332
- predicted_class = torch.argmax(probabilities).item()
333
- predicted_label = self.class_names[predicted_class]
334
- predictions.append(predicted_label)
335
-
336
- # Return a single prediction for the entire video
337
- # You can choose to use the majority vote or any other method to determine the final prediction
338
- final_prediction = max(set(predictions), key=predictions.count)
339
- return final_prediction
340
 
341
 
342
 
@@ -376,22 +366,18 @@ class HairStyleClassifier:
376
  predicted_label = self.class_names[predicted_class]
377
  return predicted_label
378
 
379
- def classify_from_frames(self, frames):
380
- predictions = []
381
-
382
- for frame in frames:
383
- with torch.no_grad():
384
- predictions_frame = self.model(frame.unsqueeze(0))
385
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
386
- predicted_class = torch.argmax(probabilities).item()
387
- predicted_label = self.class_names[predicted_class]
388
- predictions.append(predicted_label)
389
-
390
- # Return a single prediction for the entire video
391
- # You can choose to use the majority vote or any other method to determine the final prediction
392
- final_prediction = max(set(predictions), key=predictions.count)
393
- return final_prediction
394
-
395
 
396
  class MenHairColorClassifier:
397
  def __init__(self, model_path, class_names):
@@ -428,21 +414,18 @@ class MenHairColorClassifier:
428
  predicted_label = self.class_names[predicted_class]
429
  return predicted_label
430
 
431
- def classify_from_frames(self, frames):
432
- predictions = []
433
-
434
- for frame in frames:
435
- with torch.no_grad():
436
- predictions_frame = self.model(frame.unsqueeze(0))
437
- probabilities = torch.nn.functional.softmax(predictions_frame[0], dim=0)
438
- predicted_class = torch.argmax(probabilities).item()
439
- predicted_label = self.class_names[predicted_class]
440
- predictions.append(predicted_label)
441
-
442
- # Return a single prediction for the entire video
443
- # You can choose to use the majority vote or any other method to determine the final prediction
444
- final_prediction = max(set(predictions), key=predictions.count)
445
- return final_prediction
446
 
447
 
448
 
@@ -645,32 +628,120 @@ def generate_funko_figurines(input_image):
645
 
646
  def Igenerate_funko_figurines():
647
 
648
- # Capture video from the webcam for 7 seconds
649
- captured_duration = 5 # Duration in seconds
 
 
 
 
 
 
650
 
 
651
  # Initialize variables to store frames and track time
652
- #frames = []
653
- #start_time = time.time()
654
- frames = capture_frame_from_webcam(duration=5)
655
- # Continuously capture frames for the specified duration
656
- #while (time.time() - start_time) < captured_duration:
657
- # frames.extend(capture_frame_from_webcam())
658
 
 
 
 
 
 
 
 
659
  # Detect and classify gender
660
  gender_classifier = GenderClassifier('Data/FunkoSavedModels/Gender.pt', ['Female', 'Male'])
661
- predicted_gender = gender_classifier.classify_from_frames(frames)
662
 
 
 
 
 
 
663
 
664
- # Process background images and apply beard style and color along with hair style and color
665
- final_images = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
 
667
  if predicted_gender == 'Male':
 
 
668
  background_image_paths = male_background_image_paths
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
  if predicted_gender == 'Female':
670
  background_image_paths = female_background_image_paths
 
 
671
 
672
- for background_image_paths in background_image_paths:
673
- background_image = Image.open(background_image_paths)
 
 
 
 
 
 
 
 
 
 
 
674
  x_coordinate = 90
675
  y_coordinate = 50
676
  add_eyebrow(background_image, 115, 80, "Data/AdobeColorFunko/EyezBrowz/Eyebrow.png")
@@ -682,21 +753,7 @@ def Igenerate_funko_figurines():
682
  x_coordinate = 90
683
  y_coordinate = 50
684
  dummy_eye(background_image, x, y, placeholder_image_path, x_coordinate, y_coordinate)
685
- # Detect and classify beard style
686
- beard_classifier = BeardClassifier('Data/FunkoSavedModels/FunkoResnet18BeardStyle.pt', ['Bandholz', 'CleanShave', 'FullGoatee', 'Moustache', 'RapIndustryStandards', 'ShortBeard'])
687
- predicted_style_label = beard_classifier.classify_from_frames(frames)
688
 
689
- # Detect and classify beard color
690
- beard_color_classifier = BeardColorClassifier('Data/FunkoSavedModels/FunkoResnet18BeardColor.pt', ['Black', 'DarkBrown', 'Ginger', 'LightBrown', 'SaltAndPepper', 'White'])
691
- predicted_color_label = beard_color_classifier.classify_from_frames(frames)
692
-
693
- # Classify hairstyle
694
- hair_style_classifier = HairStyleClassifier('Data/FunkoSavedModels/FunkoResnet18HairStyle.pt', ['Afro', 'Bald', 'Puff', 'Spike'])
695
- predicted_hairStyle_label = hair_style_classifier.classify_from_frames(frames)
696
-
697
- #classify menHairColor
698
- menhair_color_classifier = MenHairColorClassifier('Data/FunkoSavedModels/FunkoResnet18MenHairColor.pt', ['Black', 'DarkBrown', 'Ginger', 'LightBrown', 'SaltAndPepper', 'White'])
699
- predicted_menhairColor_label = menhair_color_classifier.classify_from_frames(frames)
700
  if predicted_style_label == 'Bandholz':
701
  process_image_Beard(background_image, 320,
702
  f"Data/AdobeColorFunko/Beard/Bandholz/{predicted_color_label}.png",
@@ -730,24 +787,24 @@ def Igenerate_funko_figurines():
730
  # Add other conditions for different beard styles
731
 
732
  # Overlay hairstyle
733
- if predicted_hairStyle_label == 'Afro':
734
  process_image_menHair(background_image, 336, 420,
735
- f"Data/AdobeColorFunko/MenHairstyle/Afro/{predicted_menhairColor_label}.png",
736
  41, 76)
737
 
738
- if predicted_hairStyle_label == 'Puff':
739
  process_image_menHair(background_image, 305, 420,
740
- f"Data/AdobeColorFunko/MenHairstyle/Puff/{predicted_menhairColor_label}.png",
741
  56, 68)
742
 
743
- if predicted_hairStyle_label == 'Spike':
744
  process_image_menHair(background_image, 310, 420,
745
- f"Data/AdobeColorFunko/MenHairstyle/Spike/{predicted_menhairColor_label}.png",
746
  52, 70)
747
 
748
- if predicted_hairStyle_label == 'Bald':
749
  process_image_menHair(background_image, 310, 420,
750
- f"Data/AdobeColorFunko/MenHairstyle/Bald/{predicted_menhairColor_label}.png",
751
  67, 120)
752
 
753
 
@@ -758,29 +815,25 @@ def Igenerate_funko_figurines():
758
  x_coordinate = 90
759
  y_coordinate = 50
760
  dummy_eye(background_image, x, y, placeholder_image_path, x_coordinate, y_coordinate)
761
- WomenHairStyle_classifier = WomenHairStyleClassifier('Data/FunkoSavedModels/WomenHairStyle.pt', ['MediumLength', 'ShortHair', 'SidePlait'])
762
- predicted_WomenHairStyle = WomenHairStyle_classifier.classify_from_frames(frames)
763
-
764
- WomenHairColor_classifier = WomenHairColorClassifier('Data/FunkoSavedModels/WomenHairColor.pt', ['Black', 'Brown', 'Ginger', 'White'])
765
- predicted_WomenHairColor = WomenHairColor_classifier.classify_from_frames(frames)
766
- if predicted_WomenHairStyle == 'MediumLength':
767
  process_image_WomanHair(background_image, 300,460,
768
- f"Data/AdobeColorFunko/WomenHairstyle/MediumLength/{predicted_WomenHairColor}.png",
769
  56, 50)
770
 
771
- if predicted_WomenHairStyle == 'ShortHair':
772
  process_image_WomanHair(background_image, 270,460,
773
- f"Data/AdobeColorFunko/WomenHairstyle/ShortHair/{predicted_WomenHairColor}.png",
774
  61, 49)
775
 
776
- if predicted_WomenHairStyle == 'SidePlait':
777
  process_image_WomanHair(background_image, 300,450,
778
- f"Data/AdobeColorFunko/WomenHairstyle/SidePlait/{predicted_WomenHairColor}.png",
779
  54, 56)
780
 
781
 
782
  # Convert the resulting image to base64
783
  buffered = BytesIO()
 
784
  background_image.save(buffered, format="PNG")
785
  #base64_image = base64.b64encode(buffered.getvalue()).decode("utf-8")
786
  final_images.append(background_image)
@@ -795,7 +848,7 @@ with gr.Blocks() as demo:
795
  # Funko POP! Figure Creation
796
  Enabling Streamlined Automation with Artificial Intelligence
797
  """)
798
- imageComponent = gr.Image(type="filepath", height=200, width=200)
799
  with gr.Row():
800
  MyOutputs = [gr.Image(type="pil", label="Generated Image " + str(i + 1), height=300, width=200) for i in range(3)]
801
  submitButton = gr.Button(value="Submit")
 
36
  args = parser.parse_args()
37
  return args
38
 
39
+ def capture_frame_from_webcam(duration=5):
40
  data_transforms = transforms.Compose([
41
  transforms.Resize((224, 224)),
42
  transforms.ToTensor(),
 
108
 
109
  return predicted_label
110
 
111
+ def classify_from_frames(self, image, image_type):
112
+ input_image = None
113
+ if image_type == True:
114
+ input_image = self.preprocess_image(image)
115
+ else:
116
+ input_image = image.unsqueeze(0)
117
+ with torch.no_grad():
118
+ predictions = self.model(input_image)
119
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
120
+ predicted_class = torch.argmax(probabilities).item()
121
+ predicted_label = self.class_names[predicted_class]
122
+ return predicted_label
 
 
 
123
 
124
 
125
  class WomenHairStyleClassifier:
 
159
  predicted_label = self.class_names[predicted_class]
160
 
161
  return predicted_label
162
+ def classify_from_frames(self, image, image_type):
163
+ input_image = None
164
+ if image_type == True:
165
+ input_image = self.preprocess_image(image)
166
+ else:
167
+ input_image = image.unsqueeze(0)
168
+ with torch.no_grad():
169
+ predictions = self.model(input_image)
170
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
171
+ predicted_class = torch.argmax(probabilities).item()
172
+ predicted_label = self.class_names[predicted_class]
173
+ return predicted_label
174
 
175
  # Return a single prediction for the entire video
176
  # You can choose to use the majority vote or any other method to determine the final prediction
 
216
 
217
  return predicted_label
218
 
219
+ def classify_from_frames(self, image, image_type):
220
+ input_image = None
221
+ if image_type == True:
222
+ input_image = self.preprocess_image(image)
223
+ else:
224
+ input_image = image.unsqueeze(0)
225
+ with torch.no_grad():
226
+ predictions = self.model(input_image)
227
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
228
+ predicted_class = torch.argmax(probabilities).item()
229
+ predicted_label = self.class_names[predicted_class]
230
+ return predicted_label
 
 
 
231
 
232
  # Function to classify beard style
233
  class BeardClassifier:
 
265
  predicted_label = self.class_names[predicted_class]
266
  return predicted_label
267
 
268
+ def classify_from_frames(self, image, image_type):
269
+ input_image = None
270
+ if image_type == True:
271
+ input_image = self.preprocess_image(image)
272
+ else:
273
+ input_image = image.unsqueeze(0)
274
+ with torch.no_grad():
275
+ predictions = self.model(input_image)
276
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
277
+ predicted_class = torch.argmax(probabilities).item()
278
+ predicted_label = self.class_names[predicted_class]
279
+ return predicted_label
 
 
 
280
 
281
 
282
  # Function to classify beard color
 
315
  predicted_label = self.class_names[predicted_class]
316
  return predicted_label
317
 
318
+ def classify_from_frames(self, image, image_type):
319
+ input_image = None
320
+ if image_type == True:
321
+ input_image = self.preprocess_image(image)
322
+ else:
323
+ input_image = image.unsqueeze(0)
324
+ with torch.no_grad():
325
+ predictions = self.model(input_image)
326
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
327
+ predicted_class = torch.argmax(probabilities).item()
328
+ predicted_label = self.class_names[predicted_class]
329
+ return predicted_label
 
 
 
330
 
331
 
332
 
 
366
  predicted_label = self.class_names[predicted_class]
367
  return predicted_label
368
 
369
+ def classify_from_frames(self, image, image_type):
370
+ input_image = None
371
+ if image_type == True:
372
+ input_image = self.preprocess_image(image)
373
+ else:
374
+ input_image = image.unsqueeze(0)
375
+ with torch.no_grad():
376
+ predictions = self.model(input_image)
377
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
378
+ predicted_class = torch.argmax(probabilities).item()
379
+ predicted_label = self.class_names[predicted_class]
380
+ return predicted_label
 
 
 
 
381
 
382
  class MenHairColorClassifier:
383
  def __init__(self, model_path, class_names):
 
414
  predicted_label = self.class_names[predicted_class]
415
  return predicted_label
416
 
417
+ def classify_from_frames(self, image, image_type):
418
+ input_image = None
419
+ if image_type == True:
420
+ input_image = self.preprocess_image(image)
421
+ else:
422
+ input_image = image.unsqueeze(0)
423
+ with torch.no_grad():
424
+ predictions = self.model(input_image)
425
+ probabilities = torch.nn.functional.softmax(predictions[0], dim=0)
426
+ predicted_class = torch.argmax(probabilities).item()
427
+ predicted_label = self.class_names[predicted_class]
428
+ return predicted_label
 
 
 
429
 
430
 
431
 
 
628
 
629
  def Igenerate_funko_figurines():
630
 
631
+ predicted_women_hairstyle = None
632
+ predicted_women_haircolor = None
633
+ predicted_gender = None
634
+ predicted_style_label = None
635
+ predicted_color_label = None
636
+ predicted_hairstyle_label = None
637
+ predicted_menhaircolor_label = None
638
+ background_image_paths = None
639
 
640
+ # Capture video from the webcam for 7 seconds
641
  # Initialize variables to store frames and track time
 
 
 
 
 
 
642
 
643
+
644
+ # Classify women hairstyle
645
+ women_hairstyle_classifier = WomenHairStyleClassifier('Data/FunkoSavedModels/WomenHairStyle.pt', ['MediumLength', 'ShortHair', 'SidePlait'])
646
+
647
+ # Classify women hair color
648
+ women_hair_color_classifier = WomenHairColorClassifier('Data/FunkoSavedModels/WomenHairColor.pt', ['Black', 'Brown', 'Ginger', 'White'])
649
+
650
  # Detect and classify gender
651
  gender_classifier = GenderClassifier('Data/FunkoSavedModels/Gender.pt', ['Female', 'Male'])
 
652
 
653
+ # Detect and classify beard style
654
+ beard_classifier = BeardClassifier('Data/FunkoSavedModels/FunkoResnet18BeardStyle.pt', ['Bandholz', 'CleanShave', 'FullGoatee', 'Moustache', 'RapIndustryStandards', 'ShortBeard'])
655
+
656
+ # Detect and classify beard color
657
+ beard_color_classifier = BeardColorClassifier('Data/FunkoSavedModels/FunkoResnet18BeardColor.pt', ['Black', 'DarkBrown', 'Ginger', 'LightBrown', 'SaltAndPepper', 'White'])
658
 
659
+ # Classify hairstyle
660
+ hair_style_classifier = HairStyleClassifier('Data/FunkoSavedModels/FunkoResnet18HairStyle.pt', ['Afro', 'Bald', 'Puff', 'Spike'])
661
+
662
+ #classify menHairColor
663
+ menhair_color_classifier = MenHairColorClassifier('Data/FunkoSavedModels/FunkoResnet18MenHairColor.pt', ['Black', 'DarkBrown', 'Ginger', 'LightBrown', 'SaltAndPepper', 'White'])
664
+
665
+ def predict_male_features_from_frames(frame):
666
+ return [
667
+ beard_classifier.classify_from_frames(image=frame,image_type=False),
668
+ beard_color_classifier.classify_from_frames(image=frame,image_type=False),
669
+ hair_style_classifier.classify_from_frames(image=frame,image_type=False),
670
+ menhair_color_classifier.classify_from_frames(image=frame,image_type=False)
671
+ ]
672
+
673
+ def predict_female_features_from_frames(frame):
674
+ return [
675
+ women_hairstyle_classifier.classify_from_frames(image=frame,image_type=False),
676
+ women_hair_color_classifier.classify_from_frames(image=frame,image_type=False),
677
+ ]
678
+
679
+ def predict_gender_from_frames(frame):
680
+ return gender_classifier.classify_from_frames(image=frame,image_type=False)
681
+
682
+
683
+
684
+ print("Capturing frames")
685
+ frames = capture_frame_from_webcam(duration=7)
686
+ print("Frames captured")
687
+ print("Predictions started")
688
+ # time counting
689
+ gp_start = time.time()
690
+ gender_predictions = map(predict_gender_from_frames, frames)
691
+ gender_counter = Counter(gender_predictions)
692
+ predicted_gender = gender_counter.most_common(1)[0][0]
693
+ # time counting
694
+ gp_end = time.time()
695
+ print(f'Predicted Gender: {predicted_gender} and it took {round(gp_end - gp_start)}s')
696
 
697
  if predicted_gender == 'Male':
698
+ # time counting
699
+ mp_start = time.time()
700
  background_image_paths = male_background_image_paths
701
+
702
+ facial_feature_predictions = map(predict_male_features_from_frames, frames)
703
+ beard_style_counter = Counter()
704
+ beard_color_counter = Counter()
705
+ hair_style_label_counter = Counter()
706
+ menhair_color_counter = Counter()
707
+
708
+
709
+ for pred in facial_feature_predictions:
710
+ beard_style_counter[pred[0]] += 1
711
+ beard_color_counter[pred[1]] += 1
712
+ hair_style_label_counter[pred[2]] += 1
713
+ menhair_color_counter[pred[3]] += 1
714
+
715
+ predicted_style_label = beard_style_counter.most_common(1)[0][0]
716
+ predicted_color_label = beard_color_counter.most_common(1)[0][0]
717
+ predicted_hairstyle_label = hair_style_label_counter.most_common(1)[0][0]
718
+ predicted_menhaircolor_label = menhair_color_counter.most_common(1)[0][0]
719
+ # time counting
720
+ mp_end = time.time()
721
+
722
+
723
+ print("Predictions are:\n")
724
+ print(predicted_style_label,predicted_color_label,predicted_hairstyle_label,predicted_menhaircolor_label)
725
+ print(f'\nand it took {round(mp_end - mp_start)}s')
726
+
727
  if predicted_gender == 'Female':
728
  background_image_paths = female_background_image_paths
729
+ women_hairstyle_counter = women_haircolor_counter = Counter()
730
+ facial_feature_predictions = map(predict_female_features_from_frames, frames)
731
 
732
+ for pred in facial_feature_predictions:
733
+ women_hairstyle_counter[pred[0]] += 1
734
+ women_haircolor_counter[pred[1]] += 1
735
+
736
+ predicted_women_hairstyle = women_hairstyle_counter.most_common(1)[0][0]
737
+ predicted_women_haircolor = women_haircolor_counter.most_common(1)[0][0]
738
+
739
+ # Process background images and apply beard style and color along with hair style and color
740
+ final_images = []
741
+
742
+
743
+ for path in background_image_paths:
744
+ background_image = Image.open(path)
745
  x_coordinate = 90
746
  y_coordinate = 50
747
  add_eyebrow(background_image, 115, 80, "Data/AdobeColorFunko/EyezBrowz/Eyebrow.png")
 
753
  x_coordinate = 90
754
  y_coordinate = 50
755
  dummy_eye(background_image, x, y, placeholder_image_path, x_coordinate, y_coordinate)
 
 
 
756
 
 
 
 
 
 
 
 
 
 
 
 
757
  if predicted_style_label == 'Bandholz':
758
  process_image_Beard(background_image, 320,
759
  f"Data/AdobeColorFunko/Beard/Bandholz/{predicted_color_label}.png",
 
787
  # Add other conditions for different beard styles
788
 
789
  # Overlay hairstyle
790
+ if predicted_hairstyle_label == 'Afro':
791
  process_image_menHair(background_image, 336, 420,
792
+ f"Data/AdobeColorFunko/MenHairstyle/Afro/{predicted_menhaircolor_label}.png",
793
  41, 76)
794
 
795
+ if predicted_hairstyle_label == 'Puff':
796
  process_image_menHair(background_image, 305, 420,
797
+ f"Data/AdobeColorFunko/MenHairstyle/Puff/{predicted_menhaircolor_label}.png",
798
  56, 68)
799
 
800
+ if predicted_hairstyle_label == 'Spike':
801
  process_image_menHair(background_image, 310, 420,
802
+ f"Data/AdobeColorFunko/MenHairstyle/Spike/{predicted_menhaircolor_label}.png",
803
  52, 70)
804
 
805
+ if predicted_hairstyle_label == 'Bald':
806
  process_image_menHair(background_image, 310, 420,
807
+ f"Data/AdobeColorFunko/MenHairstyle/Bald/{predicted_menhaircolor_label}.png",
808
  67, 120)
809
 
810
 
 
815
  x_coordinate = 90
816
  y_coordinate = 50
817
  dummy_eye(background_image, x, y, placeholder_image_path, x_coordinate, y_coordinate)
818
+ if predicted_women_hairstyle == 'MediumLength':
 
 
 
 
 
819
  process_image_WomanHair(background_image, 300,460,
820
+ f"Data/AdobeColorFunko/WomenHairstyle/MediumLength/{predicted_women_haircolor}.png",
821
  56, 50)
822
 
823
+ if predicted_women_hairstyle == 'ShortHair':
824
  process_image_WomanHair(background_image, 270,460,
825
+ f"Data/AdobeColorFunko/WomenHairstyle/ShortHair/{predicted_women_haircolor}.png",
826
  61, 49)
827
 
828
+ if predicted_women_hairstyle == 'SidePlait':
829
  process_image_WomanHair(background_image, 300,450,
830
+ f"Data/AdobeColorFunko/WomenHairstyle/SidePlait/{predicted_women_haircolor}.png",
831
  54, 56)
832
 
833
 
834
  # Convert the resulting image to base64
835
  buffered = BytesIO()
836
+ # background_image.resize((200,400))
837
  background_image.save(buffered, format="PNG")
838
  #base64_image = base64.b64encode(buffered.getvalue()).decode("utf-8")
839
  final_images.append(background_image)
 
848
  # Funko POP! Figure Creation
849
  Enabling Streamlined Automation with Artificial Intelligence
850
  """)
851
+ imageComponent = gr.Image(type="filepath", height=250, width=250)
852
  with gr.Row():
853
  MyOutputs = [gr.Image(type="pil", label="Generated Image " + str(i + 1), height=300, width=200) for i in range(3)]
854
  submitButton = gr.Button(value="Submit")