import gradio as gr import numpy as np import time from PIL import Image import os # define core fn, which returns a generator {steps} times before returning the image def convert_image(image,mode,ratio): if mode == "8bit:JPEG:gray scale": image = image.convert('L') image.save("download.jpg", 'JPEG', quality=95, dpi=[300,300], bits=8) return "download.jpg" else: # print(f"width:{image.width},height:{image.height}") intRatio = int(ratio) image = image.resize((image.width*intRatio, image.height*intRatio), Image.LANCZOS) image = image.convert('1') image.save("download.png", 'PNG', quality=95, dpi=[300,300], bits=1) return "download.png" # return image demo = gr.Interface(convert_image, inputs=[gr.Image(type="pil"),gr.Radio(["8bit:JPEG:gray scale", "1bit:PNG:black and white"], label="Mode", info="Which mode would you like?"),gr.Slider(minimum=1,maximum=10,value=1)], outputs="file") demo.launch() # Copyright © 2023 @tregu0458 # All rights reserved. # This prompt are protected by copyright laws. Unauthorized reproduction, distribution, or use is prohibited. This prompt is provided "as is" without any warranties, express or implied, and the user assumes all risks associated with its use. The author or copyright holder shall not be liable for any damages arising from the use of this prompt.