Exemplo n.º 1
0
def smodel_out():
    visitor_info = request.environ
    visitor_ip = visitor_info.get('REMOTE_ADDR')
    visitor_device = (visitor_info.get('HTTP_USER_AGENT').split(')')[0]
                      ).split(';')[-1].strip()
    visitor_username = "******" + ".".join(
        visitor_ip.split('.')[0:3]) + visitor_device
    try:
        avail_tokens = counttokens(visitor_username)
        if avail_tokens > 0:
            col.update({"Username": visitor_username}, {
                "$set": {
                    "tokens": avail_tokens - 1,
                    "date": datetime.datetime.today()
                }
            })
            posted_data = request.form.get('sample_text')
            result_dict = get_spacy_ner(posted_data, nlp_spacy)
            return render_template("spacy/spacy_output.html",
                                   result=result_dict)
        else:
            flash("Sorry trials exceeded")
            return redirect(url_for('token_end_flash'))
            # return render_template("spacy/spacy_trials.html")
    except Exception as e:
        logging.exception("** AT END POINT /getDetails **")
        log_exception(e)
        ret_json = {'status': 500, 'message': 'internal server error'}
        return jsonify(ret_json)
Exemplo n.º 2
0
def tmodel_out():
    count = 1
    top = {}
    # result_dict = {}
    visitor_info = request.environ
    visitor_ip = visitor_info.get('REMOTE_ADDR')
    visitor_device = (visitor_info.get('HTTP_USER_AGENT').split(')')[0]
                      ).split(';')[-1].strip()
    visitor_username = "******" + ".".join(
        visitor_ip.split('.')[0:3]) + visitor_device
    try:
        avail_tokens = counttokens(visitor_username)
        if avail_tokens > 0:
            col.update({"Username": visitor_username},
                       {"$set": {
                           "tokens": avail_tokens - 1
                       }})
            posted_data = request.form.get('sample_text')
            avg_posted_data = len(clean_text(posted_data).split())
            # print('avg_posted_data:', avg_posted_data)
            try:
                no_of_topics = int(request.form.get('no_of_topics'))
            except Exception as e:
                logging.exception("** AT END POINT /getDetails **")
                log_exception(e)
                no_of_topics = 1
            top = get_topic_modelling(posted_data,
                                      no_of_topics,
                                      avg_posted_data,
                                      count=1)
            return render_template("topic_modelling/topic_output.html",
                                   result=top,
                                   message=None)
        else:
            flash("Sorry trials exceeded")
            return redirect(url_for('token_end_flash'))
    except Exception as e:
        logging.exception("** AT END POINT /getDetails **")
        log_exception(e)
        ret_json = {'status': 500, 'message': 'internal server error'}
        return jsonify(ret_json)