first I defined two functions in my app.py file as follows:
senti=["furious","angry","angry0","Indiferent","happy","enthusiastic","Euphoric"]
def predict(text):
seqs = tok.texts_to_sequences([text])
print(text)
word_index = tok.word_index
print('Found %s unique tokens.' % len(word_index))
sequence_pred = sequence.pad_sequences(seqs, maxlen=MAX_SEQUENCE_LENGTH)
print(sequence_pred)
prediction = model.predict(sequence_pred)
print(prediction)
return senti[np.argmax(prediction[0])]
Here I get the values of image_url that is the path of my image as follows:
@app.route("/", methods=['GET', 'POST'])
def index():
senti=["furious","angry","angry0","Indiferent","happy","enthusiastic","Euphoric"]
images=['static/angry.jpg','static/angry.jpg','static/angry.jpg','static/smile.jpg','static/smile.jpg','static/smile.jpg','static/smile.jpg']
lookup_keys = dict(zip(senti, images))
print(request.method)
if request.method == 'POST':
q=request.form['querytext']
prediction=predict(q)
image_path = lookup_keys[prediction] # get the path
print(image_path)
return render_template("result.html",
prediction=prediction,
text=q,
image_url=image_path)
return render_template("main.html")
then depending of the result I would like to display and image I am just using two smile.jpg and angry.jpg that are contained in the static folder, after that I render my template called: "result.html"
this file contains the following tags to show me the text and prediction as follows:
<h3>{{text}} </br> <button class="button-primary">{{prediction}}</button></h3>
Everything works well until this point I want to show the image dynamically I tried:
<h3>{{image_url}}<td><img src={image_url} alt=""></td></h3>
However is not displaying nothing, If I put the following tag:
<td><img src='static/angry.jpg' alt=""></td>
the image is being displayed with any problems I would like to appreciate support to modify the tag of above to display the image dinamically I mean this part:
<td><img src='static/angry.jpg' alt=""></td>
I would like to change dinamically this string 'static/angry.jpg' with the value of my variable called image_url, I am a begginer using flask so I am not sure how to use this value, thanks for the support.