I just finished this short tutorial on YouTube on the Clarifai API and Flask, but my web application is not working when I try entering my search results in either input places on http://localhost:5000/ since nothing is displaying after entering either my search term or image url. That is, the index.html is displaying, but , for example, when I try inputting 'animal' into the first input and press the 'search' button nothing is happening.
Below is the traceback, the code itself, and my directory structure. Any help would be very much appreciated.
Traceback
/usr/local/bin/python3.8 /Users/lyons/Desktop/testing.py
* Serving Flask app "testing" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [25/Sep/2020 11:45:03] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [25/Sep/2020 11:45:10] "POST / HTTP/1.1" 200 -
testing.py
from clarifai.rest import ClarifaiApp
from flask import Flask, request, render_template
clarifaiKEY = 'REDACTEDFORPRIVACY'
myAI = ClarifaiApp(api_key=clarifaiKEY)
app = Flask(__name__)
@app.route('/')
def index():
return render_template('/index.html', len=0)
@app.route('/', methods=['POST'])
def search():
if request.form['searchByConcept']:
searchTerm = request.form['searchByConcept']
searchResults = myAI.inputs.search_by_predicted_concepts(concept=searchTerm)
return render_template('/index.html', len=len(searchResults), searchResults=searchResults)
elif request.form['searchByImage']:
refImage = request.form['searchByImage']
searchResults = myAI.inputs.search_by_image(url=refImage)
return render_template('/index.html', len=len(searchResults), searchResults=searchResults)
if __name__ == '__main__':
app.run(host='0.0.0.0')
index.html
<h1>Can I help you find something?</h1>
<form action="." method="post">
<h2>Search By Concept</h2>
<input type="text" name="searchByConcept">
<input type="submit" name="searchByConcept" value="Search">
<h2>Search By Image</h2>
<input type="text" name="searchByImage" >
<input type="submit" name="searchByImage" value="Search">
</form>
{%for i in range(0,len)%}
<li><img src="{{searchResults[i].url}}" alt=""></li>
{%endfor%}
My directory structure is the following
/testing.py
/templates
/index.html