Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1 |
from flask import Flask, render_template, request, send_file
|
2 |
-
|
|
|
3 |
from run import predict_and_show
|
4 |
|
5 |
app = Flask("Ogs")
|
6 |
|
7 |
-
|
8 |
@app.route('/')
|
9 |
def index():
|
10 |
return render_template('index.html')
|
11 |
|
12 |
-
|
13 |
@app.route('/upload', methods=['POST'])
|
14 |
def upload():
|
15 |
if 'file' not in request.files:
|
@@ -20,23 +19,17 @@ def upload():
|
|
20 |
if file.filename == '':
|
21 |
return "No selected file"
|
22 |
|
23 |
-
file
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# # Read the content of the uploaded image
|
33 |
-
# image_content = file.read()
|
34 |
-
|
35 |
-
# Process the image using your attendance model
|
36 |
-
predict_and_show("image.jpeg")
|
37 |
|
38 |
return send_file("attendance.csv", as_attachment=True)
|
39 |
|
40 |
-
|
41 |
if __name__ == '__main__':
|
42 |
app.run(debug=True)
|
|
|
1 |
from flask import Flask, render_template, request, send_file
|
2 |
+
import tempfile
|
3 |
+
import os
|
4 |
from run import predict_and_show
|
5 |
|
6 |
app = Flask("Ogs")
|
7 |
|
|
|
8 |
@app.route('/')
|
9 |
def index():
|
10 |
return render_template('index.html')
|
11 |
|
|
|
12 |
@app.route('/upload', methods=['POST'])
|
13 |
def upload():
|
14 |
if 'file' not in request.files:
|
|
|
19 |
if file.filename == '':
|
20 |
return "No selected file"
|
21 |
|
22 |
+
# Use a temporary file to avoid permission issues
|
23 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
24 |
+
file.save(temp_file.name)
|
25 |
+
# Ensure the file is saved before processing
|
26 |
+
temp_file.flush()
|
27 |
+
# Process the image
|
28 |
+
predict_and_show(temp_file.name)
|
29 |
+
# Clean up if necessary
|
30 |
+
os.unlink(temp_file.name)
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
return send_file("attendance.csv", as_attachment=True)
|
33 |
|
|
|
34 |
if __name__ == '__main__':
|
35 |
app.run(debug=True)
|