Shiwanni commited on
Commit
4307fea
·
verified ·
1 Parent(s): dec8025

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from detect import DeepfakeDetector
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+ detector = DeepfakeDetector()
7
+
8
+ @app.route("/")
9
+ def home():
10
+ return render_template("index.html")
11
+
12
+ @app.route("/detect", methods=["POST"])
13
+ def detect():
14
+ if "file" not in request.files:
15
+ return jsonify({"error": "No file uploaded"}), 400
16
+
17
+ file = request.files["file"]
18
+ if file.filename == "":
19
+ return jsonify({"error": "Empty filename"}), 400
20
+
21
+ temp_path = f"temp_{file.filename}"
22
+ file.save(temp_path)
23
+
24
+ try:
25
+ result = detector.detect_from_file(temp_path)
26
+ return jsonify({"result": result})
27
+ finally:
28
+ if os.path.exists(temp_path):
29
+ os.remove(temp_path)
30
+
31
+ if __name__ == "__main__":
32
+ app.run(debug=True)