async def upload_image(user_id: str, image: Optional[UploadFile] = File(None)): if image is None: return {"error": "File not uploaded."} image_path = '/Database/val/person/' + user_id + '.jpg' image = load_image_into_numpy_array(await image.read()) person = Image.fromarray(image) req_size = (192, 256) if person.size != req_size: person = person.resize(req_size) person.save('.' + image_path) pose_parse(user_id) execute() image_url = serverURL + image_path return {"image_url": image_url}
def final_img(): global name, selection person = Image.open('temp.jpg') person.save("./Database/val/person/" + name + ".jpg") pose_parse(name) execute() f = open("./Database/val_pairs.txt", "w") f.write(name + ".jpg " + selection + "_1.jpg") f.close() predict() im = Image.open("./output/second/TOM/val/" + selection + "_1.jpg") width, height = im.size left = width / 3 top = 2 * height / 3 right = width bottom = height im1 = im.crop((left, top, right, bottom)) newsize = (600, 450) im1 = im1.resize(newsize) im1.save("./output/second/TOM/val/" + selection + "_1.jpg") result = Image.open("./output/second/TOM/val/" + selection + "_1.jpg") result.save("data.jpg") return Response(gen_stored("data.jpg"), mimetype='multipart/x-mixed-replace; boundary=frame')
['', '002337', '002599', '003086'], format_func=lambda x: 'Select an option' if x == '' else x) if uploaded_person is not None and user_input is not '' and selected is not '': person = Image.open(uploaded_person) st.image(person, caption=user_input, width=100, use_column_width=False) st.write("Saving Image") bar = st.progress(0) for percent_complete in range(100): time.sleep(0.09) bar.progress(percent_complete + 1) person.save("./Database/val/person/" + user_input + ".jpg") progress_bar = st.progress(0) st.write("Generating Mask and Pose Pairs") pose_parse(user_input) execute() for percent_complete in range(100): time.sleep(0.05) progress_bar.progress(percent_complete + 1) st.write( "Please click the Click Button after Pose pairs and Masks are generated" ) if st.button('Execute'): f = open("./Database/val_pairs.txt", "w") f.write(user_input + ".jpg " + selected + "_1.jpg") f.close() predict() from PIL import Image im = Image.open("./output/second/TOM/val/" + selected + "_1.jpg")
def upload_image4(): cache.init_app(app2) with app2.app_context(): cache.clear() party_cloth = ['000003' , '000108', '001719' ,'017376' ,'000178', '000182' , '001428' , '004710' , '008632' , '017374','002061', '017642', '017377', '017963', '018348', '019067','019564', '017643'] for i in range(len(party_cloth)): party_cloth[i] = (str(party_cloth[i])+"_1.jpg") if request.method=="POST": # if 'file' not in request.files: # flash('No file part') # return redirect(request.url) text = request.form['input_text'] file = request.files['file'] if file.filename == '': flash('No image selected for uploading') return redirect(request.url) if file and allowed_file(file.filename) and text: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text+'.jpg' os.rename(i_path+filename , i_path+input_img) filename = text+'.jpg' o_path = './output/second/TOM/val' # fish = glob.glob('./output/second/TOM/val/*') fish = glob.glob('./static/output_f/*') for f in fish: os.remove(f) time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(party_cloth)): with open(valpair_file , "w") as f: f.write(text+'.jpg '+ party_cloth[i] ) f.close() predict() im = Image.open(os.path.join(o_path,party_cloth[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save(os.path.join(app2.config['OUTPUT_FOLDER3'],party_cloth[i])) # # # return render_template('party_wear.html', party=party_cloth, text= text) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('party_wear.html')
def upload_image5(): cache.init_app(app2) with app2.app_context(): cache.clear() fish = glob.glob('./static/Database/val/person/*') for f in fish: os.remove(f) fish = glob.glob('./static/size/*') for f in fish: os.remove(f) tshirt = [ 'POLO_Black', 'POLO-blue', 'POLO-Blue', 'POLO-BLue', 'POLO-orach', 'POLO-Violet' ] for i in range(len(tshirt)): tshirt[i] = (str(tshirt[i]) + ".jpg") if request.method == "POST": text = "tshirtss" file = request.files['file'] file1 = request.files['file1'] height = request.form['height'] unit = request.form.get('unit') Go = "False" if file.filename == '': flash('No image uploaded for size prediction.') return redirect(request.url) if file1.filename == '': flash('No image uploaded for trying clothes.') return redirect(request.url) if file and allowed_file(file.filename) and file1 and allowed_file( file1.filename) and height and unit and text: filename = secure_filename(file.filename) filename1 = secure_filename(file1.filename) file1.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename1)) i_path = 'static/size/' file_path = os.path.join(i_path, filename1) size = women_size_predict(file_path, height, unit) # file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text + '.jpg' os.rename(i_path + filename, i_path + input_img) filename = text + '.jpg' o_path = './output/second/TOM/val' # time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(tshirt)): with open(valpair_file, "w") as f: f.write(text + '.jpg ' + tshirt[i]) f.close() predict() im = Image.open(os.path.join(o_path, tshirt[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save( os.path.join(app2.config['OUTPUT_FOLDER3'], tshirt[i])) # # # ## ## return render_template('tshirt.html', tshirt=tshirt, text=text, size=size) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('tshirt.html')
def upload_image4(): cache.init_app(app2) with app2.app_context(): cache.clear() fish = glob.glob('./static/Database/val/person/*') for f in fish: os.remove(f) fish = glob.glob('./static/size/*') for f in fish: os.remove(f) party = [ 'Orach-Flayrd', 'MultiColor', 'Butterfly_p', 'Waved-Black', 'Shimm', 'Wavy-Red', 'Wavy-Pink', 'Reddish-KNOTS' ] for i in range(len(party)): party[i] = (str(party[i]) + ".jpg") if request.method == "POST": text = "palty" file = request.files['file'] height = request.form['height'] unit = request.form.get('unit') Go = "False" if file.filename == '': flash('No image uploaded for trying clothes.') return redirect(request.url) if file and allowed_file(file.filename) and height and unit and text: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename)) i_path = 'static/size/' file_path = os.path.join(i_path, filename) size, file = women_size_predict1(file_path, height, unit) file = Image.fromarray(file, 'RGB') # file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text + '.jpg' os.rename(i_path + filename, i_path + input_img) filename = text + '.jpg' o_path = './output/second/TOM/val' # fish = glob.glob('./output/second/TOM/val/*') fish = glob.glob('./static/outputs/output_f/*') for f in fish: os.remove(f) time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(party)): with open(valpair_file, "w") as f: f.write(text + '.jpg ' + party[i]) f.close() predict() im = Image.open(os.path.join(o_path, party[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save( os.path.join(app2.config['OUTPUT_FOLDER3'], party[i])) # # # ## ## return render_template('party_wear.html', party=party, text=text, size=size) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('party_wear.html')
def upload_image3(): cache.init_app(app2) with app2.app_context(): cache.clear() fish = glob.glob('./static/Database/val/person/*') for f in fish: os.remove(f) fish = glob.glob('./static/size/*') for f in fish: os.remove(f) brand_cloth = [ 'Pink-Flayrd', 'Blue-flayrd', 'Flayerd-Yellow', 'Bluish-Flayrd', 'NIKE-black', 'RED-Flayrd' ] #' for i in range(len(brand_cloth)): brand_cloth[i] = (str(brand_cloth[i]) + ".jpg") if request.method == "POST": text = "brandss" file = request.files['file'] height = request.form['height'] unit = request.form.get('unit') if file.filename == '': flash('No image selected for uploading') return redirect(request.url) if file and allowed_file(file.filename) and height and unit: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename)) i_path = 'static/size/' file_path = os.path.join(i_path, filename) size, file = women_size_predict1(file_path, height, unit) file = Image.fromarray(file, 'RGB') # file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text + '.jpg' os.rename(i_path + filename, i_path + input_img) filename = text + '.jpg' o_path = './output/second/TOM/val' # fish = glob.glob('./output/second/TOM/val/*') fish = glob.glob('./static/outputs/output_f/*') for f in fish: os.remove(f) time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(brand_cloth)): with open(valpair_file, "w") as f: f.write(text + '.jpg ' + brand_cloth[i]) f.close() predict() im = Image.open(os.path.join(o_path, brand_cloth[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save( os.path.join(app2.config['OUTPUT_FOLDER3'], brand_cloth[i])) # # # return render_template('brands.html', brands=brand_cloth, text=text, size=size) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('brands.html')
def upload_image2(): cache.init_app(app2) with app2.app_context(): cache.clear() fish = glob.glob('./static/Database/val/person/*') for f in fish: os.remove(f) fish = glob.glob('./static/size/*') for f in fish: os.remove(f) sport_cloth = [ 'ADIDAS-BW', 'ADIDAS_Black', 'FILA_grey', 'FILA-Pink', 'IVY-Black', 'NIKE-grey' ] for i in range(len(sport_cloth)): sport_cloth[i] = (str(sport_cloth[i]) + ".jpg") if request.method == "POST": if 'file' not in request.files: flash('No file part') return redirect(request.url) text = "sportss" file = request.files['file'] height = request.form['height'] unit = request.form.get('unit') Go = "False" if file.filename == '': flash('No image uploaded for size prediction.') return redirect(request.url) if file and allowed_file(file.filename) and height and unit: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename)) i_path = 'static/size/' file_path = os.path.join(i_path, filename) size, file = women_size_predict1(file_path, height, unit) file = Image.fromarray(file, 'RGB') # file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text + '.jpg' os.rename(i_path + filename, i_path + input_img) filename = text + '.jpg' o_path = './output/second/TOM/val' # fish = glob.glob('./output/second/TOM/val/*') fish = glob.glob('./static/outputs/output_f/*') for f in fish: os.remove(f) time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(sport_cloth)): with open(valpair_file, "w") as f: f.write(text + '.jpg ' + sport_cloth[i]) f.close() predict() im = Image.open(os.path.join(o_path, sport_cloth[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save( os.path.join(app2.config['OUTPUT_FOLDER3'], sport_cloth[i])) # # # return render_template('sports.html', sports=sport_cloth, text=text, size=size) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('sports.html')
def upload_image(): cache.init_app(app2) with app2.app_context(): cache.clear() fish = glob.glob('./static/Database/val/person/*') for f in fish: os.remove(f) fish = glob.glob('./static/size/*') for f in fish: os.remove(f) cloth = [ 'Casual-Yellow', 'Casual-Pink', 'Casual-Violet', 'Casual-White', 'Dark_ORANGE', 'Flowers-White', 'Grey_North', 'Light-Pink', 'Multicolo-White', 'Sky_Blue', 'TheNORTHface', 'Yellow62' ] for i in range(len(cloth)): cloth[i] = (str(cloth[i]) + ".jpg") if request.method == "POST": if 'file' not in request.files: flash('No file part') return redirect(request.url) text = "casualss" file = request.files['file'] height = request.form['height'] unit = request.form.get('unit') if file.filename == '': flash('No image selected for uploading') return redirect(request.url) if file and allowed_file(file.filename) and text and height and unit: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename)) i_path = 'static/size/' file_path = os.path.join(i_path, filename) size, file = women_size_predict1(file_path, height, unit) file = Image.fromarray(file, 'RGB') # file.save(os.path.join(app.config['UPLOAD_FOLDER1'], filename)) i_path = 'static/Database/val/person/' input_img = text + '.jpg' os.rename(i_path + filename, i_path + input_img) filename = text + '.jpg' o_path = './output/second/TOM/val' # fish = glob.glob('./output/second/TOM/val/*') fish = glob.glob('./static/outputs/output_f/*') for f in fish: os.remove(f) time.sleep(10) # # # # pose_parse(text) valpair_file = 'static/Database/val_pairs.txt' for i in range(len(cloth)): with open(valpair_file, "w") as f: f.write(text + '.jpg ' + cloth[i]) f.close() predict() im = Image.open(os.path.join(o_path, cloth[i])) width, height = im.size left = width / 3 top = 2 * height / 3 right = 2 * width / 3 bottom = height im = im.crop((left, top, right, bottom)) newsize = (200, 270) im = im.resize(newsize) im.save( os.path.join(app2.config['OUTPUT_FOLDER3'], cloth[i])) # # # return render_template('casuals.html', casuals=cloth, text=text, size=size) else: flash('Allowed image types are -> png, jpg, jpeg, gif') return redirect(request.url) return render_template('casuals.html')