-1

I created a Flask app to upload an image to predict its label. This is the code of the relevant part of app.py:

@app.route("/", methods=['GET', 'POST'])
def main():
    return render_template("index.html")

@app.route("/submit", methods = ['GET', 'POST'])
def get_output():
    if request.method == 'POST':
        img = request.files['my_image']

        licenseplate = "static/" + img.filename 
        img.save(licenseplate)

        p = predictLicensePlate(licenseplate)

This is the index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Number Plate Recognition</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h1 class="jumbotron bg-primary">Number Plate Recognition</h1>
  <br><br>
  <form class="form-horizontal" action="/submit" method="post" enctype="multipart/form-data">

    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Upload Your Image :</label>
      <div class="col-sm-10">          
        <input type="file" class="form-control" placeholder="Hours Studied"  name="my_image" id="pwd">
      </div>
    </div>

    <div class="form-group">        
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-success">Submit</button>
      </div>
    </div>
  </form>

    {% if prediction %}
  <img src="{{img_path}}" height="200px" width="300px">
    <h2> Your Prediction   : <i> {{prediction}} </i></h2>

    {% endif %}

</div>







</body>
</html>

But when I upload an image I only get a placeholder image there as you see below. Can you figure out what is wrong with my code? The format of my image is png and the prediction works fine.

pic

Tobitor
  • 1,388
  • 1
  • 23
  • 58

1 Answers1

1

You need to set the img_path variable in your template:

 <img src="{{img_path}}" height="200px" width="300px">
Captain Caveman
  • 1,448
  • 1
  • 11
  • 24