Rahatara commited on
Commit
01c5d03
1 Parent(s): 8aa7053

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -36
app.py CHANGED
@@ -1,44 +1,45 @@
1
  import gradio as gr
2
- import numpy as np
3
- import time
4
  from PIL import Image
 
 
 
5
  import io
6
 
7
- def sepia(input_img):
8
- """
9
- Applies a sepia filter to the input image.
10
- """
11
- sepia_filter = np.array([
12
- [0.393, 0.769, 0.189],
13
- [0.349, 0.686, 0.168],
14
- [0.272, 0.534, 0.131]
15
- ])
16
- sepia_img = input_img.dot(sepia_filter.T)
17
- sepia_img /= sepia_img.max()
18
- return sepia_img
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- def fake_diffusion_and_sepia(steps):
21
- """
22
- A generator function that simulates a fake diffusion process for a specified number of steps.
23
- After the final step, applies a sepia filter to the image.
24
- """
25
- rng = np.random.default_rng()
26
- for i in range(steps):
27
- # Simulate the diffusion process
28
- time.sleep(1) # Wait to simulate processing time
29
- image = rng.random(size=(256, 256, 3)) # Generate a random image
30
- if i == steps - 1: # Apply sepia filter on the last step
31
- image = sepia(image)
32
- yield image
33
 
34
- # Define Gradio interface
35
  demo = gr.Interface(
36
- fn=fake_diffusion_and_sepia,
37
- inputs=gr.Slider(minimum=1, maximum=10, default=5, step=1, label="Number of Steps"),
38
- outputs=gr.Image(type="numpy", label="Sepia Image"),
39
- title="Fake Diffusion with Sepia Filter",
40
- description="Generates a series of images simulating a diffusion process. The final image is processed with a sepia filter."
41
- )
42
 
43
- if __name__ == "__main__":
44
- demo.launch()
 
1
  import gradio as gr
2
+ from tensorflow.keras.preprocessing.image import img_to_array, ImageDataGenerator
 
3
  from PIL import Image
4
+ import numpy as np
5
+ import os
6
+ import zipfile
7
  import io
8
 
9
+ # Image Augmentation Function
10
+ def augment_images(image_files, num_duplicates):
11
+ datagen = ImageDataGenerator(
12
+ rotation_range=40,
13
+ width_shift_range=0.2,
14
+ height_shift_range=0.2,
15
+ zoom_range=0.2,
16
+ fill_mode='nearest')
17
+
18
+ augmented_images = []
19
+ for image_file in image_files:
20
+ try:
21
+ img = Image.open(image_file).convert('RGB')
22
+ img = img.resize((256, 256))
23
+ x = img_to_array(img)
24
+ x = x.reshape((1,) + x.shape)
25
+ i = 0
26
+ for _ in datagen.flow(x, batch_size=1):
27
+ i += 1
28
+ augmented_images.append(x[0])
29
+ if i >= num_duplicates:
30
+ break
31
+ except Exception as e:
32
+ print(f"Error processing image: {e}")
33
 
34
+ return augmented_images
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ # Gradio UI
37
  demo = gr.Interface(
38
+ fn=augment_images,
39
+ inputs=gr.File(label="Upload Images", multiple=True, file_types=["jpg", "jpeg", "png"]),
40
+ outputs=gr.Image(label="Augmented Images"),
41
+ examples=[["images/cat.jpg"], ["images/dog.jpg"]],
42
+ description="Image Augmentation App",
43
+ allow_flagging=False)
44
 
45
+ demo.launch()