ming 3 rokov pred
rodič
commit
7cd7181208

+ 8 - 2
main.py

@@ -24,6 +24,7 @@ from websocket import create_connection
 from fastapi.middleware.cors import CORSMiddleware
 import dataset
 from datetime import datetime
+from util.swap_face import swap_face
 #service nginx restart
 #uvicorn main:app --host="0.0.0.0" --reload --port 8888
 
@@ -53,7 +54,8 @@ dir_title = 'title/'
 dir_subtitle = 'subtitle/'
 dir_anchor = 'anchor_raw/'
 
-
+class swap_req(BaseModel):
+    imgurl: str
 
 class request(BaseModel):
     name: str
@@ -107,7 +109,11 @@ async def index2():
 async def progress_page():
     return FileResponse('progress.html')
 
-
+@app.post("/swapFace")
+async def swapFace(req:swap_req):
+    sf = swap_face(req.imgurl)
+    result = sf.run()
+    notify_group(result)
 
 @app.post("/make_anchor_video_v2")
 async def make_anchor_video_v2(req:request):

+ 0 - 6
swapFace/swap_face.py

@@ -1,6 +0,0 @@
-import os 
-class swap_face():
-    #def __init__(self, name):
-    #    self.name = name
-    def run():
-        os.system

+ 0 - 0
swapFace/__pycache__/swap_face.cpython-39.pyc → util/__pycache__/swap_face.cpython-39.pyc


+ 27 - 0
util/swap_face.py

@@ -0,0 +1,27 @@
+import os 
+import requests
+class swap_face():
+    def __init__(self, imgurl):
+        self.imgurl = imgurl
+    def run():
+        name_hash = str(time.time()).replace('.','')
+        src_img = 'FaceSwap/src_img/'+name_hash+'.jpg'
+        sv_path = '../html/swap_save'+name_hash+'.avi'
+        try:
+            im = Image.open(requests.get(self.imgurl, stream=True).raw)
+            im= im.convert("RGB")
+            im.save(src_img)
+        except:
+            return '圖片錯誤'
+        
+
+        os.system('python3 FaceSwap/main_video.py --src_img '+src_img+' --video_path nina_noGesture_adj.mp4 --correct_color --save_path '+sv_path)    
+        while True:
+            print('waiting...')
+            if os.path.exists(sv_path):
+                break
+            time.sleep(5)
+            print('waiting...')
+
+        return "人物生成完成 at : www.choozmo.com:8168/swap_save/"+name_hash+".avi"
+