コード例 #1
0
def upload_file():
    if request.method == 'POST':
        # Remove existing images in directory
        files_in_dir = os.listdir(app.config['UPLOAD_FOLDER'])
        filtered_files = [
            file for file in files_in_dir
            if file.endswith(".jpg") or file.endswith(".jpeg")
        ]
        for file in filtered_files:
            path = os.path.join(app.config['UPLOAD_FOLDER'], file)
            os.remove(path)

        # Upload new file
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files['file']

        if not file:
            return

        print("GETTING PREDICTION")
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        prediction, density = get_prediction(file)
        return render_template('result.html',
                               Prediction=prediction,
                               File=filename,
                               Density=density)
    return render_template('index.html')
コード例 #2
0
ファイル: app.py プロジェクト: ashishawasthi/infer
def infer():
    # Parse Request
    req_data = request.get_json()
    logger.debug(f'req_data: {req_data}')
    model_id = request.args.get('model_id')
    if model_id is None:
        model_id = default_model_id
    model_inputs_param = request.args.get('model_inputs')
    if model_inputs_param is None:
        logger.error(f'No model_inputs found, returning 400')
        return f'No model_inputs found. {usage_guide}', 400
    try:
        model_inputs = json.loads(model_inputs_param)
    except json.decoder.JSONDecodeError as e:
        logger.error(
            f'Non JSON model_inputs: {model_inputs_param}, returning 400. \n{str(e)}'
        )
        return f'Non JSON model_inputs: {model_inputs_param}. {usage_guide}', 400
    logger.debug(f'model_inputs: {model_inputs}')

    # Predict
    try:
        prediction = get_prediction(model_id, model_inputs)
    except PredictionError as e:
        logger.error(
            f'model_inputs: {model_inputs_param}, returning 400. \n{str(e)}')
        return str(e), 400
    return Response(json.dumps(prediction.tolist()),
                    mimetype='application/json')
コード例 #3
0
ファイル: app.py プロジェクト: DKN2007/Sopredict
def predict_url():
    url_link = request.args['url_link']
    url_image = requests.get(url_link)
    image_bytes = url_image.content
    class_id, class_name = get_prediction(image_bytes=image_bytes)
    class_name = format_class_name(class_name)
    return render_template('result.html', class_name=class_name)
コード例 #4
0
def upload_file():
  if request.method == 'POST':
    data = []
    for key in ['source', 'target']:
      if key not in request.files:
        print(f"no {key}")
        return redirect(request.url)
      file_obj = request.files.get(key)
      if not file_obj:
        print("incorrect file_obj")
        return

      print(f"FILE {key}: {file_obj}")
      wav, sr = read_audio(file_obj)
      wav = transform_audio(wav, sr)
      data.append(wav)

    print("Converting...")
    result = get_prediction(data[0], data[1])
    output = audio_to_bytes(result)

    return render_template(
      'result.html',
      snd=output,
      src=audio_to_bytes(data[0].numpy()),
      tgt=audio_to_bytes(data[1].numpy())
    )

  return render_template('index.html')
コード例 #5
0
ファイル: app.py プロジェクト: sayedmohamedscu/heroku_test
def predictResNet50():
    if request.method == 'POST':
        file_path = get_file_path_and_save(request)
        im = Image.open(file_path)
        pred_class, class_name = get_prediction(image_bytes=im)
        result = format_class_name(class_name)

        return result
    return None
コード例 #6
0
def index():
    if request.method == 'POST':
        uploaded_file = request.files['file']
        if uploaded_file.filename != '':
            image_path = os.path.join('static', uploaded_file.filename)
            uploaded_file.save(image_path)
            class_name = inference.get_prediction(image_path)
            print('CLASS NAME', class_name)
    return render_template('index.html')
コード例 #7
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        prediction = get_prediction(image_bytes=img_bytes)
        return render_template('result.html', class_name=prediction)
    return render_template('index.html')
コード例 #8
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        image = b64encode(img_bytes).decode("utf-8")
        predict_post = get_prediction(image_bytes=img_bytes)
        return render_template('result.html', predict_post=predict_post, image=image)
    return render_template('index.html')
コード例 #9
0
def image_classifier():
    print("files", request.files)

    # if 'file' not in request.files:
    # return jsonify( message='file not found' )
    file = request.files['file']
    filename = secure_filename(file.filename)
    print(filename)
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    prediction = get_prediction(UPLOAD_FOLDER + filename)

    return jsonify(ammount=prediction, )
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        file_tensor = transform_image(image_bytes=img_bytes)  #######
        class_name = get_prediction(file_tensor)
        return render_template('result.html', class_name=class_name)
    return render_template('index.html')
コード例 #11
0
def upload_file():
    global model
    if request.method == "POST":
        if "file" not in request.files:
            return redirect(request.url)
        file = request.files.get("file")
        if not file:
            return
        img_bytes = file.read()
        class_id = get_prediction(model, image_bytes=img_bytes)
        return render_template("result.html", class_id=class_id)
    return render_template("index.html")
