from xml.dom.pulldom import default_bufsize import os os.system("pip install opencv-python") #import cv2 import numpy as np from PIL import Image import gradio as gr from func import rebuild_img def inference(img,k): #input_img = cv2.imread(img, cv2.IMREAD_COLOR) input_img = Image.open(img) #k=gr.inputs.Slider(0, 1, 0.1) u, sigma, v = np.linalg.svd(input_img[:, :, 0]) R = rebuild_img(u, sigma, v, k) u, sigma, v = np.linalg.svd(input_img[:, :, 1]) G = rebuild_img(u, sigma, v, k) u, sigma, v = np.linalg.svd(input_img[:, :, 2]) B = rebuild_img(u, sigma, v, k) restored_img = np.stack((R, G, B), 2) #return Image.fromarray(restored_faces[0][:,:,::-1]) return Image.fromarray(restored_img[:, :, ::-1]) title = "用 SVD 压缩图片" description = "上传需要压缩的图片,选择压缩比,点击Submit,稍等片刻,右侧Output将照片另存为即可。" article = "