abiabidali commited on
Commit
44a27e2
·
verified ·
1 Parent(s): c76e9e2

Update app.py

Browse files

multi-image uploads

Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -60,27 +60,34 @@ def resize_image(input_image, width, height):
60
  temp_file.close()
61
  return Image.open(temp_file.name)
62
 
63
- def process_image(input_image, enhance, scale, adjust_dpi, dpi, resize, width, height):
64
- original_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
 
65
 
66
- if enhance:
67
- original_image = enhance_image(original_image, scale)
68
-
69
- if adjust_dpi:
70
- original_image = muda_dpi(np.array(original_image), dpi)
71
 
72
- if resize:
73
- original_image = resize_image(np.array(original_image), width, height)
74
 
75
- temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
76
- original_image.save(temp_file.name)
77
- return original_image, temp_file.name
 
 
 
 
 
 
 
 
 
78
 
79
  iface = gr.Interface(
80
- fn=process_image,
81
  inputs=[
82
- gr.Image(label="Upload"),
83
- gr.Checkbox(label="Enhance Image (ESRGAN)"),
84
  gr.Radio(['2x', '4x', '8x'], type="value", value='2x', label='Resolution model'),
85
  gr.Checkbox(label="Adjust DPI"),
86
  gr.Number(label="DPI", value=300),
@@ -89,14 +96,15 @@ iface = gr.Interface(
89
  gr.Number(label="Height", value=512)
90
  ],
91
  outputs=[
92
- gr.Image(label="Final Image"),
93
- gr.File(label="Download Final Image")
94
  ],
95
- title="Image Enhancer",
96
- description="Upload an image (.jpg, .png), enhance using AI, adjust DPI, resize and download the final result.",
97
  examples=[
98
  ["gatuno.JPG"]
99
  ]
100
  )
101
 
102
  iface.launch(debug=True)
 
 
60
  temp_file.close()
61
  return Image.open(temp_file.name)
62
 
63
+ def process_images(input_images, enhance, scale, adjust_dpi, dpi, resize, width, height):
64
+ processed_images = []
65
+ file_paths = []
66
 
67
+ for input_image in input_images:
68
+ original_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
 
 
 
69
 
70
+ if enhance:
71
+ original_image = enhance_image(original_image, scale)
72
 
73
+ if adjust_dpi:
74
+ original_image = muda_dpi(np.array(original_image), dpi)
75
+
76
+ if resize:
77
+ original_image = resize_image(np.array(original_image), width, height)
78
+
79
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
80
+ original_image.save(temp_file.name)
81
+ processed_images.append(original_image)
82
+ file_paths.append(temp_file.name)
83
+
84
+ return processed_images, file_paths
85
 
86
  iface = gr.Interface(
87
+ fn=process_images,
88
  inputs=[
89
+ gr.Images(label="Upload Images"), # Use gr.Images for multi-image upload
90
+ gr.Checkbox(label="Enhance Images (ESRGAN)"),
91
  gr.Radio(['2x', '4x', '8x'], type="value", value='2x', label='Resolution model'),
92
  gr.Checkbox(label="Adjust DPI"),
93
  gr.Number(label="DPI", value=300),
 
96
  gr.Number(label="Height", value=512)
97
  ],
98
  outputs=[
99
+ gr.Gallery(label="Final Images"), # Use gr.Gallery to display multiple images
100
+ gr.Files(label="Download Final Images")
101
  ],
102
+ title="Multi-Image Enhancer",
103
+ description="Upload multiple images (.jpg, .png), enhance using AI, adjust DPI, resize, and download the final results.",
104
  examples=[
105
  ["gatuno.JPG"]
106
  ]
107
  )
108
 
109
  iface.launch(debug=True)
110
+