Gagan0141 commited on
Commit
7549365
·
verified ·
1 Parent(s): fda03c7

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +14 -49
templates/index.html CHANGED
@@ -1,49 +1,14 @@
1
- from flask import Flask, render_template, request, jsonify
2
- from deepface import DeepFace
3
- import tempfile
4
- import os
5
-
6
- app = Flask(__name__, template_folder="templates", static_folder="static")
7
-
8
- # preload models once for performance
9
- models_cache = {
10
- "emotion": DeepFace.build_model("Emotion")
11
- }
12
-
13
- @app.route("/")
14
- def index():
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>