AIOmarRehan commited on
Commit
12738f9
·
verified ·
1 Parent(s): 309f9a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -9,7 +9,16 @@ from tensorflow.keras.models import load_model
9
  model = load_model("unet_model.h5", compile=False)
10
 
11
  # Load Hugging Face dataset
12
- dataset = load_dataset("AIOmarRehan/Cropped_Yale_Faces")
 
 
 
 
 
 
 
 
 
13
 
14
  # Preprocess function
15
  def preprocess_image(image, target_size=(192, 176)):
@@ -38,9 +47,10 @@ def add_salt_and_pepper_noise(image, amount=0.05):
38
 
39
  # Prediction function
40
  def predict(img=None, use_dataset=False, add_noise=False):
 
41
  if use_dataset:
42
- # Pick random image from dataset
43
- example = random.choice(dataset["train"])
44
  img = example["image"]
45
 
46
  if img is None:
 
9
  model = load_model("unet_model.h5", compile=False)
10
 
11
  # Load Hugging Face dataset
12
+ dataset = None
13
+
14
+ def get_dataset():
15
+ global dataset
16
+ if dataset is None:
17
+ dataset = load_dataset(
18
+ "AIOmarRehan/Cropped_Yale_Faces",
19
+ trust_remote_code=True
20
+ )
21
+ return dataset
22
 
23
  # Preprocess function
24
  def preprocess_image(image, target_size=(192, 176)):
 
47
 
48
  # Prediction function
49
  def predict(img=None, use_dataset=False, add_noise=False):
50
+
51
  if use_dataset:
52
+ ds = get_dataset()
53
+ example = random.choice(ds["train"])
54
  img = example["image"]
55
 
56
  if img is None: