import gradio as gr | |
import numpy as np | |
import time | |
def sepia(input_img, num_copies): | |
sepia_filter = np.array([ | |
[0.393, 0.769, 0.189], | |
[0.349, 0.686, 0.168], | |
[0.272, 0.534, 0.131] | |
]) | |
# Normalize input image to 0-1 range | |
input_img = input_img / 255.0 | |
sepia_img = np.dot(input_img[...,:3], sepia_filter.T) | |
sepia_img = np.clip(sepia_img, 0, 1) | |
# Iterate to yield multiple sepia images | |
for _ in range(num_copies): | |
# Simulating a delay for demonstration, you might not need this | |
time.sleep(1) | |
yield (sepia_img * 255).astype(np.uint8) | |
demo = gr.Interface(fn=sepia, | |
inputs=[gr.Image(), gr.Number()], | |
outputs="image", | |
title="Sepia Tone Generator") | |
if __name__ == "__main__": | |
demo.launch() | |