Browse Source

fix text2zip.py

tomoya 1 month ago
parent
commit
8ad3188a2e
1 changed files with 14 additions and 7 deletions
  1. 14 7
      backend/app/app/api/api_v1/endpoints/text2zip.py

+ 14 - 7
backend/app/app/api/api_v1/endpoints/text2zip.py

@@ -149,13 +149,24 @@ def generate_zip(
 def generate_video(
       *,
     background_tasks: BackgroundTasks,
-    db: Session = Depends(deps.get_db),
     #current_user: models.User = Depends(deps.get_current_active_user),
     model:Literal['sd3', 'flux']="sd3", 
     email:EmailStr,
     texts:List[str],
     lang:Literal["en", 'zh']):
+    
+    flag=False
+    for text in texts:
+        if text:
+            flag=True
+    if flag:
+        background_tasks.add_task(wait_finish, model, email, texts, lang)
+        return "OK"
+    else:
+        return HTTPException("No texts.")
 
+async def wait_finish(model, email, texts, lang): 
+    db = SessionLocal()
     if not model:
         model = 'sd3'
     wb = px.Workbook()
@@ -201,12 +212,8 @@ def generate_video(
         video_data['style'] = "style14"
         video_data['lang'] = lang
         video_data['email'] = email
-        background_tasks.add_task(wait_finish, video_data)
-        
-        
-    return "OK"
-
-async def wait_finish(video_data:dict): 
+    db.close()
+    
     zip_filename = video_data['stored_filename']+".zip"
     process = await asyncio.create_subprocess_exec("sshpass", "-p", "choozmo9", 
                     "scp", "-P", "5722", "-o", "StrictHostKeyChecking=no", f"/tmp/{zip_filename}", f"root@172.104.93.163:{str(LOCAL_ZIP_STORAGE)}")