ThinkWeb/aesthetic_scorer
0
1import gradio as gr2from transformers import pipeline3 4pipe_aesthetic = pipeline("image-classification", "cafeai/cafe_aesthetic")5def aesthetic(input_img):6 data = pipe_aesthetic(input_img, top_k=2)7 final = {}8 for d in data:9 final[d["label"]] = d["score"]10 return final11demo_aesthetic = gr.Interface(fn=aesthetic, inputs=gr.Image(type="pil"), outputs=gr.Label(label="aesthetic"))12 13pipe_style = pipeline("image-classification", "cafeai/cafe_style")14def style(input_img):15 data = pipe_style(input_img, top_k=5)16 final = {}17 for d in data:18 final[d["label"]] = d["score"]19 return final20demo_style = gr.Interface(fn=style, inputs=gr.Image(type="pil"), outputs=gr.Label(label="style"))21 22pipe_waifu = pipeline("image-classification", "cafeai/cafe_waifu")23def waifu(input_img):24 data = pipe_waifu(input_img, top_k=5)25 final = {}26 for d in data:27 final[d["label"]] = d["score"]28 return final29demo_waifu = gr.Interface(fn=waifu, inputs=gr.Image(type="pil"), outputs=gr.Label(label="waifu"))30 31gr.Parallel(demo_aesthetic, demo_style, demo_waifu).launch()32 