Пример #1
0
 def dataset_picker(state: SessionState):
     columns = st.beta_columns(5)
     state.dataset = select_random_dataset()
     image_idx = 0
     for col in columns:
         col.image(state.dataset[image_idx])
         image_idx += 1
         col.image(state.dataset[image_idx])
         image_idx += 1
     if st.button("Select random dataset"):
         state.images = state.dataset
         state.default_text_input = "A sign that says 'SLOW DOWN'"
Пример #2
0
def main():
    print(COLOR_HEADER + "Insomniac " + get_version() + "\n" + COLOR_ENDC)

    if not check_adb_connection():
        return

    ok, args = _parse_arguments()
    if not ok:
        return

    if len(args.bloggers) == 0:
        print(COLOR_FAIL + "Zero bloggers, no sense to proceed." + COLOR_ENDC)
        return
    else:
        print("bloggers = " +
              ", ".join(str(blogger) for blogger in args.bloggers))

    device = uiautomator.device
    storage = Storage()
    on_interaction = partial(_on_interaction,
                             interactions_limit=int(args.interactions),
                             likes_limit=int(args.total_likes_limit))

    while True:
        session_state = SessionState()
        sessions.append(session_state)

        print(COLOR_OKBLUE + "\n-------- START: " +
              str(session_state.startTime) + " --------" + COLOR_ENDC)
        open_instagram()
        _job_handle_bloggers(device, args.bloggers, int(args.likes_count),
                             storage, on_interaction)
        close_instagram()
        session_state.finishTime = datetime.now()
        print(COLOR_OKBLUE + "-------- FINISH: " +
              str(session_state.finishTime) + " --------" + COLOR_ENDC)
        _print_report()

        if args.repeat:
            repeat = int(args.repeat)
            print("\nSleep for " + str(repeat) + " minutes")
            try:
                sleep(60 * repeat)
            except KeyboardInterrupt:
                _print_report()
                sys.exit(0)
        else:
            break

    _print_report()
Пример #3
0
 def prompts_input(state: SessionState,
                   input_label: str,
                   prompt_prefix: str = ''):
     raw_text_input = st.text_input(
         input_label,
         value=state.default_text_input
         if state.default_text_input is not None else "")
     state.is_default_text_input = raw_text_input == state.default_text_input
     if raw_text_input:
         state.prompts = [
             prompt_prefix + class_name
             for class_name in raw_text_input.split(";")
             if len(class_name) > 1
         ]
Пример #4
0
    def __init__(self, session_state):
        self.tab = "Data Loading"
        self.loading_session_state = SessionState.get(
            file=session_state.file,
            file_button=session_state.file_button,
            link=session_state.link,
            path=session_state.path,
            path_button=session_state.path_button,
            link_button=session_state.link_button,
            raw_data=session_state.raw_data,
            data_check=session_state.data_check,
            data_load_state=session_state.data_load_state,
            out_col=session_state.out_col,
            unique_values=session_state.unique_values,
            selected_filename=session_state.selected_filename,
            out_col_check=session_state.out_col_check,
            problem_type=session_state.problem_type)

        self.de_session_state = SessionState.get(
            raw_data=session_state.raw_data,
            out_col=session_state.out_col,
            to_drop=session_state.to_drop,
            num_impute_strategy=session_state.num_impute_strategy,
            cat_impute_strategy=session_state.cat_impute_strategy,
            encode_strategy=session_state.encode_strategy,
            scale_strategy=session_state.scale_strategy,
            balance_strategy=session_state.balance_strategy,
            problem_type=session_state.problem_type)

        self.viz_session_state = SessionState.get(
            raw_data=session_state.raw_data,
            out_col=session_state.out_col,
            problem_type=session_state.problem_type)

        self.ml_session_state = SessionState.get(
            raw_data=session_state.raw_data, out_col=session_state.out_col)

        self.load_page = loading_page(self.loading_session_state)
        self.de_page = data_engineering_page(self.de_session_state)
        self.viz_page = exploration_page(self.viz_session_state)
        self.ml_page = ml_page(self.ml_session_state)
        self.ml_reg_page = ml_reg_page(self.ml_session_state)
        self.problem_type = session_state.problem_type
Пример #5
0
 def image_uploader(state: SessionState, accept_multiple_files: bool):
     uploaded_images = st.file_uploader(
         "Upload image",
         type=[".png", ".jpg", ".jpeg"],
         accept_multiple_files=accept_multiple_files)
     if (not accept_multiple_files and uploaded_images is not None) or (
             accept_multiple_files and len(uploaded_images) >= 1):
         images = []
         if not accept_multiple_files:
             uploaded_images = [uploaded_images]
         for uploaded_image in uploaded_images:
             pil_image = Image.open(uploaded_image)
             pil_image = preprocess_image(pil_image)
             images.append(pil_image)
         state.images = images
