File size: 1,110 Bytes
b29dd97 |
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 |
from flask import Flask, render_template, request, send_from_directory
import os
from model_loader import get_model
from utils import process_video
app = Flask(__name__)
UPLOAD_FOLDER = 'static/uploads'
RESULT_FOLDER = 'static/results'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(RESULT_FOLDER, exist_ok=True)
num_classes = 21
model, device = get_model(num_classes)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
file = request.files['video']
if file:
filepath = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(filepath)
output_path = os.path.join(RESULT_FOLDER, 'result_' + file.filename)
result_path = process_video(filepath, model, output_path, device)
return render_template('index.html', video_result=result_path)
return render_template('index.html', video_result=None)
@app.route('/static/<path:path>')
def send_static(path):
return send_from_directory('static', path)
if __name__ == '__main__':
app.run(debug=True)
|