Python Forum
Deploying to ML Model to web application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deploying to ML Model to web application
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__)

def home():
    return render_template('index.html')

def get_delay():

    query_title = result['title']
    query_author = result['author']
    query_text = result['maintext']
    query = get_all_query(query_title, query_author, query_text)
    user_input = {'query':query}
    pred = pipeline.predict(query)
    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__':, debug=True)
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 = ''
    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_sentence

Traceback (most recent call last):
File "", line 2, in <module>
from sklearn.externals import joblib
ImportError: cannot import name 'joblib' from 'sklearn.externals'
Joblib was excluded from scikit-learn since ver. 0.23. Import joblib directly, e.g. import joblib.
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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Deploying Python-based excel plugin pyexcelnewbie 2 1,847 Mar-22-2018, 08:56 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020