創新實訓第三週團隊博客

創新實訓第三週團隊博客

這一週主要完成了剩餘的App前端代碼和後端接口,PSGAN模型的微調和flask上妝接口。具體工作參考每個團隊成員的個人博客。

前端App工作

整合後端接口和PSGAN的上妝接口,修復App的一些bug。

最終效果如下所示:
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

後端工作

和前端協調接口開發,實現動態相關接口,部分文檔如下:

1,發佈動態(需要驗權)
1)方法:POST
2)URL:/star/publish
3)參數:content動態內容, images動態圖片,目前只支持一張
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,並攜帶動態信息

2,轉發動態(需要驗權)
1)方法:POST
2)URL:/star/forward/:starID
3)參數:content和images同上,starID是轉發動態的id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,並攜帶動態信息

3,更新動態(需要驗權)
1)方法:POST
2)URL:/star/update/:starID
3)參數:參數同1
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,並攜帶動態信息

4,刪除動態(需要驗權)
1)方法:GET
2)URL:/star/delete/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200

5,點贊動態(需要驗權)
1)方法:GET
2)URL:/star/like/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200

6,取消點贊動態(需要驗權)
1)方法:GET
2)URL:/star/cancel_like/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200

7,動態詳情
1)方法:GET
2)URL:/star/details/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,動態已被刪除返回狀態碼400,發佈成功返回狀態碼 200,攜帶動態詳情數據

8,獲取點贊用戶列表
1)方法:GET
2)URL:/star/like_users/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,攜帶點贊用戶列表

9,獲取轉發動態列表
1)方法:GET
2)URL:/star/forward_stars/:starID
3)參數:starID是動態id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,攜帶轉發動態列表

10,獲取用戶全部動態
1)方法:GET
2)URL:/user/:id/stars
3)參數:id是用戶id
4)響應:內部錯誤返回狀態碼 500,發佈成功返回狀態碼 200,攜帶動態列表

PSGAN 模型搭建

通過flask框架完成模型上妝接口。

flask相關代碼如下:

from flask import Flask, request, render_template, Response

from data_loaders.makeup_utils import *
from solver_psgan import Solver_PSGAN

app = Flask(__name__)


@app.route('/generate_makeup', methods=['POST', 'GET'])
def generate_makeup():
    if request.method == 'POST':
        try:
            example_image = request.files.get('example_image')
            user_image = request.files.get('user_image')
            shade_alpha = request.form.get("shade_alpha")
            local_flag = request.form.get("local_flag")
            lip_flag = request.form.get("lip_flag")
            eye_flag = request.form.get("eye_flag")
            face_flag = request.form.get("face_flag")

            if str(local_flag) == '1':
                print('local flag')
                images = [user_image, example_image]
                mask2use = get_mask(Image.open(images[1]), lip_flag, eye_flag, face_flag)
                images = [Image.open(image) for image in images]
                images = [preprocess_image(image) for image in images]
                transferred_image = Solver_PSGAN.partial_test(*(images[0]), *(images[1]), *(images[0]), mask2use, shade_alpha=float(shade_alpha))
            else:
                images = [user_image, example_image]
                images = [Image.open(image) for image in images]
                images = [preprocess_image(image) for image in images]
                transferred_image = Solver_PSGAN.image_test(*(images[0]), *(images[1]), shade_alpha=float(shade_alpha))
            transferred_image.save('./static/images/transferred_image.png')

            with open('static/images/transferred_image.png', 'rb') as f:
                image = f.read()
                resp = Response(image, status=200, mimetype="image/png")
            return resp
        except Exception as e:
            print(str(e))
            resp = Response(response='Exception', status=500, content_type='text/html;charset=utf8')
            return resp

    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)

用於測試接口的HTML頁面如下:

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章