Commit
·
f67d0b5
1
Parent(s):
ac598ad
error handle
Browse files- HDML-FaceDetection.log +0 -1
- README.MD +0 -5
- README.md +14 -0
- data/__init__.py +0 -0
- face_api.py +19 -14
- face_main.py +14 -9
- model/__init__.py +0 -0
- requirements.txt +9 -0
HDML-FaceDetection.log
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
Time:05:29:53 PM, Execution Done and Total Successfull Execution : 1, Payload:url='https://bl-bucket.sgp1.digitaloceanspaces.com/pulse/faceDetection/lvglbz46yd9et1qknf/faceDetection-original', Result:{}
|
|
|
|
|
|
README.MD
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
### Himel_Face_Detection
|
| 2 |
-
|
| 3 |
-
# Himel app
|
| 4 |
-
------------
|
| 5 |
-
ngrok config add-authtoken 2Qm8hS1zPhVXiLjEdlI4738tLzF_2QJwGJMK5oTbQD33QSVXS && sudo apt update && sudo apt upgrade && ngrok http --domain=hawkeyes.ngrok.app 8000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### rakib72642/HDML_Face_Detection_Model
|
| 2 |
+
|
| 3 |
+
# HuggingFace: https://huggingface.co/rakib72642/HDML_Face_Detection_Model
|
| 4 |
+
|
| 5 |
+
# Setup Global API
|
| 6 |
+
|
| 7 |
+
sudo apt install iproute2 -y && sudo apt install wget -y && sudo apt install unzip -y && sudo apt install unzip -y && apt install nvtop -y && sudo apt-get install git-all -y && sudo apt-get install git-lfs -y && sud apt-get update && sudo apt-get install libgl1 -y && sudo apt install curl -y && curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok -y && sudo apt update && sudo apt upgrade -y && ngrok config add-authtoken 2Qm8hS1zPhVXiLjEdlI4738tLzF_2QJwGJMK5oTbQD33QSVXS && ngrok http --domain=hawkeyes.ngrok.app 8585
|
| 8 |
+
|
| 9 |
+
# Setup Local API
|
| 10 |
+
git clone https://huggingface.co/rakib72642/HDML_Face_Detection_Model && cd HDML_Face_Detection_Model && pip install -r requirements.txt && sudo apt update && sudo apt upgrade -y && python face_main.py
|
| 11 |
+
|
| 12 |
+
cd HDML_Face_Detection_Model && python face_main.py
|
| 13 |
+
|
| 14 |
+
# hypercorn face_main:app --bind 127.0.0.1:8585 --workers 4
|
data/__init__.py
ADDED
|
File without changes
|
face_api.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import asyncio
|
| 4 |
from typing import List, Union
|
|
@@ -37,21 +37,25 @@ async def process_item(item: Item):
|
|
| 37 |
result = await mainDet(item.url)
|
| 38 |
result = json.loads(result)
|
| 39 |
return result
|
|
|
|
|
|
|
| 40 |
finally:
|
| 41 |
torch.cuda.empty_cache()
|
| 42 |
-
pass
|
| 43 |
|
| 44 |
async def process_items(items: Union[Item, List[Item]]):
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
@app.get("/status")
|
|
@@ -72,17 +76,18 @@ async def create_items(items: Union[Item, List[Item]]):
|
|
| 72 |
total_error += 1
|
| 73 |
logger.info(f"Time:{get_bd_time()}, Execution Failed and Total Failed Execution : {total_error}, Payload:{items}, Error:{str(e)}")
|
| 74 |
logger.error(str(e))
|
| 75 |
-
|
| 76 |
finally:
|
| 77 |
global total_done
|
| 78 |
total_done +=1
|
| 79 |
logger.info(f"Time:{get_bd_time()}, Execution Done and Total Successfull Execution : {total_done}, Payload:{items}, Result:{results}")
|
| 80 |
torch.cuda.empty_cache()
|
| 81 |
-
pass
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|
| 84 |
try:
|
| 85 |
del faceModel
|
| 86 |
uvicorn.run(app, host="127.0.0.1", port=8585)
|
|
|
|
|
|
|
| 87 |
finally:
|
| 88 |
torch.cuda.empty_cache()
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import asyncio
|
| 4 |
from typing import List, Union
|
|
|
|
| 37 |
result = await mainDet(item.url)
|
| 38 |
result = json.loads(result)
|
| 39 |
return result
|
| 40 |
+
except Exception as e:
|
| 41 |
+
raise ValueError(f"process_item ERROR : {str(e)}")
|
| 42 |
finally:
|
| 43 |
torch.cuda.empty_cache()
|
|
|
|
| 44 |
|
| 45 |
async def process_items(items: Union[Item, List[Item]]):
|
| 46 |
+
try:
|
| 47 |
+
if type(items)==list:
|
| 48 |
+
coroutines = [process_item(item) for item in items]
|
| 49 |
+
results = await asyncio.gather(*coroutines)
|
| 50 |
+
print("multi : ",results)
|
| 51 |
+
else:
|
| 52 |
+
results = await process_item(items)
|
| 53 |
+
print("single : ", results)
|
| 54 |
+
return results
|
| 55 |
+
except Exception as e:
|
| 56 |
+
raise ValueError(f"process_items ERROR : {str(e)}")
|
| 57 |
+
finally:
|
| 58 |
+
torch.cuda.empty_cache()
|
| 59 |
|
| 60 |
|
| 61 |
@app.get("/status")
|
|
|
|
| 76 |
total_error += 1
|
| 77 |
logger.info(f"Time:{get_bd_time()}, Execution Failed and Total Failed Execution : {total_error}, Payload:{items}, Error:{str(e)}")
|
| 78 |
logger.error(str(e))
|
| 79 |
+
raise ValueError(f"process_item ERROR : {str(e)}")
|
| 80 |
finally:
|
| 81 |
global total_done
|
| 82 |
total_done +=1
|
| 83 |
logger.info(f"Time:{get_bd_time()}, Execution Done and Total Successfull Execution : {total_done}, Payload:{items}, Result:{results}")
|
| 84 |
torch.cuda.empty_cache()
|
|
|
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
try:
|
| 88 |
del faceModel
|
| 89 |
uvicorn.run(app, host="127.0.0.1", port=8585)
|
| 90 |
+
except Exception as e:
|
| 91 |
+
raise ValueError(f"face_api ERROR : {str(e)}")
|
| 92 |
finally:
|
| 93 |
torch.cuda.empty_cache()
|
face_main.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
| 2 |
import pandas as pd
|
| 3 |
import asyncio
|
| 4 |
import base64
|
|
|
|
| 5 |
from PIL import Image, ImageDraw
|
| 6 |
from aiohttp import ClientSession
|
| 7 |
from io import BytesIO
|
|
@@ -16,7 +17,9 @@ async def getImage(img_url):
|
|
| 16 |
img_data = await response.read()
|
| 17 |
return BytesIO(img_data)
|
| 18 |
except Exception as e:
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
async def detection(model,img_content):
|
|
@@ -38,7 +41,10 @@ async def detection(model,img_content):
|
|
| 38 |
detection.update(res)
|
| 39 |
return detection
|
| 40 |
except Exception as e:
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
|
|
@@ -51,11 +57,9 @@ async def format_result(ai_result,convert_data):
|
|
| 51 |
result.update({i:member_details[i]})
|
| 52 |
return result
|
| 53 |
except Exception as e:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
|
| 61 |
async def mainDet(url):
|
|
@@ -64,7 +68,8 @@ async def mainDet(url):
|
|
| 64 |
detect_data = await asyncio.create_task(detection(faceModel, image))
|
| 65 |
result = await asyncio.create_task(format_result(detect_data,member_details))
|
| 66 |
return json.dumps(result)
|
| 67 |
-
|
| 68 |
except Exception as e:
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import asyncio
|
| 4 |
import base64
|
| 5 |
+
import torch
|
| 6 |
from PIL import Image, ImageDraw
|
| 7 |
from aiohttp import ClientSession
|
| 8 |
from io import BytesIO
|
|
|
|
| 17 |
img_data = await response.read()
|
| 18 |
return BytesIO(img_data)
|
| 19 |
except Exception as e:
|
| 20 |
+
raise ValueError(f"getImage ERROR : {str(e)}")
|
| 21 |
+
finally:
|
| 22 |
+
torch.cuda.empty_cache()
|
| 23 |
|
| 24 |
|
| 25 |
async def detection(model,img_content):
|
|
|
|
| 41 |
detection.update(res)
|
| 42 |
return detection
|
| 43 |
except Exception as e:
|
| 44 |
+
raise ValueError(f"detection ERROR : {str(e)}")
|
| 45 |
+
finally:
|
| 46 |
+
torch.cuda.empty_cache()
|
| 47 |
+
|
| 48 |
|
| 49 |
|
| 50 |
|
|
|
|
| 57 |
result.update({i:member_details[i]})
|
| 58 |
return result
|
| 59 |
except Exception as e:
|
| 60 |
+
raise ValueError(f"format_result ERROR : {str(e)}")
|
| 61 |
+
finally:
|
| 62 |
+
torch.cuda.empty_cache()
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
async def mainDet(url):
|
|
|
|
| 68 |
detect_data = await asyncio.create_task(detection(faceModel, image))
|
| 69 |
result = await asyncio.create_task(format_result(detect_data,member_details))
|
| 70 |
return json.dumps(result)
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
+
raise ValueError(f"mainDet ERROR : {str(e)}")
|
| 73 |
+
finally:
|
| 74 |
+
torch.cuda.empty_cache()
|
| 75 |
|
model/__init__.py
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
pydantic
|
| 3 |
+
uvicorn
|
| 4 |
+
hypercorn
|
| 5 |
+
pytz
|
| 6 |
+
httpx
|
| 7 |
+
requests
|
| 8 |
+
aiofiles
|
| 9 |
+
ultralytics
|