Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将二进制文件(Dicom文件)上载到flask服务器,同时使用javascript接收JSON响应_Javascript_Python_Json_Flask_Binary - Fatal编程技术网

将二进制文件(Dicom文件)上载到flask服务器,同时使用javascript接收JSON响应

将二进制文件(Dicom文件)上载到flask服务器,同时使用javascript接收JSON响应,javascript,python,json,flask,binary,Javascript,Python,Json,Flask,Binary,我正在尝试将一个dicom文件上传到一个运行深度学习模型的flask服务器上,并以JSON格式从服务器上获取预测值 所以问题出在下面的javascript代码中。有没有一种方法可以同时发送和获取值?请帮忙 HTML: 我在烧瓶演示中做了类似的事情。你可以看看,试试看 HTML 欢迎来到ImageClassifier演示 预测 结果: js $(文档).ready(函数(){ $(“#预测”).bind('click',function(){ $.getJSON(“/predict”{ a:$

我正在尝试将一个dicom文件上传到一个运行深度学习模型的flask服务器上,并以JSON格式从服务器上获取预测值

所以问题出在下面的javascript代码中。有没有一种方法可以同时发送和获取值?请帮忙

HTML:


我在烧瓶演示中做了类似的事情。你可以看看,试试看

HTML

欢迎来到ImageClassifier演示
预测
结果:
js


$(文档).ready(函数(){
$(“#预测”).bind('click',function(){
$.getJSON(“/predict”{
a:$('input[name=“url”]”)。val()
},函数(数据){
console.log(“收到结果”)
$(“#结果”).text(“结果:+data.result”);
});
返回false;
});
});

我尝试了很多次,但都没有改变,Flask terminal不断返回错误代码302。
<body>
<input id="image-selector" type="file">    
<button id="predict-button">Predict</button>

<p><h1>PREDICTIONS</h1></p>
<span id="predicted-value_1">
<span id="predicted-value_2">
<span id="predicted-value_3">
</body>
$("#predict-button").click(function(){

    var form_data = new FormData();
    var ins = document.getElementById('image-selector').files.length;

    if(ins == 0) {
        $('#msg').html('<span style="color:red">Select one file</span>');
            return;
    }
    else{
        form_data = document.getElementById('image-selector').files[0]
    }

    let message = {
        "file": form_data
    }
    console.log(message);
    

    $.post("http://127.0.0.1:5000/predict", JSON.stringify(message), function(response){
    $("#predicted-value_1").text(response.prediction.value1);
    $("#predicted-value_1").text(response.prediction.value2);
    $("#predicted-value_1").text(response.prediction.value3);
    console.log(response);
    });
});
@app.route("/predict", methods=['GET', 'POST'])
def predict():

if request.method == 'POST':
    # check if the post request has the file part
    if 'file' not in request.files:
        flash('No file part')
        return redirect(request.url)
    
    file = request.files['file']
    # if user does not select file, browser also
    # submit an empty part without filename
    if file.filename == '':
        flash('No selected file')
        return redirect(request.url)
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
   #Rest of the code! I can take it from here!!
    <h4>Welcome to ImageClassifier Demo</h4>
    <input type=text size=5 name=url>
    <button id="prediction" type="submit">
        <span>Predict</span>
    </button>
    <span id=result>
        Result:
    </span>
    <script type="text/javascript">
        $(document).ready(function(){
            $('#prediction').bind('click', function() {
                $.getJSON('/predict', {
                    a: $('input[name="url"]').val()
                    }, function(data) {
                        console.log("Result Received")
                        $("#result").text("Result: " + data.result);
                        });
                return false;
            });
        });
    </script>