Hussein El-Hadidy commited on
Commit ·
b3607bf
1
Parent(s): a988833
CPR Added
Browse files- .gitignore +4 -0
- app.py +37 -2
- main.py +37 -2
- requirements.txt +103 -20
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/*
|
| 2 |
+
venv/*
|
| 3 |
+
uploads/*
|
| 4 |
+
runs/*
|
app.py
CHANGED
|
@@ -15,10 +15,15 @@ import requests
|
|
| 15 |
import joblib
|
| 16 |
import numpy as np
|
| 17 |
from ECG import classify_new_ecg
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
|
|
|
|
|
|
| 22 |
# ✅ MongoDB connection
|
| 23 |
mongo_uri = "mongodb://husseinelhadidy03:W8ByXdBS4EFkZmd5@ac-lqfhgnk-shard-00-00.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-01.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-02.ycuagnj.mongodb.net:27017/?replicaSet=atlas-az5d0x-shard-0&ssl=true&authSource=admin&retryWrites=true&w=majority&appName=Cluster0"
|
| 24 |
client = MongoClient(mongo_uri, server_api=ServerApi('1'))
|
|
@@ -136,7 +141,6 @@ def transform_image():
|
|
| 136 |
except Exception as e:
|
| 137 |
return {"error": str(e)}
|
| 138 |
|
| 139 |
-
|
| 140 |
@app.post("/classify-ecg")
|
| 141 |
async def classify_ecg(files: list[UploadFile] = File(...)):
|
| 142 |
model = joblib.load('voting_classifier.pkl')
|
|
@@ -166,4 +170,35 @@ async def classify_ecg(files: list[UploadFile] = File(...)):
|
|
| 166 |
for file_name in os.listdir(temp_dir):
|
| 167 |
file_path = os.path.join(temp_dir, file_name)
|
| 168 |
os.remove(file_path)
|
| 169 |
-
os.rmdir(temp_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import joblib
|
| 16 |
import numpy as np
|
| 17 |
from ECG import classify_new_ecg
|
| 18 |
+
from ultralytics import YOLO
|
| 19 |
+
import tensorflow as tf
|
| 20 |
+
from fastapi import HTTPException
|
| 21 |
|
| 22 |
|
| 23 |
app = FastAPI()
|
| 24 |
|
| 25 |
+
UPLOAD_DIR = "uploads"
|
| 26 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 27 |
# ✅ MongoDB connection
|
| 28 |
mongo_uri = "mongodb://husseinelhadidy03:W8ByXdBS4EFkZmd5@ac-lqfhgnk-shard-00-00.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-01.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-02.ycuagnj.mongodb.net:27017/?replicaSet=atlas-az5d0x-shard-0&ssl=true&authSource=admin&retryWrites=true&w=majority&appName=Cluster0"
|
| 29 |
client = MongoClient(mongo_uri, server_api=ServerApi('1'))
|
|
|
|
| 141 |
except Exception as e:
|
| 142 |
return {"error": str(e)}
|
| 143 |
|
|
|
|
| 144 |
@app.post("/classify-ecg")
|
| 145 |
async def classify_ecg(files: list[UploadFile] = File(...)):
|
| 146 |
model = joblib.load('voting_classifier.pkl')
|
|
|
|
| 170 |
for file_name in os.listdir(temp_dir):
|
| 171 |
file_path = os.path.join(temp_dir, file_name)
|
| 172 |
os.remove(file_path)
|
| 173 |
+
os.rmdir(temp_dir)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
@app.post("/process_video")
|
| 177 |
+
async def process_video(file: UploadFile = File(...)):
|
| 178 |
+
if not file.content_type.startswith("video/"):
|
| 179 |
+
raise HTTPException(status_code=400, detail="File must be a video.")
|
| 180 |
+
|
| 181 |
+
print("File content type:", file.content_type)
|
| 182 |
+
print("File filename:", file.filename)
|
| 183 |
+
# Save uploaded file
|
| 184 |
+
video_path = os.path.join(UPLOAD_DIR, file.filename)
|
| 185 |
+
with open(video_path, "wb") as buffer:
|
| 186 |
+
shutil.copyfileobj(file.file, buffer)
|
| 187 |
+
|
| 188 |
+
model = YOLO(r"C:\Users\husse\Desktop\All Courses\BackendElhaany\Deploy_El7a2ny_Application\yolo11n-pose_float16.tflite") # fixed variable name
|
| 189 |
+
|
| 190 |
+
print("Model loaded successfully")
|
| 191 |
+
|
| 192 |
+
# Run YOLO detection
|
| 193 |
+
try:
|
| 194 |
+
results = model(
|
| 195 |
+
source=video_path,
|
| 196 |
+
show=True, # Set True if running locally and want to view
|
| 197 |
+
save=True,
|
| 198 |
+
project="runs/detect",
|
| 199 |
+
name="testResult"
|
| 200 |
+
)
|
| 201 |
+
except Exception as e:
|
| 202 |
+
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 203 |
+
|
| 204 |
+
return JSONResponse(content={"message": "Video processed successfully", "result_dir": "runs/detect/testResult"})
|
main.py
CHANGED
|
@@ -15,10 +15,15 @@ import requests
|
|
| 15 |
import joblib
|
| 16 |
import numpy as np
|
| 17 |
from ECG import classify_new_ecg
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
|
|
|
|
|
|
| 22 |
# ✅ MongoDB connection
|
| 23 |
mongo_uri = "mongodb://husseinelhadidy03:W8ByXdBS4EFkZmd5@ac-lqfhgnk-shard-00-00.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-01.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-02.ycuagnj.mongodb.net:27017/?replicaSet=atlas-az5d0x-shard-0&ssl=true&authSource=admin&retryWrites=true&w=majority&appName=Cluster0"
|
| 24 |
client = MongoClient(mongo_uri, server_api=ServerApi('1'))
|
|
@@ -136,7 +141,6 @@ def transform_image():
|
|
| 136 |
except Exception as e:
|
| 137 |
return {"error": str(e)}
|
| 138 |
|
| 139 |
-
|
| 140 |
@app.post("/classify-ecg")
|
| 141 |
async def classify_ecg(files: list[UploadFile] = File(...)):
|
| 142 |
model = joblib.load('voting_classifier.pkl')
|
|
@@ -166,4 +170,35 @@ async def classify_ecg(files: list[UploadFile] = File(...)):
|
|
| 166 |
for file_name in os.listdir(temp_dir):
|
| 167 |
file_path = os.path.join(temp_dir, file_name)
|
| 168 |
os.remove(file_path)
|
| 169 |
-
os.rmdir(temp_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import joblib
|
| 16 |
import numpy as np
|
| 17 |
from ECG import classify_new_ecg
|
| 18 |
+
from ultralytics import YOLO
|
| 19 |
+
import tensorflow as tf
|
| 20 |
+
from fastapi import HTTPException
|
| 21 |
|
| 22 |
|
| 23 |
app = FastAPI()
|
| 24 |
|
| 25 |
+
UPLOAD_DIR = "uploads"
|
| 26 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 27 |
# ✅ MongoDB connection
|
| 28 |
mongo_uri = "mongodb://husseinelhadidy03:W8ByXdBS4EFkZmd5@ac-lqfhgnk-shard-00-00.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-01.ycuagnj.mongodb.net:27017,ac-lqfhgnk-shard-00-02.ycuagnj.mongodb.net:27017/?replicaSet=atlas-az5d0x-shard-0&ssl=true&authSource=admin&retryWrites=true&w=majority&appName=Cluster0"
|
| 29 |
client = MongoClient(mongo_uri, server_api=ServerApi('1'))
|
|
|
|
| 141 |
except Exception as e:
|
| 142 |
return {"error": str(e)}
|
| 143 |
|
|
|
|
| 144 |
@app.post("/classify-ecg")
|
| 145 |
async def classify_ecg(files: list[UploadFile] = File(...)):
|
| 146 |
model = joblib.load('voting_classifier.pkl')
|
|
|
|
| 170 |
for file_name in os.listdir(temp_dir):
|
| 171 |
file_path = os.path.join(temp_dir, file_name)
|
| 172 |
os.remove(file_path)
|
| 173 |
+
os.rmdir(temp_dir)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
@app.post("/process_video")
|
| 177 |
+
async def process_video(file: UploadFile = File(...)):
|
| 178 |
+
if not file.content_type.startswith("video/"):
|
| 179 |
+
raise HTTPException(status_code=400, detail="File must be a video.")
|
| 180 |
+
|
| 181 |
+
print("File content type:", file.content_type)
|
| 182 |
+
print("File filename:", file.filename)
|
| 183 |
+
# Save uploaded file
|
| 184 |
+
video_path = os.path.join(UPLOAD_DIR, file.filename)
|
| 185 |
+
with open(video_path, "wb") as buffer:
|
| 186 |
+
shutil.copyfileobj(file.file, buffer)
|
| 187 |
+
|
| 188 |
+
model = YOLO(r"C:\Users\husse\Desktop\All Courses\BackendElhaany\Deploy_El7a2ny_Application\yolo11n-pose_float16.tflite") # fixed variable name
|
| 189 |
+
|
| 190 |
+
print("Model loaded successfully")
|
| 191 |
+
|
| 192 |
+
# Run YOLO detection
|
| 193 |
+
try:
|
| 194 |
+
results = model(
|
| 195 |
+
source=video_path,
|
| 196 |
+
show=True, # Set True if running locally and want to view
|
| 197 |
+
save=True,
|
| 198 |
+
project="runs/detect",
|
| 199 |
+
name="testResult"
|
| 200 |
+
)
|
| 201 |
+
except Exception as e:
|
| 202 |
+
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 203 |
+
|
| 204 |
+
return JSONResponse(content={"message": "Video processed successfully", "result_dir": "runs/detect/testResult"})
|
requirements.txt
CHANGED
|
@@ -1,21 +1,104 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
joblib==1.4.2
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
absl-py==2.2.2
|
| 2 |
+
aiohappyeyeballs==2.6.1
|
| 3 |
+
aiohttp==3.11.16
|
| 4 |
+
aiosignal==1.3.2
|
| 5 |
+
annotated-types==0.7.0
|
| 6 |
+
anyio==4.9.0
|
| 7 |
+
astunparse==1.6.3
|
| 8 |
+
async-timeout==5.0.1
|
| 9 |
+
attrs==25.3.0
|
| 10 |
+
certifi==2025.1.31
|
| 11 |
+
cffi==1.17.1
|
| 12 |
+
charset-normalizer==3.4.1
|
| 13 |
+
click==8.1.8
|
| 14 |
+
cloudinary==1.44.0
|
| 15 |
+
colorama==0.4.6
|
| 16 |
+
contourpy==1.3.2
|
| 17 |
+
cycler==0.12.1
|
| 18 |
+
dnspython==2.7.0
|
| 19 |
+
exceptiongroup==1.2.2
|
| 20 |
+
fastapi==0.115.12
|
| 21 |
+
filelock==3.18.0
|
| 22 |
+
flatbuffers==25.2.10
|
| 23 |
+
fonttools==4.57.0
|
| 24 |
+
frozenlist==1.6.0
|
| 25 |
+
fsspec==2025.3.2
|
| 26 |
+
gast==0.6.0
|
| 27 |
+
google-pasta==0.2.0
|
| 28 |
+
grpcio==1.71.0
|
| 29 |
+
h11==0.14.0
|
| 30 |
+
h5py==3.13.0
|
| 31 |
+
idna==3.10
|
| 32 |
+
imageio==2.37.0
|
| 33 |
+
Jinja2==3.1.6
|
| 34 |
joblib==1.4.2
|
| 35 |
+
keras==3.9.2
|
| 36 |
+
kiwisolver==1.4.8
|
| 37 |
+
lazy_loader==0.4
|
| 38 |
+
libclang==18.1.1
|
| 39 |
+
Markdown==3.8
|
| 40 |
+
markdown-it-py==3.0.0
|
| 41 |
+
MarkupSafe==3.0.2
|
| 42 |
+
matplotlib==3.10.1
|
| 43 |
+
mdurl==0.1.2
|
| 44 |
+
ml-dtypes==0.4.1
|
| 45 |
+
mpmath==1.3.0
|
| 46 |
+
multidict==6.4.3
|
| 47 |
+
namex==0.0.8
|
| 48 |
+
networkx==3.4.2
|
| 49 |
+
numpy==2.0.2
|
| 50 |
+
opencv-python==4.11.0.86
|
| 51 |
+
opt_einsum==3.4.0
|
| 52 |
+
optree==0.15.0
|
| 53 |
+
packaging==25.0
|
| 54 |
+
pandas==2.2.3
|
| 55 |
+
pillow==11.2.1
|
| 56 |
+
propcache==0.3.1
|
| 57 |
+
protobuf==5.29.4
|
| 58 |
+
psutil==7.0.0
|
| 59 |
+
py-cpuinfo==9.0.0
|
| 60 |
+
pycparser==2.22
|
| 61 |
+
pydantic==2.11.3
|
| 62 |
+
pydantic_core==2.33.1
|
| 63 |
+
Pygments==2.19.1
|
| 64 |
+
pymongo==4.12.0
|
| 65 |
+
pyparsing==3.2.3
|
| 66 |
+
python-dateutil==2.9.0.post0
|
| 67 |
+
python-multipart==0.0.20
|
| 68 |
+
pytz==2025.2
|
| 69 |
+
PyWavelets==1.8.0
|
| 70 |
+
PyYAML==6.0.2
|
| 71 |
+
requests==2.32.3
|
| 72 |
+
rich==14.0.0
|
| 73 |
+
scikit-image==0.25.2
|
| 74 |
+
scikit-learn==1.6.1
|
| 75 |
+
scipy==1.15.2
|
| 76 |
+
seaborn==0.13.2
|
| 77 |
+
six==1.17.0
|
| 78 |
+
sniffio==1.3.1
|
| 79 |
+
soundfile==0.13.1
|
| 80 |
+
starlette==0.46.2
|
| 81 |
+
sympy==1.13.1
|
| 82 |
+
tensorboard==2.18.0
|
| 83 |
+
tensorboard-data-server==0.7.2
|
| 84 |
+
tensorflow==2.18.0
|
| 85 |
+
tensorflow-io-gcs-filesystem==0.31.0
|
| 86 |
+
tensorflow_intel==2.18.0
|
| 87 |
+
tensorly==0.9.0
|
| 88 |
+
termcolor==3.0.1
|
| 89 |
+
threadpoolctl==3.6.0
|
| 90 |
+
tifffile==2025.3.30
|
| 91 |
+
torch==2.6.0
|
| 92 |
+
torchvision==0.21.0
|
| 93 |
+
tqdm==4.67.1
|
| 94 |
+
typing-inspection==0.4.0
|
| 95 |
+
typing_extensions==4.13.2
|
| 96 |
+
tzdata==2025.2
|
| 97 |
+
ultralytics==8.3.111
|
| 98 |
+
ultralytics-thop==2.0.14
|
| 99 |
+
urllib3==2.4.0
|
| 100 |
+
uvicorn==0.34.2
|
| 101 |
+
Werkzeug==3.1.3
|
| 102 |
+
wfdb==4.3.0
|
| 103 |
+
wrapt==1.17.2
|
| 104 |
+
yarl==1.20.0
|