万粉博主推荐,微信小程序 Flask后端调用AnimeGanV2(4)

2022-10-30 来源:旧番剧
} }, fail: (res) =>{ console.log("fail===",res) } }) },
Flask后端实现步骤
1、配置RESTful路由方法
@app.route("/postdata", methods=["POST"])def postdata(): f = request.files["content"] print(f) user_input = request.form.get("name") basepath = os.path.dirname(__file__) # 当前文件所在路径 src_imgname = str(uuid.uuid1()) ".jpg" upload_path = os.path.join(basepath, "static/srcImg/") if os.path.exists(upload_path)==False: os.makedirs(upload_path) f.save(upload_path src_imgname) # img = cv2.
imread(upload_path src_imgname, 1) save_path = os.path.join(basepath, "static/resImg/") if os.path.exists(save_path) == False: os.makedirs(save_path) generateAvantar(src_imgname,upload_path,save_path) resSets["value"] = 10 resSets["resurl"] = "http://127.0.0.1:8090" "/static/resImg/" src_imgname return json.dumps(resSets, ensure_ascii=False)
该代码主要接受前端传来的图片url,进行处理并且通过json传回去。
2、调用AnimeGanv2实现动漫化
net = Generator()net.load_state_dict(torch.load(args.checkpoint, map_location="cpu"))net.to(args.device).eval()# print(f"model loaded: {args.checkpoint}") # os.makedirs(args.output_dir, exist_ok=True) def load_image(image_path, x32=False): img = cv2.imread(image_path).astype(np.float32) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) h, w = img.shape[:2] if x32:
猜你喜欢
动漫推荐
免责声明:动漫番剧数据来源网络!本站不收费,无vip,请勿上当!

www.jiufanju.com-旧番剧