Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +14 -49
templates/index.html
CHANGED
|
@@ -1,49 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"emotion":
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return render_template("index.html")
|
| 16 |
-
|
| 17 |
-
@app.route("/detect_live", methods=["POST"])
|
| 18 |
-
def detect_live():
|
| 19 |
-
if "frame" not in request.files:
|
| 20 |
-
return jsonify({"error": "no frame uploaded"}), 400
|
| 21 |
-
|
| 22 |
-
file = request.files["frame"]
|
| 23 |
-
|
| 24 |
-
tmp = tempfile.NamedTemporaryFile(delete=False)
|
| 25 |
-
file.save(tmp.name)
|
| 26 |
-
|
| 27 |
-
try:
|
| 28 |
-
result = DeepFace.analyze(
|
| 29 |
-
tmp.name,
|
| 30 |
-
actions=["emotion"],
|
| 31 |
-
models=models_cache,
|
| 32 |
-
enforce_detection=False
|
| 33 |
-
)
|
| 34 |
-
except Exception as e:
|
| 35 |
-
os.remove(tmp.name)
|
| 36 |
-
return jsonify({"error": str(e)}), 500
|
| 37 |
-
|
| 38 |
-
os.remove(tmp.name)
|
| 39 |
-
|
| 40 |
-
dominant = result[0]["dominant_emotion"]
|
| 41 |
-
scores = result[0]["emotion"]
|
| 42 |
-
|
| 43 |
-
return jsonify({
|
| 44 |
-
"emotion": dominant,
|
| 45 |
-
"scores": scores
|
| 46 |
-
})
|
| 47 |
-
|
| 48 |
-
if __name__ == "__main__":
|
| 49 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Emotion Detection</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<h2>Live Emotion Detection</h2>
|
| 8 |
+
|
| 9 |
+
<video id="webcam" autoplay playsinline width="420"></video>
|
| 10 |
+
<p id="emotion">Emotion: ...</p>
|
| 11 |
+
|
| 12 |
+
<script src="/static/script.js"></script>
|
| 13 |
+
</body>
|
| 14 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|