Rahatara commited on
Commit
c9c84b0
·
verified ·
1 Parent(s): 5cb46bd

Delete App.py

Browse files
Files changed (1) hide show
  1. App.py +0 -43
App.py DELETED
@@ -1,43 +0,0 @@
1
- from pathlib import Path
2
- import gradio as gr
3
- import numpy as np
4
- from zipfile import ZipFile
5
-
6
- def sepia(input_img, num_copies):
7
- sepia_filter = np.array([
8
- [0.393, 0.769, 0.189],
9
- [0.349, 0.686, 0.168],
10
- [0.272, 0.534, 0.131]
11
- ])
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) * 255
15
- sepia_imgs = [(sepia_img).astype(np.uint8) for _ in range(num_copies)]
16
- return sepia_imgs
17
-
18
- def zip_sepia_images(sepia_imgs):
19
- temp_dir = Path(tempfile.mkdtemp()) # Use Path for easier file handling
20
- zip_path = temp_dir / "sepia_images.zip"
21
- with ZipFile(zip_path, 'w') as zipf:
22
- for i, img in enumerate(sepia_imgs):
23
- img_path = temp_dir / f"sepia_image_{i}.png"
24
- gr.utils.save_image(str(img_path), img) # Convert Path object to string for compatibility
25
- zipf.write(img_path, img_path.name)
26
- return str(zip_path) # Convert Path object to string for return
27
-
28
- with gr.Blocks() as demo:
29
- with gr.Row():
30
- input_img = gr.Image()
31
- num_copies = gr.Number(label="Number of Copies", value=1)
32
- gallery = gr.Gallery(label="Sepia Images")
33
- download_btn = gr.File(label="Download ZIP", visible=True)
34
-
35
- input_img.change(fn=lambda x: x, inputs=input_img, outputs=gallery)
36
- num_copies.change(fn=lambda x: x, inputs=num_copies, outputs=gallery)
37
-
38
- generate_btn = gr.Button("Generate Sepia Images")
39
- generate_btn.click(fn=sepia, inputs=[input_img, num_copies], outputs=gallery)
40
- generate_btn.click(fn=zip_sepia_images, inputs=gallery, outputs=download_btn)
41
-
42
- if __name__ == "__main__":
43
- demo.launch()