代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/deoldify 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# import the necessary packages
import os
import sys
import requests
import ssl
from flask import Flask
from flask import request
from flask import jsonify
from flask import send_file
from uuid import uuid4
from os import path
import torch
import fastai
from fasterai.visualize import *
from pathlib import Path
import traceback
torch.backends.cudnn.benchmark=True
image_colorizer = get_image_colorizer(artistic=True)
video_colorizer = get_video_colorizer()
os.environ['CUDA_VISIBLE_DEVICES']='0'
app = Flask(__name__)
# define a predict function as an endpoint
@app.route("/process_image", methods=["POST"])
def process_image():
try:
source_url = request.json["source_url"]
render_factor = int(request.json["render_factor"])
upload_directory = 'upload'
if not os.path.exists(upload_directory):
os.mkdir(upload_directory)
random_filename = str(uuid4()) + '.png'
image_colorizer.plot_transformed_image_from_url(url=source_url, path=os.path.join(upload_directory, random_filename), figsize=(20,20),
render_factor=render_factor, display_render_factor=True, compare=False)
callback = send_file(os.path.join("result_images", random_filename), mimetype='image/jpeg')
return callback
except:
traceback.print_exc()
return {message: 'input error'}, 400
finally:
os.remove(os.path.join("result_images", random_filename))
os.remove(os.path.join("upload", random_filename))
@app.route("/process_video", methods=["POST"])
def process_video():
try:
source_url = request.json["source_url"]
render_factor = int(request.json["render_factor"])
upload_directory = 'upload'
if not os.path.exists(upload_directory):
os.mkdir(upload_directory)
random_filename = str(uuid4()) + '.mp4'
video_path = video_colorizer.colorize_from_url(source_url, random_filename, render_factor)
callback = send_file(os.path.join("video/result/", random_filename), mimetype='application/octet-stream')
return callback
except:
traceback.print_exc()
return {message: 'input error'}, 400
finally:
os.remove(os.path.join("video/result/", random_filename))
if __name__ == '__main__':
port = 5000
host = '0.0.0.0'
app.run(host=host, port=port, threaded=True)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。