分类多个文档,并将它们在不同的文件夹中存储经由瓶(蟒蛇)

问题描述 投票:0回答:1

我想要做的就是我希望我的web应用程序把多个文件作为输入,并使用我的模型进行归类和归类文档存储到不同的文件夹。

我已经开发了分类文档的模型。模型准备就绪,并具有约0.96的F值的精度。我要实现它的烧瓶中。我已经在文本输入,显示准确的结果执行。

((#LIBRARIES
app = Flask(__name__)

app.config.from_object(__name__) # load config from th

app.config['UPLOAD_FOLDER'] = 'CV_upload/'
app.config['ALLOWED_EXTENSIONS'] = set(['txt', 'pdf', 'png', 'jpg', 
    'jpeg', 'gif'])

# Route for handling the login page logic
@app.route('/login', methods=['GET', 'POST'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != 'admin' or 
    request.form['password'] != 'admin':
            error = 'Invalid Credentials. Please try again.'
        else:
            return redirect(url_for('home'))
    return render_template('index.html', error=error)

@app.route('/logout')
def logout():
    session.pop('logged_in', None)
    flash('You were logged out')
    return redirect(url_for('home'))


@app.route('/home')
def home():
    return render_template('home.html')

@app.route('/predict',methods=['POST'])
def predict():
    <<<<<<<<<<<<<<#MY_NAIVE_BAYES MODEL 
   HERE>>>>>>>>>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<<THis is where i take input text but i want this to 
   change as input multiple pdf files and then classify them>>>>>>>>
                if request.method == 'POST':
            message = request.form['message']
            data = [message]
            vect = vectorizer.transform(data).toarray()
            my_prediction = model.predict(vect)
            return render_template('result.html',prediction = my_prediction)



if __name__ == '__main__':
    app.run(debug=True , threaded=True) 
))

我想要做的就是我希望我的web应用程序把多个文件作为输入,并使用我的模型进行归类和归类文档存储到不同的文件夹。当放置一个查询就会产生结果。

python flask document text-classification
1个回答
0
投票

使用FileUploads最小解

import os

from flask import Flask, request
from werkzeug.utils import secure_filename

app = Flask(__name__)

def classify(bindata):
    #this is a pdf file, extract text and run your model
    return "abc"

def ensure_dirs(path):
    if not os.path.exists(path):
        os.makedirs(path)

@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        for fileobj in request.files.getlist('file'):
            print "Found {}".format(fileobj.filename)
            binary_data = fileobj.stream.read()
            file_class = classify(binary_data)
            path = "uploads/{}".format(file_class)
            ensure_dirs(path)
            fd = open(os.path.join(path, fileobj.filename), "wb")
            fd.write(binary_data)
            fd.close()
            fileobj.close()
    return '''
    <!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
    <form method=post enctype=multipart/form-data>
      <input type=file name=file multiple>
      <input type=submit value=Upload>
    </form>
    '''

if __name__ == '__main__':
    app.run()
© www.soinside.com 2019 - 2024. All rights reserved.