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
#1
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_sentence
StackTrace

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'
Reply
#2
Joblib was excluded from scikit-learn since ver. 0.23. Import joblib directly, e.g. import joblib.
Reply
#3
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.
Reply


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

Forum Jump:

User Panel Messages

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