Exemple #1
0
def main():
    pred = predict.predictor()

    for name in NAMES:
        for tp in TYPES:
            # shutil.copyfile(name + '_' + tp + '.json', name + '_' + tp + '_BACKUP.json')
            with open(BASE_DIR + name + '_' + tp + '.json', 'r',
                      newline='') as f:
                f_data = json.load(f)

                # create a list of the sentiments of each tweet (in order)
                sentiment_list = pred.infer(
                    tweets=list(map(lambda x: x['text'], f_data['statuses'])))

                # normalizes the sentiment so that -1 is the most negative and 1 is the most positive
                sentiment_list = list(
                    map(lambda x: (2.0 * x[1]) - 1, sentiment_list))

                # add a sentiment field to each tweet and set it to be the normalized value of the sentiment
                for (status, sentiment) in zip(f_data['statuses'],
                                               sentiment_list):
                    status['sentiment'] = sentiment

            with open(BASE_DIR + name + '_' + tp + '.json', 'w') as f:
                json.dump(f_data, f)
                print('Dumped %d lines of data to file' %
                      len(f_data['statuses']))
Exemple #2
0
def handle_message(event):
    text = u'นี้คือ {}'.format(event.message.type)
    output = None
    if event.message.type == "text":
        text = u'แมวววว'
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=text))

    elif event.message.type == "image":
        message_content = line_bot_api.get_message_content(event.message.id)
        file_name = event.message.id + "_image.jpg"
        with open(file_name, 'wb') as fd:
            for chunk in message_content.iter_content():
                fd.write(chunk)

        fd.close()

        output = predict.predictor(file_name)
        #text = u'สไตล์แวนโกะเลย เมี้ยววววว {}'.format(os.path.join(request.url_root, output))
        url_img = os.path.join(request.url_root, output)
        if url_img[:5] != 'https':
            url_img = 'https' + url_img[4:]

        line_bot_api.reply_message(
            event.reply_token,
            ImageSendMessage(type="image",
                             original_content_url=url_img,
                             preview_image_url=url_img))

    else:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=text))
def main():
    if not os.path.isdir(flag.output_dir):
        os.mkdir(flag.output_dir)
    if flag.mode == 'train':
        train_op = train.Trainer(flag)
        train_op.train()
    elif flag.mode == 'predict':
        predict_op = predict.predictor(flag)
        predict_op.inference()
    elif flag.mode == 'eval':
        eval_op = predict.predictor(flag)
        eval_op.evaluate()
    elif flag.mode == 'cam':
        cam_op = predict.predictor(flag)
        cam_op.cam()
    else:
        print 'not supported'
Exemple #4
0
def home_repost():
    if request.method == 'POST':
        final_symptoms = request.form.getlist('disease_checkbox')
        diseases = predictor(final_symptoms)

        if request.form.get('accept'):
            db.child('Accepted Diseases').child(input_text).update(
                {"Symptoms": final_symptoms})
            db.child('Accepted Diseases').child(input_text).update(
                {"Disease": diseases})

    return render_template('disease.html',
                           text=input_text,
                           final_symptoms=final_symptoms,
                           diseases=diseases)
 def predict(self):
     self.ignore_warning = False
     try:
         self.pred.should_terminate = True
         print("Successfully terminated predicting thread !")
     except Exception as err:
         print(err)
     
     # KILL EXISTING PROCESS
     try:
         subprocess.Popen.kill(self.graph_process)
     except Exception as err:
         print(err)
     
     date = (self.calendar.get_date())
     date = datetime.strptime(date,"%Y-%m-%d")
     import threading as th
     import multiprocessing as mp
     daydelta = 0
     fill_plot=bool(self.options["fill"].get()) # fill plot
     scatter_plot = bool(self.options["scatter"].get()) # use scatter plot
     print("plot options",fill_plot,scatter_plot)
     use_gpu = bool(self.options["use_gpu"].get()) # use gpu for tensorflow 
     num_biomass = self.options["num_biomass"].get()
     num_biogas = self.options["num_biogas"].get()
     num_solar = self.options["num_solar"].get()
     biomass_pv = self.options["biomass_pv"].get()
     biogas_pv = self.options["biogas_pv"].get()
     period = 15
     self.pred = predictor(dt=date,model_path=self.model,use_gpu=use_gpu,message_callback=self.power_error_callback) # creat new instance of predictor
     self.pred.iteration_delay = self.interval_scaler.get()/1000 # self.predictor loop delay
     self.pred.BIOMASS_PV = biomass_pv
     self.pred.BIOGAS_PV = biogas_pv
     self.pred.num_biomass = num_biomass
     self.pred.num_biogas = num_biogas
     self.pred.num_solar = num_solar
     pred_thread = th.Thread(target=self.pred.run)
     pred_thread.start()
     self.graph_process = subprocess.Popen([
         "python",
         "plot_load.py",
         "--date",str(date.date()),
         "--scatter-plot", str(scatter_plot),
         "--fill-plot", str(fill_plot)
     ])