コード例 #12
0
def upload_file():
    error = ""

    if request.method == 'POST':
        img_urls = [request.form['url']]
    else:
        img_urls = [
            "https://upload.wikimedia.org/wikipedia/en/b/b0/Les-miserables-movie-poster1.jpg"
        ]

    try:
        result = get_prediction(urls=img_urls)
    except:
        img_urls = [
            "https://upload.wikimedia.org/wikipedia/en/b/b0/Les-miserables-movie-poster1.jpg"
        ]
        result = get_prediction(urls=img_urls)
        error = "Invalid URL format"
    return render_template('result.html',
                           img_url=img_urls[0],
                           class_name=result,
                           error=error)
コード例 #13
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        file_tensor = transform_image(image_bytes=img_bytes)  ########
        #file_share_ptr = secret_share(file_tensor,workers,hospital)  # patient generates secret shares of the data and sends one share to the global agent.
        class_name = get_prediction(file_tensor)
        return render_template('result.html', class_name=class_name)
    return render_template('index.html')
コード例 #14
0
def upload_file():
    if request.method == 'GET':
        return render_template('index.html')
    if request.method == 'POST':
        print(request.files)
        if 'file' not in request.files:
            print('File not Uploaded..!')
            return
        file = request.files['file']
        img = file.read()
        pet_class, pet_name = get_prediction(image_bytes=img)
        return render_template('results.html',
                               class_id=pet_class,
                               pet=pet_name)
コード例 #15
0
def index():
    if request.method == "POST":
        uploaded_file = request.files["file"]
        if uploaded_file.filename != "":
            image_path = os.path.join("static", uploaded_file.filename)
            uploaded_file.save(image_path)
            class_name = get_prediction(image_path)
            result = {
                "class_name": class_name,
                "image_path": image_path
            }
            return render_template("show.html", result = result)

    return render_template("index.html")
コード例 #16
0
ファイル: app.py プロジェクト: DKN2007/Sopredict
def predict_image():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        class_id, class_name = get_prediction(image_bytes=img_bytes)
        class_name = format_class_name(class_name)
        return render_template('result.html',
                               class_id=class_id,
                               class_name=class_name)
    return render_template('index.html')
コード例 #17
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()

        mask = get_prediction(image_bytes=img_bytes)
        mask_to_img = generate_png(img_bytes, mask)

        return render_template('result.html', mask=mask, img=mask_to_img)
    return render_template('index.html')
コード例 #18
0
def index():
    if request.method =='POST':
        uploaded_file = request.files['file']
        if uploaded_file.filename.endswith('.jpg') or uploaded_file.filename.endswith('.png') or uploaded_file.filename.endswith('.jpeg'):
            image_path = os.path.join('static', uploaded_file.filename)
            uploaded_file.save(image_path)
            class_name = inference.get_prediction(image_path)

            result = {
            'class_name':class_name,
            'image_path': image_path
            }
            return render_template('show.html', result=result)
    return render_template('index.html') # by default it will look in templates folder
コード例 #19
0
ファイル: app.py プロジェクト: evertongava/SIZE.AI
def upload_file():
    if request.method == 'POST':
        absolute_path = os.path.abspath("../")
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files['file']
        if not file:
            return
        print("GETTING PREDICTION")
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        prediction = get_prediction(file) # Change this to 'file' PATH - ensure format
        return render_template('result.html', Prediction=prediction, File=filename) # Pass in the prediction
    return render_template('index.html')
コード例 #20
0
def index():
    if request.method == 'POST': #image file is uploaded
        uploaded_file = request.files['file']
        if uploaded_file.filename != '':
            image_path = os.path.join('static', uploaded_file.filename)
            uploaded_file.save(image_path)
            class_name = inference.get_prediction(image_path)
            print('Class name = ', class_name)
            result = {
            'class_name' : class_name,
            'image_path' : image_path,
            }
            return render_template('show.html', result = result)

    return render_template('index.html')
コード例 #21
0
ファイル: app.py プロジェクト: vijay-guttula/Tensy
def index():
    if request.method == 'POST':
        uploaded_file = request.files['file']
        if uploaded_file.filename != '':
            image_path = os.path.join('static', uploaded_file.filename)
            uploaded_file.save(image_path)
            class_name, n = inference.get_prediction(image_path)
            #print("Class Name : "+ class_name)
            result = {
                'class_name': class_name,
                'image_path': image_path,
                'n': n,
            }
            return render_template('show.html', result=result)
    return render_template('index.html')  #to the html
コード例 #22
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files.get('file')
        if not file:
            return
        img_bytes = file.read()
        class_name = get_prediction(image_bytes=img_bytes)
        if isinstance(class_name, str) :
            class_name = format_class_name(class_name[0])
        else :
            class_name = 'No hard hat'
        return render_template('result.html', class_name=class_name)
    return render_template('index.html')
