-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (42 loc) · 2.18 KB
/
Copy pathapp.py
File metadata and controls
55 lines (42 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, render_template, request, redirect, url_for
import os
from datetime import datetime
from web.utils.predictor import ForgeryPredictor
from werkzeug.utils import secure_filename
# Initialize Flask app with correct template folder
app = Flask(__name__,
template_folder='web/templates',
static_folder='web/static')
app.config['UPLOAD_FOLDER'] = 'web/static/uploads'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
# Ensure upload directory exists
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
predictor = ForgeryPredictor()
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
try:
if 'file' not in request.files:
return render_template('result.html', error='No file uploaded')
file = request.files['file']
if file.filename == '':
return render_template('result.html', error='No file selected')
if not file.filename.lower().endswith(('.png', '.jpg', '.jpeg')):
return render_template('result.html', error='Invalid file type. Please upload a PNG, JPG, or JPEG image.')
# Save the uploaded file
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(file_path)
# Process the image
prediction, confidence = predictor.process_upload(file_path)
return render_template('result.html',
prediction=prediction,
confidence=confidence,
result_class='authentic' if prediction == 'Authentic' else 'tampered',
filename=filename,
analysis_date=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
except Exception as e:
return render_template('result.html', error=str(e))
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)