Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,28 @@
|
|
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
|
6 |
-
import zipfile
|
7 |
-
import io
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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 |
-
|
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()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import numpy as np
|
3 |
+
import time
|
|
|
|
|
4 |
|
5 |
+
def sepia(input_img, num_copies):
|
6 |
+
sepia_filter = np.array([
|
7 |
+
[0.393, 0.769, 0.189],
|
8 |
+
[0.349, 0.686, 0.168],
|
9 |
+
[0.272, 0.534, 0.131]
|
10 |
+
])
|
11 |
+
# Normalize input image to 0-1 range
|
12 |
+
input_img = input_img / 255.0
|
13 |
+
sepia_img = np.dot(input_img[...,:3], sepia_filter.T)
|
14 |
+
sepia_img = np.clip(sepia_img, 0, 1)
|
15 |
+
|
16 |
+
# Iterate to yield multiple sepia images
|
17 |
+
for _ in range(num_copies):
|
18 |
+
# Simulating a delay for demonstration, you might not need this
|
19 |
+
time.sleep(1)
|
20 |
+
yield (sepia_img * 255).astype(np.uint8)
|
21 |
|
22 |
+
demo = gr.Interface(fn=sepia,
|
23 |
+
inputs=[gr.Image(), gr.Number(label="Number of Copies", default=1)],
|
24 |
+
outputs=gr.Image(type="numpy", label="Sepia Image"),
|
25 |
+
title="Sepia Tone Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
if __name__ == "__main__":
|
28 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|