Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import time
|
| 4 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 5 |
import io
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 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 |
-
#
|
| 35 |
demo = gr.Interface(
|
| 36 |
-
fn=
|
| 37 |
-
inputs=gr.
|
| 38 |
-
outputs=gr.Image(
|
| 39 |
-
|
| 40 |
-
description="
|
| 41 |
-
)
|
| 42 |
|
| 43 |
-
|
| 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()
|
|
|