saurabh091 commited on
Commit
cb4f607
·
verified ·
1 Parent(s): 75451dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -7,17 +7,15 @@ import os
7
  import pandas as pd
8
  import shutil
9
 
10
- os.mkdir("/tmp/nice")
11
- shutil.rmtree("/tmp/nice")
12
 
13
- def clr_static():
14
  """
15
  for removing the static folder (for memoery saving in web)
16
  """
17
  dir = '/tmp/static'
18
  try:
19
  shutil.rmtree(dir)
20
- print("Cleared Static")
21
  except:
22
  pass
23
 
@@ -27,8 +25,8 @@ def clr_old_upload():
27
  """
28
  dir = '/tmp/UPLOAD_FOLDER'
29
  try:
30
- shutil.rmtree(dir)
31
- print("Cleared UPLOAD_FOLDER")
32
  except:
33
  pass
34
 
@@ -43,14 +41,14 @@ def mk_csv_folder():
43
 
44
  #Creating UPLOAD_FOLDER dir to save the Uploaded file
45
  def mk_uploaded_folder():
46
- try:
47
- os.mkdir("/tmp/UPLOAD_FOLDER")
48
- print("made UPLOAD_FOLDER")
49
- except:
50
- pass
51
 
52
  #Creating static dir to save the generated file
53
- def mk_static_folder():
54
  try:
55
  os.mkdir("/tmp/static")
56
  print("made static folder")
@@ -71,7 +69,7 @@ def Use_yolo(img_path):
71
 
72
  results = model(img_path, conf=0.1, verbose=False)
73
  model.predict(img_path, save=True, conf=0.2, show_labels=True,
74
- project='static', name="Image_Prediction")
75
  # Extract bounding boxes, confidence scores, and class labels
76
  boxes = results[0].boxes.xyxy.tolist() # Bounding boxes in xyxy format
77
  classes = results[0].boxes.cls.tolist() # Class indices
@@ -137,26 +135,25 @@ def wbc_info_click():
137
  def upload():
138
  try:
139
  if request.method == 'POST':
140
-
141
  ## clearing old files and folders and creating Folders for saving file
142
  clr_old_upload()
143
- clr_static()
144
- mk_static_folder()
145
  mk_uploaded_folder()
146
  mk_csv_folder()
147
  show_csv_heading = False ## This is set so that co-ordinates table heading will only whow when it is true
148
  f = request.files['fileInput'] ## geting path of input file
149
 
150
  f.save(os.path.join(app.config["UPLOAD_FOLDER"], secure_filename(f.filename) )) ## saving the input image file in UPLOAD_FOLDER
151
- imageList = os.listdir("UPLOAD_FOLDER") # geting listv of image files in UPLOAD_FOLDER
152
 
153
  for image in imageList:
154
  ### Applying yolo model for object detection on uploaded files
155
- Use_yolo("UPLOAD_FOLDER/"+image)
156
 
157
- pred_image_list = os.listdir("static/Image_Prediction") ## geting the file path of generated image having object detection
158
 
159
- df = pd.read_csv("static/CSV_File/WBC_File.csv") # Reading CSV File
160
  # Convert DataFrame to a list of dictionaries
161
  data = df.to_dict(orient='records')
162
  show_csv_heading = True
@@ -166,5 +163,4 @@ def upload():
166
  return render_template("error.html")
167
 
168
  if __name__ == "__main__":
169
- app.run(host='0.0.0.0', port=7860)
170
-
 
7
  import pandas as pd
8
  import shutil
9
 
 
 
10
 
11
+ def clr_pred():
12
  """
13
  for removing the static folder (for memoery saving in web)
14
  """
15
  dir = '/tmp/static'
16
  try:
17
  shutil.rmtree(dir)
18
+ print("Cleared Previous Predictions")
19
  except:
20
  pass
21
 
 
25
  """
26
  dir = '/tmp/UPLOAD_FOLDER'
27
  try:
28
+ shutil.rmtree(dir)
29
+ print("Cleared UPLOAD_FOLDER")
30
  except:
31
  pass
32
 
 
41
 
42
  #Creating UPLOAD_FOLDER dir to save the Uploaded file
43
  def mk_uploaded_folder():
44
+ # try:
45
+ os.mkdir("/tmp/UPLOAD_FOLDER")
46
+ print("made UPLOAD_FOLDER")
47
+ # except:
48
+ # pass
49
 
50
  #Creating static dir to save the generated file
51
+ def mk_pred_folder():
52
  try:
53
  os.mkdir("/tmp/static")
54
  print("made static folder")
 
69
 
70
  results = model(img_path, conf=0.1, verbose=False)
71
  model.predict(img_path, save=True, conf=0.2, show_labels=True,
72
+ project='/tmp/static', name="Image_Prediction")
73
  # Extract bounding boxes, confidence scores, and class labels
74
  boxes = results[0].boxes.xyxy.tolist() # Bounding boxes in xyxy format
75
  classes = results[0].boxes.cls.tolist() # Class indices
 
135
  def upload():
136
  try:
137
  if request.method == 'POST':
 
138
  ## clearing old files and folders and creating Folders for saving file
139
  clr_old_upload()
140
+ clr_pred()
141
+ mk_pred_folder()
142
  mk_uploaded_folder()
143
  mk_csv_folder()
144
  show_csv_heading = False ## This is set so that co-ordinates table heading will only whow when it is true
145
  f = request.files['fileInput'] ## geting path of input file
146
 
147
  f.save(os.path.join(app.config["UPLOAD_FOLDER"], secure_filename(f.filename) )) ## saving the input image file in UPLOAD_FOLDER
148
+ imageList = os.listdir("/tmp/UPLOAD_FOLDER") # geting listv of image files in UPLOAD_FOLDER
149
 
150
  for image in imageList:
151
  ### Applying yolo model for object detection on uploaded files
152
+ Use_yolo("/tmp/UPLOAD_FOLDER/"+image)
153
 
154
+ pred_image_list = os.listdir("/tmp/static/Image_Prediction") ## geting the file path of generated image having object detection
155
 
156
+ df = pd.read_csv("/tmp/static/CSV_File/WBC_File.csv") # Reading CSV File
157
  # Convert DataFrame to a list of dictionaries
158
  data = df.to_dict(orient='records')
159
  show_csv_heading = True
 
163
  return render_template("error.html")
164
 
165
  if __name__ == "__main__":
166
+ app.run(debug=True)