Spaces:
Running
on
T4
Running
on
T4
Commit
·
225c7ff
1
Parent(s):
39bf82c
added token and modified /submit
Browse files
app.py
CHANGED
|
@@ -905,7 +905,7 @@ fastapi_app.add_middleware(
|
|
| 905 |
)
|
| 906 |
|
| 907 |
_bearer_scheme = HTTPBearer(auto_error=False)
|
| 908 |
-
_api_bearer_token = os.getenv("API_BEARER_TOKEN", "
|
| 909 |
|
| 910 |
def _verify_bearer_token(credentials: Optional[HTTPAuthorizationCredentials] = Depends(_bearer_scheme)):
|
| 911 |
if not _bearer_scheme:
|
|
@@ -990,6 +990,22 @@ async def submit(
|
|
| 990 |
progress=progress_stub,
|
| 991 |
)
|
| 992 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 993 |
if _mongo_collection is not None:
|
| 994 |
try:
|
| 995 |
_mongo_collection.insert_one({
|
|
@@ -1005,29 +1021,28 @@ async def submit(
|
|
| 1005 |
"with_model_name": with_model_name,
|
| 1006 |
},
|
| 1007 |
"outputs": {
|
| 1008 |
-
"images":
|
| 1009 |
-
"zips":
|
| 1010 |
},
|
| 1011 |
})
|
| 1012 |
except Exception:
|
| 1013 |
pass
|
| 1014 |
|
| 1015 |
-
def _dl_url(name: str) -> str:
|
| 1016 |
-
return f"/download/{name}"
|
| 1017 |
-
|
| 1018 |
return {
|
| 1019 |
-
"output_images":
|
| 1020 |
-
"output_zips":
|
| 1021 |
"download_urls": {
|
| 1022 |
-
"images": [_dl_url(
|
| 1023 |
-
"zips": [_dl_url(
|
| 1024 |
},
|
| 1025 |
}
|
|
|
|
| 1026 |
except HTTPException:
|
| 1027 |
raise
|
| 1028 |
except Exception as e:
|
| 1029 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
| 1030 |
|
|
|
|
| 1031 |
@fastapi_app.get("/download/{filename}")
|
| 1032 |
def download(filename: str, _: bool = Depends(_verify_bearer_token)):
|
| 1033 |
safe_name = os.path.basename(filename)
|
|
|
|
| 905 |
)
|
| 906 |
|
| 907 |
_bearer_scheme = HTTPBearer(auto_error=False)
|
| 908 |
+
_api_bearer_token = os.getenv("API_BEARER_TOKEN", "logicgo_123")
|
| 909 |
|
| 910 |
def _verify_bearer_token(credentials: Optional[HTTPAuthorizationCredentials] = Depends(_bearer_scheme)):
|
| 911 |
if not _bearer_scheme:
|
|
|
|
| 990 |
progress=progress_stub,
|
| 991 |
)
|
| 992 |
|
| 993 |
+
# --- Filter only final outputs ---
|
| 994 |
+
final_images = [
|
| 995 |
+
os.path.basename(p)
|
| 996 |
+
for p in (output_files or [])
|
| 997 |
+
if not any(tag in os.path.basename(p) for tag in ["cropped_faces", "restored_faces", "cmp"])
|
| 998 |
+
]
|
| 999 |
+
final_zips = [
|
| 1000 |
+
os.path.basename(p)
|
| 1001 |
+
for p in (zip_files or [])
|
| 1002 |
+
if "restored_images" in os.path.basename(p)
|
| 1003 |
+
]
|
| 1004 |
+
|
| 1005 |
+
def _dl_url(name: str) -> str:
|
| 1006 |
+
return f"/download/{name}"
|
| 1007 |
+
|
| 1008 |
+
# Save to Mongo if available
|
| 1009 |
if _mongo_collection is not None:
|
| 1010 |
try:
|
| 1011 |
_mongo_collection.insert_one({
|
|
|
|
| 1021 |
"with_model_name": with_model_name,
|
| 1022 |
},
|
| 1023 |
"outputs": {
|
| 1024 |
+
"images": final_images,
|
| 1025 |
+
"zips": final_zips,
|
| 1026 |
},
|
| 1027 |
})
|
| 1028 |
except Exception:
|
| 1029 |
pass
|
| 1030 |
|
|
|
|
|
|
|
|
|
|
| 1031 |
return {
|
| 1032 |
+
"output_images": final_images,
|
| 1033 |
+
"output_zips": final_zips,
|
| 1034 |
"download_urls": {
|
| 1035 |
+
"images": [_dl_url(p) for p in final_images],
|
| 1036 |
+
"zips": [_dl_url(p) for p in final_zips],
|
| 1037 |
},
|
| 1038 |
}
|
| 1039 |
+
|
| 1040 |
except HTTPException:
|
| 1041 |
raise
|
| 1042 |
except Exception as e:
|
| 1043 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
| 1044 |
|
| 1045 |
+
|
| 1046 |
@fastapi_app.get("/download/{filename}")
|
| 1047 |
def download(filename: str, _: bool = Depends(_verify_bearer_token)):
|
| 1048 |
safe_name = os.path.basename(filename)
|