'I can't use 'predict' method when assigning my trained svc model to the user input in flask
I can't use 'predict' method when assigning my trained svc model to the user input in flask. it gives me this error, "AttributeError: 'str' object has no attribute 'predict'" I used python to develop my model and used visual studio code.
This is my app.py code.
app = Flask(__name__)
model = pickle.load(open('hsd.pkl', 'rb'))
@app.route("/")
def hello():
return render_template("home.html")
@app.route("/submit", methods =['POSt'])
def submit():
if request.method == "POST":
text1 = request.form['tweet']
probb = [np.array(text1)]
y = model.predict(probb)
return render_template("submit.html", n = y)
if __name__ == "__main__":
app.run(debug=True)
This is my html code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hate speech Detection</title>
</head>
<body>
<h1>Hate speech Detection</h1>
<h3>Enter your tweet</h3>
<form action="/submit" method="POST">
<input type="text" name='tweet' placeholder="input your tweet">
<input type="submit" value="predict">
</form>
</body>
</html>
This is my submit html code.
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<center>
<h1> PREDICTION : </h1>
{%if n == 0%}
<h1>No hp</h1>
{%else%}
<h1>hp</h1>
{%endif%}
<br><br>
<a href='/'>go back to home page</a>
</center>
</body>
</html>`
Traceback
Traceback (most recent call last):
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\USER\anaconda3\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\deploy\app.py", line 53, in submit
y = model.predict(text1)
AttributeError: 'str' object has no attribute 'predict'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