Exemple #6
0
def home_post():
    if request.method == 'POST':
        text = request.form.get('symptoms_input')
        words = word_extractor(text)
        final_symptoms = symptoms(words)
        diseases = predictor(final_symptoms)
        global input_text
        input_text = text

        if request.form.get('accept'):
            db.child('Accepted Diseases').child(input_text).update(
                {"Symptoms": final_symptoms})
            db.child('Accepted Diseases').child(input_text).update(
                {"Disease": diseases})

    return render_template('disease.html',
                           text=text,
                           final_symptoms=final_symptoms,
                           diseases=diseases)
def handle_message(event):
    if event.message.type == "text":
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='แมววว'))

    elif event.message.type == "image":
        message_content = line_bot_api.get_message_content(event.message.id)
        filepath = event.message.id + "image.jpg"
        with open(filepath, 'wb') as fd:
            for chunk in message_content.iter_content():
                fd.write(chunk)

        fd.close()

        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=predict.predictor(filepath)))

    else:
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text="นี้คือ " + event.message.type))
Exemple #8
0
import predict as pd
my_data = [['slashdot', 'USA', 'yes', 18, 'None'],
           ['google', 'France', 'yes', 23, 'Premium'],
           ['digg', 'USA', 'yes', 24, 'Basic'],
           ['kiwitobes', 'France', 'yes', 23, 'Basic'],
           ['google', 'UK', 'no', 21, 'Premium'],
           ['(direct)', 'New Zealand', 'no', 12, 'None'],
           ['(direct)', 'UK', 'no', 21, 'Basic'],
           ['google', 'USA', 'no', 24, 'Premium'],
           ['slashdot', 'France', 'yes', 19, 'None'],
           ['digg', 'USA', 'no', 18, 'None'],
           ['google', 'UK', 'no', 18, 'None'],
           ['kiwitobes', 'UK', 'no', 19, 'None'],
           ['digg', 'New Zealand', 'yes', 12, 'Basic'],
           ['slashdot', 'UK', 'no', 21, 'None'],
           ['google', 'UK', 'yes', 18, 'Basic'],
           ['kiwitobes', 'France', 'yes', 19, 'Basic']]
header = ['Company', 'Country', 'FAQ', 'No. of Visits']
name = raw_input("Company Name:")
country = raw_input("Country :")
faq = raw_input("Visited FAQ (yes/no)")
visits = int(raw_input("No. of Visits"))
tple = [name, country, faq, visits]
pd.predictor(my_data, tple, header, "Subscription Prediction")
Exemple #9
0
import predict as pd

data = [['yes', 'single', 125, 'No'], ['no', 'married', 100, 'No'],
        ['no', 'single', 70, 'No'], ['yes', 'married', 120, 'No'],
        ['no', 'divorced', 95, 'Yes'], ['no', 'married', 60, 'No'],
        ['yes', 'divorced', 220, 'No'], ['no', 'single', 85, 'Yes'],
        ['no', 'married', 75, 'No'], ['no', 'single', 90, 'Yes']]

header = ["Home Owner", "Marital Status", "Annual Income"]
own = raw_input("Home Owner?(yes/no)")
mar = raw_input("Marital status(single/married/divorced)")
inc = int(raw_input("Annual Income"))
pd.predictor(data, [own, mar, inc], header, "Defaulted Borrower")
Exemple #10
0
import predict
import cv2

weights_path = "../../inceptionV3.299x299.h5"

p = predict.predictor(weights_path)

#print('\n Enter the path to the image\n')
#image_path = input().strip()
#print(p.predict_from_path(image_path))

img = cv2.imread("../../pythonFL/data/test/drawings/0A2FD005-76FF-4C5A-8C81-8179010ED1BB.jpg")
img = cv2.resize(img, (299, 299))

print(p.predict_from_array(img))