Deploying to ML Model to web application - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Deploying to ML Model to web application (/thread-29090.html) |
Deploying to ML Model to web application - Scoder - Aug-18-2020 Hello am working on a personal project to practice what I ahve learnt. The title of the project is 'Fake news detection using machine learning'. I'm having a problem in deploying to web app using flask. Please I will be glad to receive help here. The error am having is that: ImportError: cannot import name 'joblib' from 'sklearn.externals' Relevant code files are attached. the flask code from flask import Flask, abort, jsonify, request, render_template from sklearn.externals import joblib from feature import * import json pipeline = joblib.load('pipeline.sav') app = Flask(__name__) @app.route('/') def home(): return render_template('index.html') @app.route('/api',methods=['POST']) def get_delay(): result=request.form query_title = result['title'] query_author = result['author'] query_text = result['maintext'] print(query_text) query = get_all_query(query_title, query_author, query_text) user_input = {'query':query} pred = pipeline.predict(query) print(pred) dic = {1:'real',0:'fake'} return f'<html><body><h1>{dic[pred[0]]}</h1> <form action="/"> <button type="submit">back </button> </form></body></html>' if __name__ == '__main__': app.run(port=8080, debug=True).......................... feature.py import numpy as np # linear algebra import pandas as pd #data processing import os import re import nltk def get_all_query(title, author, text): total= title + author + text total = [total] return total def remove_punctuation_stopwords_lemma(sentence): filter_sentence = '' lemmatizer=WordNetLemmatizer() sentence = re.sub(r'[^\w\s]','',s) words = nltk.word_tokenize(sentence) #tokenization words = [w for w in words if not w in stop_words] for word in words: filter_sentence = filter_sentence + ' ' + str(lemmatizer.lemmatize(word)).lower() return filter_sentenceStackTrace Traceback (most recent call last): File "app.py", line 2, in <module> from sklearn.externals import joblib ImportError: cannot import name 'joblib' from 'sklearn.externals' RE: Deploying to ML Model to web application - scidam - Aug-20-2020 Joblib was excluded from scikit-learn since ver. 0.23. Import joblib directly, e.g. import joblib .
RE: Deploying to ML Model to web application - hussainmujtaba - Aug-31-2020 Why don't you use streamlit to make webapps for ML.It is much easier and less complicated.Here is how made a webapp for sentiment analysis(although didn't deploy it).Check out this article too, I guess it will be cool if you make a web app for it. |