Update Backend/app.py
Browse files- Backend/app.py +10 -4
Backend/app.py
CHANGED
@@ -10,11 +10,16 @@ import cv2
|
|
10 |
import os
|
11 |
import traceback
|
12 |
from keras.models import load_model
|
|
|
|
|
13 |
|
14 |
# Load the trained model
|
15 |
model_path = os.path.join(os.path.dirname(__file__), 'emotion_model.keras')
|
16 |
model = load_model(model_path)
|
17 |
|
|
|
|
|
|
|
18 |
# Emotion and emoji maps
|
19 |
emotion_dict = {
|
20 |
0: "Angry", 1: "Disgusted", 2: "Fearful", 3: "Happy",
|
@@ -48,11 +53,12 @@ class ImageData(BaseModel):
|
|
48 |
# Load Haarcascade once
|
49 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
-
@app.post("/")
|
56 |
async def process_image(data: ImageData):
|
57 |
try:
|
58 |
header, encoded = data.image.split(",")
|
|
|
10 |
import os
|
11 |
import traceback
|
12 |
from keras.models import load_model
|
13 |
+
from fastapi.responses import FileResponse
|
14 |
+
from fastapi.staticfiles import StaticFiles
|
15 |
|
16 |
# Load the trained model
|
17 |
model_path = os.path.join(os.path.dirname(__file__), 'emotion_model.keras')
|
18 |
model = load_model(model_path)
|
19 |
|
20 |
+
# Mount the frontend folder to serve static files
|
21 |
+
app.mount("/static", StaticFiles(directory="Frontend"), name="static")
|
22 |
+
|
23 |
# Emotion and emoji maps
|
24 |
emotion_dict = {
|
25 |
0: "Angry", 1: "Disgusted", 2: "Fearful", 3: "Happy",
|
|
|
53 |
# Load Haarcascade once
|
54 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
55 |
|
56 |
+
@app.get("/")
|
57 |
+
def serve_homepage():
|
58 |
+
return FileResponse("Frontend/index.html")
|
59 |
+
|
60 |
|
61 |
+
@app.post("/process_image")
|
62 |
async def process_image(data: ImageData):
|
63 |
try:
|
64 |
header, encoded = data.image.split(",")
|