Пример #6
0
 def image_picker(state: SessionState, default_text_input: str):
     col1, col2, col3 = st.beta_columns(3)
     with col1:
         default_image_1 = "https://cdn.pixabay.com/photo/2014/10/13/21/34/clipper-487503_960_720.jpg"
         st.image(default_image_1, use_column_width=True)
         if st.button("Select image 1"):
             state.images = [default_image_1]
             state.default_text_input = default_text_input
     with col2:
         default_image_2 = "https://cdn.pixabay.com/photo/2019/12/17/18/20/peacock-4702197_960_720.jpg"
         st.image(default_image_2, use_column_width=True)
         if st.button("Select image 2"):
             state.images = [default_image_2]
             state.default_text_input = default_text_input
     with col3:
         default_image_3 = "https://cdn.pixabay.com/photo/2016/11/15/16/24/banana-1826760_960_720.jpg"
         st.image(default_image_3, use_column_width=True)
         if st.button("Select image 3"):
             state.images = [default_image_3]
             state.default_text_input = default_text_input
Пример #7
0
import argparse
import sys
import traceback
from datetime import datetime, timedelta
from functools import partial

import uiautomator

from action_handle_blogger import handle_blogger
from session_state import SessionState
from storage import Storage
from utils import *

sessionState = SessionState()
completedSessions = 0
totalTimeWorked = timedelta(0)


def main():
    print(COLOR_HEADER + "Insomniac " + get_version() + "\n" + COLOR_ENDC)

    if not check_adb_connection():
        return

    ok, args = _parse_arguments()
    if not ok:
        return

    if len(args.bloggers) == 0:
        print(COLOR_FAIL + "Zero bloggers, no sense to proceed." + COLOR_ENDC)
        return
Пример #8
0
def limit_number_prompts(state: SessionState):
    """When moving between tasks sometimes the state of prompts can have too many samples"""
    if state.prompts is not None and len(state.prompts) > 1:
        state.prompts = [state.prompts[0]]
Пример #9
0
def limit_number_images(state: SessionState):
    """When moving between tasks sometimes the state of images can have too many samples"""
    if state.images is not None and len(state.images) > 1:
        state.images = [state.images[0]]
Пример #10
0
import os
import tkinter as tk
from tkinter import filedialog
from matplotlib import pyplot
from sklearn.preprocessing import LabelEncoder
from collections import Counter
from dynamic_sampling_data_generator import DynamicSamplingDataGenerator
from focal_loss import SparseCategoricalFocalLoss
from session_state import SessionState
from model_training_loop import ModelTrainer

st.set_option('deprecation.showPyplotGlobalUse', False)

session_state = SessionState.get(is_model_trained=False,
                                 trained_model=None,
                                 data_augmenter=None,
                                 final_status=None,
                                 is_model_training=False)

td = None
tl = None
vd = None
vl = None

st.sidebar.write("""
## Upload Training Data and Labels
""")

# Upload training set
training_data = st.sidebar.file_uploader("Upload Training Data",
                                         type=["csv", "txt"])
