You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
889 B
29 lines
889 B
import json
|
|
|
|
from django.http import HttpResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from basic.helper import get_image_name
|
|
from .utils import *
|
|
|
|
PREFIX = './media/'
|
|
DEFAULT_FORMAT = '.jpg'
|
|
|
|
SUPPORT_MODEL = ['candy', 'composition_vii', 'feathers', 'la_muse', 'mosaic',
|
|
'starry_night', 'the_scream', 'the_wave', 'udnie']
|
|
|
|
|
|
@csrf_exempt
|
|
def transfer(request):
|
|
if request.method == 'POST':
|
|
para = json.loads(request.body)
|
|
image = para['img']
|
|
my_type = para['model']
|
|
if my_type not in SUPPORT_MODEL:
|
|
return HttpResponse('不支持的风格转换')
|
|
model = 'advance/models/' + para['type'] + '.t7'
|
|
filename = get_image_name() + DEFAULT_FORMAT
|
|
style_transfer(PREFIX + image, PREFIX + filename, model)
|
|
return HttpResponse(filename)
|
|
return HttpResponse('请使用POST方法')
|