Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121314151617181920212223242526272829303132333435368 unmodified lines# Convert image to RGBAimg = input_image.convert("RGBA")pixels = img.getdata()new_pixels = []for (r, g, b, a) in pixels:# Keep pixel's original alpha if all components are <= 15,# otherwise make fully transparent.if r <= 15 and g <= 15 and b <= 15:new_pixels.append((r, g, b, a))else:new_pixels.append((r, g, b, 0))img.putdata(new_pixels)return imgdemo = gr.Interface(fn=dark_pixels_only,inputs=gr.Image(type="pil"),outputs=gr.Image(type="pil"),title="Make Non-Dark Pixels Transparent",description="Upload an image. Any pixel with an R, G, or B value above 15 ""will be made fully transparent. Pixels with R, G, B all ≤ 15 ""retain their original alpha.")if __name__ == "__main__":demo.launch(share=True)8 unmodified lines910111213141516171819202122232425262728293031323334353637383940414243448 unmodified lines# Convert image to RGBAimg = input_image.convert("RGBA")pixels = img.getdata()new_pixels = []for (r, g, b, a) in pixels:# Keep pixel's original alpha if R, G, B are <= 15.# Otherwise, make fully transparent.if r <= 15 and g <= 15 and b <= 15:new_pixels.append((r, g, b, a))else:new_pixels.append((r, g, b, 0))# Update pixelsimg.putdata(new_pixels)# Save to disk so we can give a file path to Gradioout_path = "processed.png"img.save(out_path)# Return a tuple: (preview_image, downloadable_file)return img, out_pathdemo = gr.Interface(fn=dark_pixels_only,inputs=gr.Image(type="pil"),outputs=[gr.Image(type="pil", label="Preview of Processed Image"),gr.File(label="Download Processed Image")],title="Make Non-Dark Pixels Transparent",description="Pixels with R,G,B ≤ 15 retain their alpha; everything else becomes transparent.")if __name__ == "__main__":demo.launch()
app.py+17-9