osamaifti commited on
Commit
5cc192b
1 Parent(s): fa1fa67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -6
app.py CHANGED
@@ -19,17 +19,54 @@ class ShelfClassifier:
19
  class_label = "Disorganized or Empty" if class_index == 1 else "Organized"
20
  return class_label
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  @app.route('/', methods=['GET', 'POST'])
23
  def upload_image():
24
  if request.method == 'POST':
25
  # Check if the post request has the file part
26
  if 'file' not in request.files:
27
- return render_template('index.html', message='No file part')
28
  file = request.files['file']
29
  # If user does not select file, browser also
30
  # submit an empty part without filename
31
  if file.filename == '':
32
- return render_template('index.html', message='No selected file')
33
  if file:
34
  # Read uploaded image
35
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
@@ -43,8 +80,8 @@ def upload_image():
43
  cv2.rectangle(image, (0, 0), (image.shape[1], image.shape[0]), (255, 0, 0), 2)
44
  # Save image with bounding box
45
  cv2.imwrite('result.jpg', image)
46
- return render_template('result.html', class_label=class_label)
47
- return render_template('index.html')
48
 
49
- if __name__ == '__main__':
50
- app.run(debug=True)
 
19
  class_label = "Disorganized or Empty" if class_index == 1 else "Organized"
20
  return class_label
21
 
22
+ index_html = """
23
+ <!DOCTYPE html>
24
+ <html lang="en">
25
+ <head>
26
+ <meta charset="UTF-8">
27
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
28
+ <title>Shelf Classifier</title>
29
+ </head>
30
+ <body>
31
+ <h1>Shelf Classifier</h1>
32
+ <form method="POST" enctype="multipart/form-data">
33
+ <input type="file" name="file">
34
+ <input type="submit" value="Upload">
35
+ </form>
36
+ {% if message %}
37
+ <p>{{ message }}</p>
38
+ {% endif %}
39
+ </body>
40
+ </html>
41
+ """
42
+
43
+ result_html = """
44
+ <!DOCTYPE html>
45
+ <html lang="en">
46
+ <head>
47
+ <meta charset="UTF-8">
48
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
49
+ <title>Classification Result</title>
50
+ </head>
51
+ <body>
52
+ <h1>Classification Result</h1>
53
+ <p>{{ class_label }}</p>
54
+ <img src="result.jpg" alt="Result Image">
55
+ </body>
56
+ </html>
57
+ """
58
+
59
  @app.route('/', methods=['GET', 'POST'])
60
  def upload_image():
61
  if request.method == 'POST':
62
  # Check if the post request has the file part
63
  if 'file' not in request.files:
64
+ return render_template_string(index_html, message='No file part')
65
  file = request.files['file']
66
  # If user does not select file, browser also
67
  # submit an empty part without filename
68
  if file.filename == '':
69
+ return render_template_string(index_html, message='No selected file')
70
  if file:
71
  # Read uploaded image
72
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
 
80
  cv2.rectangle(image, (0, 0), (image.shape[1], image.shape[0]), (255, 0, 0), 2)
81
  # Save image with bounding box
82
  cv2.imwrite('result.jpg', image)
83
+ return render_template_string(result_html, class_label=class_label)
84
+ return render_template_string(index_html)
85
 
86
+ if __name__ == '__main__':
87
+ app.run(debug=True)