def check(event=None): show_info("") # try: raw_text = displayed_file.get('1.0', tk.END) global candidate candidate = Prediction(raw_text, jl, jl_multiClass) global propDict propDict = candidate.predict_technique() if len(propDict) > 0: displayed_file.delete('1.0', END) global percent_of_propaganda percent_of_propaganda = candidate.percent_of_propaganda() # displayed_file.insert(tk.END, ) displayed_file.insert(tk.END, raw_text) displayed_file.tags() statistics_button.grid(row=3, column=4, padx=10, pady=10) print(propDict) for key in propDict: for value in propDict[key]: displayed_file.highlight_pattern(value, key) tag = key displayed_file.tag_configure(tag) displayed_file.tag_bind(tag, "<Enter>", lambda event, key=key: show_info(key)) displayed_file.tag_bind(tag, "<Leave>", lambda event, key=key: show_info("")) else: show_info("No propaganda detected") return propDict
def join_connection(): req_data = request.get_json() conn_id = req_data['_id'] fileName = req_data['fileName'] userId = req_data['userId'] p = Prediction() # fo = open(app.config['UPLOAD_FOLDER'] + "/" + "ad.enc",'rb').read() # # Decrypts the data, requires a user-input password # CSVplaintext = decrypt('USERPASSWORD', fo).decode('utf8') # #create a temp csv-like file to pass to pandas.read_csv() # DATA=StringIO(CSVplaintext) # # Makes a panda dataframe with the data # df = pd.read_excel(DATA) # print df.head() value = int(p.run(app.config['UPLOAD_FOLDER'] + "/Data/" + fileName)) #conn_id = '5bf8ab7c101c372f28c65c2b' users = mongo.db.users connections = mongo.db.connections parser = connections.find({'_id': ObjectId(conn_id)}) for doc in parser: connDoc = doc currCount = connDoc['currRemainingCount'] if currCount > 0: playerNum = connDoc['userCount'] - (currCount - 1) print os.system('pwd') command = 'python ./../viff-1.0/apps/sum.py --no-ssl player-' + str( playerNum) + '.ini ' + str(value) print command print connections.update({'_id': ObjectId(conn_id)}, {'$inc': { 'currRemainingCount': -1 }}) #os.system(command) proc = Popen(command, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) print "Status = " + str(proc) status = 0 if status == 0: #print output value *= 100 users.insert({ 'userId': str(userId), 'yourVal': value, 'AvgValue': 0 }) retVal = {} retVal['sum'] = 'Will be updated soon!' return jsonify(retVal), 200 else: 'Joining Failed', 404 else: return 'Connection Full', 404
def predict_image(model_path: str, image: np.ndarray, show: bool = False): pred = Prediction(model_path=model_path, output_path=None, patch_size=train_params['patch_size'], batch_size=train_params['batch_size'], offset=2 * train_params["n_layers"], n_classes=len(classes_mask.keys()), n_filters=train_params["n_filters"], n_layers=train_params["n_layers"]) # image = np.array(Image.open(image)).astype(np.float32) / 255 predicted = pred.__predict_image__(image) predicted = np.argmax(predicted, axis=2) if show: Image.fromarray( colorize_mask(np.dstack((predicted, predicted, predicted)), n_classes=pred.n_classes)).show() return predicted
def __init__(self): #TODO move to outside self.model_name = CHATBOT_MODEL self.embedding_file = 'embedding_wiki_100d_pt.txt' self.ds = Dataset() self.messages = self.ds.import_dataset() self.questions = self.ds.get_questions( self.messages) #['why?', 'how?', 'when?, ...'] self.answers = self.ds.get_answers( self.messages) #['yes', 'no', 'maybe', ...] self.model = load_model(CHATDATA_DIR + self.model_name) self.pc_questions = self.ds.get_page_compute(qea=1) self.pc_answers = self.ds.get_page_compute(qea=0) self.tokenizer = self.ds.load_tokenizer() self.p = Prediction(model=self.model, messages=self.messages, questions=self.questions, answers=self.answers, pc_questions=self.pc_questions, pc_answers=self.pc_answers, tokenizer=self.tokenizer)
def __init__( self ): """Constructor.""" super( QMainWindow, self ).__init__( ) self.setGeometry(10, 50, 300, 150) self.setWindowTitle("Informative or NonInformative Tweets") self.filename = "" self.prediction = Prediction( "../models/text.h5", "../models/old_image/damage.h5" ) self.widget = QWidget ( ) self.widget.setObjectName("widget") self.widget.setStyleSheet("QWidget#widget{border-image:url('../images/background.jpg');}\n") self.layout = QGridLayout( self.widget ) self.image_label = QLabel( ) self.result_label = QLabel( ) self.image_label .setScaledContents( True ) self.result_label.setScaledContents( True ) self.browse = QPushButton( "Browse" ) self.text_field = QLineEdit ( ) self.submit = QPushButton( "Submit" ) self.layout.addWidget( self.image_label ) self.layout.addWidget( self.browse ) self.layout.addWidget( self.text_field ) self.layout.addWidget( self.submit ) self.layout.addWidget( self.result_label ) self.browse.clicked.connect( self.pick_file ) self.submit.clicked.connect( self.predict ) self.setCentralWidget( self.widget )
import MySQLdb.cursors import re import os import cv2 import image_processing.filters as filters import image_processing.preprocessing as preprocessing import image_processing.to_domain as to_domain import time os.environ["CUDA_VISIBLE_DEVICES"] = "-1" from predict import Prediction predictor = Prediction("model_weights.h5") app = Flask(__name__) app.secret_key = 'thisissecret' app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = '******' app.config['MYSQL_PASSWORD'] = '' app.config['MYSQL_DB'] = 'retinadb' mysql = MySQL(app) predicted = {} processed_images = {} @app.route("/index")
mode = sys.argv[1] if mode == "train" or mode == "onlyexport": data_file = sys.argv[2] parameter_file = sys.argv[3] examples_file = sys.argv[4] with codecs.open(parameter_file, 'r', 'utf-8') as f: params = json.load(f) with codecs.open(examples_file, 'r', 'utf-8') as f: examples = json.load(f) t = Training(data_file=data_file, examples=examples) for p in params: print("Trying:{}".format(p)) p["only_export"] = (mode == "onlyexport") t.train(**p) if mode == "predict": vocab_file = sys.argv[2] model_file = sys.argv[3] text = sys.argv[4] p = Prediction(model_file, vocab_file) print(p.predict(text)) if mode == "predict_server": data_file = sys.argv[2] model_file = sys.argv[3] p = Prediction(model_file, data_file) db = get_database_from_file(data_file) PredictServer(p, db)
from numpy import array import numpy as np import tensorflow as tf from tensorflow.keras.preprocessing.text import tokenizer_from_json from predict import Prediction import json # Load saved tokenizer with open('tokenizer_30000.json') as f: data = json.load(f) tokenizer = tokenizer_from_json(data) max_length = 179 pred = Prediction(tokenizer, max_length) pred.load_model() #we were laughing , haha thats funny but then we were saying damn it all , what kind of example is this guy setting for the kids ? #this is just great , seth shouted . #he might be into it . #just try to be less annoying than usual #this may say something important # Predict for given sequence print(pred.predict_sequnce("just try to be less annoying than usual", 100))