Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- facefusion/api/core.py +17 -10
- facefusion/api/test/test.py +2 -1
facefusion/api/core.py
CHANGED
|
@@ -22,25 +22,26 @@ def root():
|
|
| 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.
|
| 35 |
-
globals.
|
| 36 |
-
globals.
|
| 37 |
-
|
|
|
|
| 38 |
print(globals.output_path)
|
| 39 |
|
| 40 |
print_globals()
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
try:
|
| 46 |
core.api_conditional_process()
|
|
@@ -48,6 +49,12 @@ async def process_frames(params: Params = Body(...)) -> dict:
|
|
| 48 |
print(e)
|
| 49 |
return {"message": "Error"}
|
| 50 |
output = image_to_base64_str(globals.output_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
return {'output': output}
|
| 52 |
|
| 53 |
def update_global_variables(params: Params):
|
|
|
|
| 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 |
+
globals.source_path = f"{work_dir+params.user_id}source-{int(time.time())}.{params.source_type}"
|
| 34 |
+
globals.target_path = f"{work_dir+params.user_id}target-{int(time.time())}.{params.target_type}"
|
| 35 |
+
globals.output_path = f"{work_dir+params.user_id}output-{int(time.time())}.{params.target_type}"
|
| 36 |
+
# globals.source_path = f"{work_dir+params.user_id}source.{params.source_type}"
|
| 37 |
+
# globals.target_path = f"{work_dir+params.user_id}target.{params.target_type}"
|
| 38 |
+
# globals.output_path = f"{work_dir+params.user_id}output.{params.target_type}"
|
| 39 |
print(globals.output_path)
|
| 40 |
|
| 41 |
print_globals()
|
| 42 |
|
| 43 |
+
save_file(globals.source_path, params.source)
|
| 44 |
+
save_file(globals.target_path, params.target)
|
| 45 |
|
| 46 |
try:
|
| 47 |
core.api_conditional_process()
|
|
|
|
| 49 |
print(e)
|
| 50 |
return {"message": "Error"}
|
| 51 |
output = image_to_base64_str(globals.output_path)
|
| 52 |
+
# delete_files_in_directory(globals.source_path)
|
| 53 |
+
# delete_files_in_directory(globals.target_path)
|
| 54 |
+
# delete_files_in_directory(globals.output_path)
|
| 55 |
+
os.remove(globals.source_path)
|
| 56 |
+
os.remove(globals.target_path)
|
| 57 |
+
os.remove(globals.output_path)
|
| 58 |
return {'output': output}
|
| 59 |
|
| 60 |
def update_global_variables(params: Params):
|
facefusion/api/test/test.py
CHANGED
|
@@ -29,7 +29,8 @@ params = {
|
|
| 29 |
'face_selector_mode': 'one',
|
| 30 |
}
|
| 31 |
|
| 32 |
-
url = 'https://michaelj-facefusionapi.hf.space/'
|
|
|
|
| 33 |
response = requests.post(url, json=params)
|
| 34 |
|
| 35 |
# 銈广儐銉笺偪銈广偝銉笺儔銇ㄣ儸銈广儩銉炽偣銇唴瀹广倰纰鸿獚
|
|
|
|
| 29 |
'face_selector_mode': 'one',
|
| 30 |
}
|
| 31 |
|
| 32 |
+
# url = 'https://michaelj-facefusionapi.hf.space/'
|
| 33 |
+
url="http://0.0.0.0:7860"
|
| 34 |
response = requests.post(url, json=params)
|
| 35 |
|
| 36 |
# 銈广儐銉笺偪銈广偝銉笺儔銇ㄣ儸銈广儩銉炽偣銇唴瀹广倰纰鸿獚
|