darpanaswal commited on
Commit
0923429
·
verified ·
1 Parent(s): 2a60598

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -1,15 +1,14 @@
1
  from flask import Flask, render_template, request, send_file
2
- # Import your attendance model and processing functions
 
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.save("image.jpeg")
24
- # # Access file properties
25
- # filename = file.filename
26
- # content_type = file.content_type
27
- # file_size = len(file.read())
28
-
29
- # # Reset file cursor to the beginning after reading it
30
- # file.seek(0)
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)