Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- facefusion/api/core.py +14 -6
- facefusion/api/test/test.py +1 -1
facefusion/api/core.py
CHANGED
|
@@ -11,21 +11,29 @@ from facefusion.utilities import normalize_output_path
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@router.post("/")
|
| 16 |
async def process_frames(params: Params = Body(...)) -> dict:
|
| 17 |
-
|
| 18 |
-
delete_files_in_directory(
|
| 19 |
-
delete_files_in_directory(
|
|
|
|
| 20 |
|
| 21 |
if not (params.source or params.target):
|
| 22 |
return {"message": "Source image or path is required"}
|
| 23 |
|
| 24 |
update_global_variables(params)
|
| 25 |
|
| 26 |
-
globals.source_path = f"
|
| 27 |
-
globals.target_path = f"
|
| 28 |
-
globals.output_path = f"
|
| 29 |
|
| 30 |
print(globals.output_path)
|
| 31 |
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
router = APIRouter()
|
| 14 |
+
app_dir = os.path.dirname(__file__)
|
| 15 |
+
work_dir = os.path.dirname(app_dir)+'/app/'
|
| 16 |
+
print("工作目录",work_dir)
|
| 17 |
+
@app.get("/")
|
| 18 |
+
def root():
|
| 19 |
+
return {"API": "hello"}
|
| 20 |
+
|
| 21 |
|
| 22 |
@router.post("/")
|
| 23 |
async def process_frames(params: Params = Body(...)) -> dict:
|
| 24 |
+
|
| 25 |
+
delete_files_in_directory(f"{work_dir}temp/source")
|
| 26 |
+
delete_files_in_directory(f"{work_dir}temp/target")
|
| 27 |
+
delete_files_in_directory(f"{work_dir}temp/output")
|
| 28 |
|
| 29 |
if not (params.source or params.target):
|
| 30 |
return {"message": "Source image or path is required"}
|
| 31 |
|
| 32 |
update_global_variables(params)
|
| 33 |
|
| 34 |
+
globals.source_path = f"{work_dir+params.user_id}-{int(time.time())}.{params.source_type}"
|
| 35 |
+
globals.target_path = f"{work_dir+params.user_id}-{int(time.time())}.{params.target_type}"
|
| 36 |
+
globals.output_path = f"{work_dir+params.user_id}-{int(time.time())}.{params.target_type}"
|
| 37 |
|
| 38 |
print(globals.output_path)
|
| 39 |
|
facefusion/api/test/test.py
CHANGED
|
@@ -39,7 +39,7 @@ start=time.time()
|
|
| 39 |
# ステータスコードが200の場合のみ処理を進める
|
| 40 |
if response.status_code == 200:
|
| 41 |
output_data = base64.b64decode(response.json()['output'])
|
| 42 |
-
|
| 43 |
with open(f'/workspaces/facefusion-api/facefusion/api/temp/output/{int(time.time())}a.jpg', 'wb') as f:
|
| 44 |
f.write(output_data)
|
| 45 |
end=time.time()
|
|
|
|
| 39 |
# ステータスコードが200の場合のみ処理を進める
|
| 40 |
if response.status_code == 200:
|
| 41 |
output_data = base64.b64decode(response.json()['output'])
|
| 42 |
+
print("response.json()",response.json())
|
| 43 |
with open(f'/workspaces/facefusion-api/facefusion/api/temp/output/{int(time.time())}a.jpg', 'wb') as f:
|
| 44 |
f.write(output_data)
|
| 45 |
end=time.time()
|