Rahatara commited on
Commit
233c4fc
·
verified ·
1 Parent(s): 5a3f652

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -16,8 +16,9 @@ def augment_images(image_file, num_duplicates):
16
  horizontal_flip=True,
17
  fill_mode='nearest')
18
 
19
- img = Image.open(image_file).convert('RGB') # Convert to RGB
20
- img = img.resize((256, 256)) # Resize image
 
21
  x = img_to_array(img) # Convert image to numpy array
22
  x = x.reshape((1,) + x.shape) # Reshape for data generator
23
 
@@ -29,7 +30,7 @@ def augment_images(image_file, num_duplicates):
29
  break
30
 
31
  # Zip the augmented images
32
- zip_name = tempfile.mktemp(suffix='.zip')
33
  with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
34
  for root, _, files in os.walk(temp_dir):
35
  for file in files:
@@ -39,7 +40,10 @@ def augment_images(image_file, num_duplicates):
39
 
40
  iface = gr.Interface(
41
  fn=augment_images,
42
- inputs=[gr.Image(label="Upload Image", source="upload"), gr.Slider(minimum=1, maximum=20, default=5, label="Number of Augmented Samples")],
 
 
 
43
  outputs=gr.File(label="Download Augmented Images"),
44
  title="Image Augmentation App",
45
  description="Upload an image to generate augmented versions. Select the number of augmented duplicates you want for the image."
 
16
  horizontal_flip=True,
17
  fill_mode='nearest')
18
 
19
+ # Convert to RGB and resize the image
20
+ img = Image.open(image_file).convert('RGB')
21
+ img = img.resize((256, 256))
22
  x = img_to_array(img) # Convert image to numpy array
23
  x = x.reshape((1,) + x.shape) # Reshape for data generator
24
 
 
30
  break
31
 
32
  # Zip the augmented images
33
+ zip_name = os.path.join(tempfile.gettempdir(), 'augmented_images.zip')
34
  with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
35
  for root, _, files in os.walk(temp_dir):
36
  for file in files:
 
40
 
41
  iface = gr.Interface(
42
  fn=augment_images,
43
+ inputs=[
44
+ gr.Image(tool="editor", label="Upload Image"),
45
+ gr.Slider(minimum=1, maximum=20, default=5, label="Number of Augmented Samples")
46
+ ],
47
  outputs=gr.File(label="Download Augmented Images"),
48
  title="Image Augmentation App",
49
  description="Upload an image to generate augmented versions. Select the number of augmented duplicates you want for the image."