mahmoud669 commited on
Commit
1657dc5
·
verified ·
1 Parent(s): 763c5ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -44,18 +44,21 @@ reversed_map = {
44
  16: 'Will Smith'
45
  }
46
  def extract(zip_file, extract_path):
47
- # Create a directory to store extracted images
48
  os.makedirs(extract_path, exist_ok=True)
49
-
50
- # Extract images from the ZIP file
51
  with zipfile.ZipFile(zip_file, 'r') as zip_ref:
52
  zip_ref.extractall(extract_path)
53
-
54
- # Display each image in the extracted directory
55
- image_files = os.listdir(extract_path)
56
- for image_file in image_files:
57
- image_path = os.path.join(extract_path, image_file)
58
- image = Image.open(image_path)
 
 
 
 
 
59
 
60
  model = timm.create_model("rexnet_150", pretrained = True, num_classes = 17)
61
  model.load_state_dict(torch.load('faces_best_model.pth', map_location=torch.device('cpu')))
 
44
  16: 'Will Smith'
45
  }
46
  def extract(zip_file, extract_path):
 
47
  os.makedirs(extract_path, exist_ok=True)
48
+
 
49
  with zipfile.ZipFile(zip_file, 'r') as zip_ref:
50
  zip_ref.extractall(extract_path)
51
+
52
+ for root, dirs, files in os.walk(extract_path):
53
+ for file in files:
54
+ if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif')): # Adjust file extensions as needed
55
+ image_path = os.path.join(root, file)
56
+ try:
57
+ image = Image.open(image_path)
58
+ # Process or display the image here
59
+ image.show()
60
+ except IOError as e:
61
+ print(f"Error opening image {image_path}: {e}")
62
 
63
  model = timm.create_model("rexnet_150", pretrained = True, num_classes = 17)
64
  model.load_state_dict(torch.load('faces_best_model.pth', map_location=torch.device('cpu')))