File size: 1,333 Bytes
e24647c 01c5d03 12f0a31 01c5d03 e24647c 01c5d03 e24647c 01c5d03 8aa7053 01c5d03 8aa7053 01c5d03 e24647c 01c5d03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
from tensorflow.keras.preprocessing.image import img_to_array, ImageDataGenerator
from PIL import Image
import numpy as np
import os
import zipfile
import io
# Image Augmentation Function
def augment_images(image_files, num_duplicates):
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
zoom_range=0.2,
fill_mode='nearest')
augmented_images = []
for image_file in image_files:
try:
img = Image.open(image_file).convert('RGB')
img = img.resize((256, 256))
x = img_to_array(img)
x = x.reshape((1,) + x.shape)
i = 0
for _ in datagen.flow(x, batch_size=1):
i += 1
augmented_images.append(x[0])
if i >= num_duplicates:
break
except Exception as e:
print(f"Error processing image: {e}")
return augmented_images
# Gradio UI
demo = gr.Interface(
fn=augment_images,
inputs=gr.File(label="Upload Images", multiple=True, file_types=["jpg", "jpeg", "png"]),
outputs=gr.Image(label="Augmented Images"),
examples=[["images/cat.jpg"], ["images/dog.jpg"]],
description="Image Augmentation App",
allow_flagging=False)
demo.launch() |