Пример #11
0
def main():
    colorama.init()
    print_timeless(COLOR_HEADER + "Insomniac " + get_version() + "\n" +
                   COLOR_ENDC)

    ok, args = _parse_arguments()
    if not ok:
        return

    global device_id
    device_id = args.device
    device = uiautomator.device if device_id is None else uiautomator.Device(
        device_id)

    if not check_adb_connection(is_device_id_provided=(device_id is not None)):
        return

    mode = None
    is_interact_enabled = len(args.interact) > 0
    is_unfollow_enabled = int(args.unfollow) > 0
    is_unfollow_non_followers_enabled = int(args.unfollow_non_followers) > 0
    total_enabled = int(is_interact_enabled) + int(is_unfollow_enabled) + int(
        is_unfollow_non_followers_enabled)
    if total_enabled == 0:
        print_timeless(
            COLOR_FAIL +
            "You have to specify one of the actions: --interact, --unfollow, "
            "--unfollow-non-followers" + COLOR_ENDC)
        return
    elif total_enabled > 1:
        print_timeless(
            COLOR_FAIL +
            "Running Insomniac with two or more actions is not supported yet."
            + COLOR_ENDC)
        return
    else:
        if is_interact_enabled:
            print("Action: interact with @" +
                  ", @".join(str(blogger) for blogger in args.interact))
            mode = Mode.INTERACT
        elif is_unfollow_enabled:
            print("Action: unfollow " + str(args.unfollow))
            mode = Mode.UNFOLLOW
        elif is_unfollow_non_followers_enabled:
            print("Action: unfollow " + str(args.unfollow_non_followers) +
                  " non followers")
            mode = Mode.UNFOLLOW_NON_FOLLOWERS

    on_interaction = partial(_on_interaction,
                             interactions_limit=int(args.interactions_count),
                             likes_limit=int(args.total_likes_limit))

    while True:
        session_state = SessionState()
        sessions.append(session_state)

        print_timeless(COLOR_WARNING + "\n-------- START: " +
                       str(session_state.startTime) + " --------" + COLOR_ENDC)
        open_instagram(device_id)
        session_state.my_username = get_my_username(device)
        storage = Storage(session_state.my_username)

        # IMPORTANT: in each job we assume being on the top of the Profile tab already
        if mode == Mode.INTERACT:
            _job_handle_bloggers(device, args.interact, int(args.likes_count),
                                 int(args.follow_percentage), storage,
                                 on_interaction)
        elif mode == Mode.UNFOLLOW:
            _job_unfollow(device,
                          int(args.unfollow),
                          storage,
                          only_non_followers=False)
        elif mode == Mode.UNFOLLOW_NON_FOLLOWERS:
            _job_unfollow(device,
                          int(args.unfollow_non_followers),
                          storage,
                          only_non_followers=True)

        close_instagram()
        print_copyright(session_state.my_username)
        session_state.finishTime = datetime.now()
        print_timeless(COLOR_WARNING + "-------- FINISH: " +
                       str(session_state.finishTime) + " --------" +
                       COLOR_ENDC)

        if args.repeat:
            _print_report()
            repeat = int(args.repeat)
            print_timeless("")
            print("Sleep for " + str(repeat) + " minutes")
            try:
                sleep(60 * repeat)
            except KeyboardInterrupt:
                _print_report()
                sys.exit(0)
        else:
            break

    _print_report()
        """

        self.get_path_or_link()
        self.load_data()
        self.show_raw_data()
        self.show_infos_data()
        self.get_pred_column()
        self.get_unique_values()
        if prob_type == "classification":
            self.show_data_balance()
        self.show_infos_nan()


if __name__ == "__main__":
    session_state = SessionState.get(link="",
                                     path="",
                                     path_button=None,
                                     link_button=None,
                                     raw_data=None,
                                     data_check=False,
                                     data_load_state=0,
                                     data_separator_check=False,
                                     data_separator=',',
                                     out_col="",
                                     unique_values=[],
                                     selected_filename="",
                                     out_col_check=False)

    l = loading_page(session_state)
    l.routine()
Пример #13
0
        self.go_to_de()
        self.go_to_viz()
        self.go_to_ml()


if __name__ == "__main__":

    session_state = SessionState.get(file=None,
                                     file_button=None,
                                     link="",
                                     path="",
                                     path_button=None,
                                     link_button=None,
                                     raw_data=None,
                                     data_check=False,
                                     data_load_state=0,
                                     out_col="",
                                     unique_values=[],
                                     selected_filename="",
                                     out_col_check=False,
                                     to_drop=[],
                                     num_impute_strategy="",
                                     cat_impute_strategy="",
                                     encode_strategy="",
                                     scale_strategy="",
                                     balance_strategy="",
                                     problem_type="classification")

    page_zero = clairevoyance(session_state)
    page_zero.routine()
Пример #14
0
        """

        THE LOOP THAT STREAMLIT WILL BE EXECUTING

        """

        self.get_2_axis_viz()
        self.joint_plot()
        self.get_scatter_matrix_rows()
        try:
            self.scatter_matrix(prob_type)
        except:
            st.warning("something is wrong, can't plot scatter matrix")

        if prob_type == "classification":
            self.get_hist_col()
            self.plot_hist_m()
        else:
            self.get_box_col()
            self.plot_box_seaborn()
        self.get_corr()
        self.plot_corr_matrix()
        self.plot_pca()


if __name__ == "__main__":
    session_state = SessionState.get(raw_data=pd.read_csv("Churn_Modelling.csv", nrows=10000),
                                    out_col="Exited")#change this bro)
    ep = exploration_page(session_state)
    ep.routine()
Пример #15
0
    def routine(self, prob_type):

        """

        THE LOOP THAT STREAMLIT WILL BE EXECUTING

        """

        self.get_col_to_drop()
        self.get_impute_strategy()
        self.get_encode_strategy()
        self.get_scale_strategy()
        if prob_type == "classification":
            self.get_balance_strategy()
            self.get_discretize_strategy()
        self.run_data_engineering(prob_type)


if __name__ == "__main__":
    session_state = SessionState.get(raw_data=pd.read_csv("Churn_Modelling.csv", nrows=10000),
                                    out_col="Exited", #change this bro
                                    to_drop=[],
                                    num_impute_strategy="",
                                    cat_impute_strategy="",
                                    encode_strategy="",
                                    scale_strategy="",
                                    balance_strategy="")

    de = data_engineering_page(session_state)
    de.routine()