DEMO 1-2: Display an Image

import gradio as gr
from PIL import Image

def to_black(file):
    image=Image.fromarray(file) #  Convert a numpy array to a PIL Image
    # image=Image.open(file) # If the input is a file path, open it as a PIL Image
    # image=file # If the input is already a PIL Image, use it directly
    img=image.convert("L") #  Convert to a grayscale image
    img=img.rotate(180) #  Rotate the image by 180 degrees
    return img

demo = gr.Interface(fn=to_black, 
            inputs=gr.Image(type='numpy'),  #type='pil','numpy','filepath'
            outputs=gr.Image(type='pil'),)

demo.launch(share=False)