AarohiSingla / Object-Detection-Web-App-Using-YOLOv7-and-Flask

Object Detection Web App Using YOLOv7 and Flask
50 stars 20 forks source link

webapp.py not working properly #1

Open ardaxz99 opened 1 year ago

ardaxz99 commented 1 year ago
filename = predict_img.imgpath

AttributeError: 'function' object has no attribute 'imgpath'

AarohiSingla commented 1 year ago

imgpath is a variable present in predict_img function. Check if you have the same function name in which you are using imgpath variable.

anikaafrin commented 1 year ago

I am also facing the same problem. Kindly help. There is no variable in your predict_img function. rather its written predict_img.imgpath = f.filename in that function as well.

AarohiSingla commented 1 year ago

imgpath is a variable which is present in predict_img function. If this is not working for you then you can use imgpath variable directly and provide it a image path where ever your image is stored. Refer predict_image function where I have used this : predict_img.imgpath = f.filename

AarohiSingla commented 1 year ago

Modify the display function:

@app.route('/')

def display(filename): folder_path = 'runs/detect' subfolders = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]
latest_subfolder = max(subfolders, key=lambda x: os.path.getctime(os.path.join(folder_path, x)))
directory = folder_path+'/'+latest_subfolder print("printing directory: ",directory)
files = os.listdir(directory) latest_file = files[0] print(latest_file) filename = os.path.join(folder_path, latest_subfolder, latest_file) print("#################",filename) file_extension = filename.rsplit('.', 1)[1].lower() environ = request.environ if file_extension == 'jpg':
return send_from_directory(directory,filename,environ) elif file_extension == 'mp4': return render_template('index.html') else: return "Invalid file format"

Priyanshu88 commented 1 year ago

Getting this error on terminal after applying your code as well. image

AarohiSingla commented 1 year ago

Please check your display function. In the shared screenshot You have this "TypeError: display() missing 1 required positional argument 'filename' " You need to provide the filename argument in display function.