コード例 #23
0
def upload_file():
    if request.method == 'POST':
        # if not request.files.get('content', None) or not request.files.get('style', None):
        #     return redirect(request.url)

        content = request.files.get('content')
        style = request.files.get('style')

        full_filename = os.path.join(app.config['UPLOAD_FOLDER'], "target.png")

        target = get_prediction(content, style)
        target.save(full_filename)
        while not os.path.isfile(full_filename):
            time.sleep(1)
        return render_template("result.html", image=full_filename)
    return render_template('index.html')
コード例 #24
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        # templateから送られてきたFileStorageオブジェクト
        file = request.files.get('file')
        if not file:
            return
        # クライアントから送られた画像ファイルを読み込める
        image_bytes = file.read()
        class_id, class_name = get_prediction(image_bytes)
        class_name = format_class_name(class_name)
        return render_template('result.html',
                               class_id=class_id,
                               class_name=class_name)

    return render_template('index.html')
コード例 #25
0
def upload_file():
    if request.method == 'POST':
        text = request.form.get('textbox')
        print('text is :', text)
        # if 'file' not in request.files:
        # return redirect(request.url)
        # file = request.files.get('file')
        # if not file:
        #     return
        #img_bytes = file.read()
        img_bytes = text
        #        class_id, class_name = get_prediction(image_bytes=img_bytes)
        reply = get_prediction(image_bytes=img_bytes)
        class_name = format_class_name(reply)
        return render_template('result.html', class_name=class_name)
        #  class_name=class_name)
    return render_template('index.html')
コード例 #26
0
ファイル: app.py プロジェクト: ConyYang/Flask_tf_ImgClassify
def index():
    if request.method == 'POST':
        upload_file = request.files['file']
        if upload_file.filename != '':
            image_path = os.path.join('static', upload_file.filename)
            upload_file.save(image_path)

            predict_result = inference.get_prediction(image_path)
            predict_score = predict_result[0]
            class_name = predict_result[1]
            result = {
                'predict_score': predict_score,
                'class_name': class_name,
                'image_path': image_path,
            }
            return render_template('show.html', result=result)

    return render_template('index.html')
コード例 #27
0
def index():
    # For a POST request, execute this code to infer a result.
    if request.method == 'POST':
        # Get the file uploaded in the form.
        uploaded_file = request.files['file']
        # If there is an uploaded file execute this code.
        if uploaded_file.filename != '':
            # Define a path for saving this image in the "static" folder.
            image_path = os.path.join('static', uploaded_file.filename)
            # Save the uploaded image to display it later.
            uploaded_file.save(image_path)
            # Get a class name by making a prediction on the image.
            class_name = inference.get_prediction(image_path)
            # Print the class name in the terminal.
            print('CLASS NAME = ', class_name)
            # Define an object/dictionary to store the class name and path to the saved image.
            result = {'class_name': class_name, 'image_path': image_path}
            # Pass the result to show.html and render the page.
            return render_template('show.html', result=result)
    # For a GET request, render index.html
    return render_template('index.html')
コード例 #28
0
def index():
    # when the image has been uploaded
    if request.method == 'POST':
        uploaded_file = request.files['file']
        if uploaded_file.filename != '':  # check if the click was valid
            ''' ADD A filetype validation here '''

            # Saving a copy of the uploaded image to static to display along with the picture
            image_path = os.path.join(
                'static', uploaded_file.filename
            )  # A unique filaneme creattion method can be used here
            uploaded_file.save(image_path)

            # Get the predicted class name from the inference module function
            class_name = inference.get_prediction(image_path)
            print('The identified animal is a: {}'.format(
                class_name))  # Display the result

            # Result to be displayed
            result = {'class_name': class_name, 'image_path': image_path}
            return render_template('show.html', result=result)
    return render_template('index.html')
コード例 #29
0
def upload_file():
    if request.method == 'POST':
        if 'files[]' not in request.files:
            return redirect(request.url)
        files = request.files.getlist('files[]')
        for file in files:
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
        if not files:
            return
            
        filenames=[]
        for file in glob.glob(UPLOAD_FOLDER+'/*'):
            filenames.append(file)
        results=[]
        for file in glob.glob(UPLOAD_FOLDER+'/*'):
            class_name = get_prediction(file)
            results.append(class_name)
        #print(filenames)
        #print(results)
        for file in glob.glob(UPLOAD_FOLDER+'/*'):
            os.remove(file)
        return render_template('result.html', results=results,files=filenames)
    return render_template('index.html')
コード例 #30
0
def submit_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request_url)
        file = request.files['file']
        if file.filename == '':
            flash('No file selected for uploading')
            return redirect(request.url)
        if file:
            print(file.filename)
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
            new_file = os.path.join(r'C:\Users\NDH60042\MAJOR PROJECT\Flask project',filename)
            result, accuracy = get_prediction(new_file)
            if len(result.split())==2:
                search = "https://www.google.com/search?q=DIY+Reusing+Ideas+for"+result.split()[0]+result.split()[1]
            else:
                search = "https://www.google.com/search?q=DIY+Reusing+Ideas+for"+result
            flash(result)
            flash(accuracy)
            flash(filename)
            webbrowser.open(search)
            return redirect('/')