def main():
	
	# text/title
	st.title('"QuizMe": Automated Question and Answer Generator for Any Text, Using Machine Learning')
	st.subheader("By: Mark Torres")
	st.header("This web app lets you automatically generate True/False and Multiple Choice questions for any passage or piece of text.")

	col1, col2 = st.beta_columns([3, 1])

	with col1:
		# create text box to enter data
		st.subheader("Please enter a paragraph or more about any topic (from horses to Australia to macaroni and cheese) and our app will create test questions about that topic!")
		text = st.text_area("Enter your text:", height = 250)

	with col2:
		# ask how many questions you want
		st.subheader("Please fill out some additional options below:")

		num_questions = st.number_input("How many questions would you like to create? Typically, somewhere around 10 questions gives the best results",
										min_value = 0, 
										max_value = 50, 
										value = 10, 
										step = 1, 
										format = '%i')

		# ask if they want True/False, MC, or both
		type_of_question = st.radio("What types of questions do you want? Currently we support True/False and Multiple Choice questions", 
									options = ["Multiple Choice", "True/False", "Both"])

		# if they choose either Multiple Choice or Both, ask them how many options they'd want
		if type_of_question == "Multiple Choice" or type_of_question == "Both":
			num_options_MC = st.radio("How many multiple choice options would you want to see?", options = [3, 4, 5], index=1)

	# submit
	if st.button("Create questions!"):
		# add first success message
		st.success("Successfully submitted!")
		# add loading capability (TODO: get this to time the question generation process - use as decorator?)

		# get our questions
		if type_of_question == "Multiple Choice":
			question_answer_list = get_multiple_choice_questions(text, num_questions, num_options_MC)
		elif type_of_question == "True/False":
			question_answer_list = get_true_false_questions(text, num_questions)
		elif type_of_question == "Both":
			mc_questions = get_multiple_choice_questions(text, num_questions, num_options_MC)
			true_false_questions = get_true_false_questions(text, num_questions)
			# combine both lists
			question_answer_list = mc_questions + true_false_questions
			# shuffle
			random.shuffle(question_answer_list)
			# get only desired number of questions
			question_answer_list[:num_questions]
		else:
			st.error("Please select a type of question (see options above)")

		# add success at end
		st.success("Questions were successfully created! Check it out below!")
		# print original text
		st.subheader("Your original text:")
		st.markdown(text)
		st.subheader("Here are the questions that our AI program came up with:")
		# print questions
		for question_num, question in enumerate(question_answer_list):
			question_with_num = f"{question_num + 1})" + question
			st.markdown(question_with_num)
Ejemplo n.º 2
0
def app():

    # THE DATA
    data_load = st.text('Loading data...')
    df = get_cached_data()
    data_load.text(' ')
    # # Control charts
    # csfont = {'fontname': 'Comic Sans MS'}
    # hfont = {'fontname': 'Helvetica'}
    # # plt.rcParams['font.sans-serif'] = 'Arial'
    # # plt.rcParams['font.family'] = 'sans-serif'
    # plt.rcParams['text.color'] = '#404040'
    # plt.rcParams['axes.labelcolor'] = '#404040'
    # plt.rcParams['xtick.color'] = '#402020'
    # plt.rcParams['ytick.color'] = '#402020'
    # plt.rcParams['font.size'] = 12
    
    st.markdown('# SURVEY - Characteristics of the respondants')
    st.write('''#''')
    ##########
    # GENDER #
    ##########
    
    st.markdown('## Gender of respondents percentage distribution')
    st.markdown('#')
    st.markdown("""
                Resopondents were 72.08 % female, 26.89 % Male. The remaining respondents answered 'other' or did not provide an answer.
                    """)
    
    col1, col2, col3, col4 = st.beta_columns((2, 0.5, 1.2, 0.8))
    
    with col1:

    
        color_palette_list = ['#CDF1AE', '#90DACC', '#F7E9D1', '#F4D2B5',
                            '#EAB7B7', '#B89ACF']
        
        # GENDER PIE CHART
        values = list(df['Dem_gender'].value_counts(normalize=True))
        names = list(df['Dem_gender'].value_counts().index)
        fig = px.pie(df, values=values, names=names
                    )
        fig.update_traces(textposition='outside', textinfo='percent+label',
                        marker=dict(colors=color_palette_list))
        st.plotly_chart(fig, use_container_width=True)
        
        
    
    with col3: 
        st.markdown('''
                    #
                    #
                    #### Gender of respondents percentage
                    ''')
        # TABLE GENDER
        df_gender = pd.DataFrame(
            (df['Dem_gender'].value_counts(normalize=True)))
        df_gender.columns = ['%']
        st.table(df_gender)
        
        
        
    st.write('''---''')
    
    ##############
    # EMPLOYMENT #
    ##############
    st.markdown('## Employment Status of respondents perctage distribution')
    st.markdown('#')
    st.markdown('''
                    The majority of respondents (58.83%) were in full-time, part-time work or self-employed,
                    15.69% were either unemployed or retired, 16.6% were students.
                    ''')
    col1, col2, col3, col4 = st.beta_columns((2, 0.5, 1.2, 0.8))
    with col1:
        
        

        # EMPLOYMENT PIE CHART
        values = list(df['Dem_employment'].value_counts(normalize=True))
        names = list(df['Dem_employment'].value_counts().index)
        fig = px.pie(df, values=values, names=names,
                    title='Employment Status of respondents'
                    )
        fig.update_traces(textposition='inside', textinfo='percent+label',
                        marker=dict(colors=color_palette_list))
        st.plotly_chart(fig, use_container_width=True)

        
    with col3:
        st.markdown('''
                    #
                    ### Employment Status of respondents percentage
                    ''')
        # EMPLOYMENT TABLE
        df_employment = pd.DataFrame(
            (df['Dem_employment'].value_counts(normalize=True)*100))
        df_employment.columns = ['%']

        st.table(df_employment)
    
    st.write('''---''')
    
    #######
    # AGE #
    #######
    
    st.write('## Age of respondents')
    st.markdown('#')
    
    col1, col2, col3, col4 = st.beta_columns((2, 0.25, 0.75, 1))
    
    # AGE HISTOGRAM
    with col1:
        st.markdown(
            'The age of the respondents ranged from 18 to 110, with a median age of 38.89.')
        st.markdown('#')
        # FIG 1
        counts, bins = np.histogram(df.Dem_age, bins=range(18, 115, 5))
        bins = 0.5 * (bins[:-1] + bins[1:])
        fig = px.bar(x=bins, y=counts, labels={
                     'x': 'Age', 'y': 'Count'})
        st.plotly_chart(fig, use_container_width=True)
        
        # FIG 2
        # fig = px.histogram(df, x="Dem_age", nbins=45, histnorm='percent',
        #                    title='Age distribution of respondents', opacity=0.5)
        
        # st.plotly_chart(fig, use_container_width=True)
        
        # FIG 3
        
        # st.bar_chart(np.histogram(df['Dem_age'], bins=25)[0])
        
    
        
        
    with col3:
        # st.markdown('#')
        st.markdown(f"""
                    Maximal age of a respondent: `{df['Dem_age'].max()}` \n
                    Minimal age of a respondent: `{df['Dem_age'].min()}` \n
                    Mean age: `{df['Dem_age'].mean().round(2)}`
                    """)
        st.table(df[['Dem_age']].describe())
Ejemplo n.º 3
0
def page_work(state_container, page_flip: bool):
    '''The main workhorse routine for the Xplore page'''

    if not state_container.xploreSessionState:
        state_container.xploreSessionState = XploreSessionState()
        state = state_container.xploreSessionState
        state.columns = ['default']
    else:
        state = state_container.xploreSessionState

    url_params = st.experimental_get_query_params()
    page = url_params.pop('page', '')
    if get_title() in page:
        if url_params and not all(not x for x in url_params.values()):
            for key in url_params:
                if key == 'columns':
                    # This needs to be a list
                    continue
                val = url_params.get(key, '')
                if isinstance(val, list):
                    val = val[0]
                    url_params[key] = val
                if key == '':
                    if val == 'True':
                        url_params[key] = True
                    else:
                        url_params[key] = False
            state.__init__(**url_params)

    sqobjs = state_container.sqobjs
    # All the user input is preserved in the state vars
    xplore_sidebar(state, sqobjs)

    if state.table != "tables":
        df = gui_get_df(sqobjs[state.table], _table=state.table,
                        namespace=state.namespace.split(),
                        hostname=state.hostname.split(),
                        start_time=state.start_time, end_time=state.end_time,
                        view=state.view, columns=state.columns)
        if state.table == "device" and 'uptime' in df.columns:
            df.drop(columns=['uptime'], inplace=True)
    else:
        df = gui_get_df(sqobjs[state.table], _table=state.table,
                        namespace=state.namespace.split(),
                        hostname=state.hostname.split(),
                        start_time=state.start_time, end_time=state.end_time,
                        view=state.view)

    if state.table != "tables":
        summ_df = xplore_run_summarize(sqobjs[state.table],
                                       namespace=state.namespace.split(),
                                       hostname=state.hostname.split(),
                                       start_time=state.start_time,
                                       end_time=state.end_time,
                                       query_str=state.query)
    else:
        summ_df = pd.DataFrame()

    if not df.empty:
        if 'error' in df.columns:
            st.error(df.iloc[0].error)
            st.experimental_set_query_params(**asdict(state))
            st.stop()
        if state.query:
            try:
                show_df = df.query(state.query)
            except Exception:
                st.warning('Query string throws an exception, ignoring')
                show_df = df
        else:
            show_df = df
    else:
        show_df = df

    if not show_df.empty:
        dfcols = show_df.columns.tolist()
        if (state.table == 'routes' and 'prefix' in dfcols and
                'prefixlen' not in dfcols):
            dfcols.append('prefixlen')

        dfcols = sorted((filter(lambda x: x not in ['index', 'sqvers'],
                                dfcols)))

        grid1 = st.beta_container()
        headercol, uniq_col = st.beta_columns(2)
        with grid1:
            with headercol:
                st.write(
                    f'<h2 style="color: darkblue; font-weight: bold;">{state.table} View</h2>',
                    unsafe_allow_html=True)
                if show_df.shape[0] > 256:
                    st.write(
                        f'Showing first 256 of {show_df.shape[0]} rows, use query to filter')
            with uniq_col:
                if state.table != "tables":
                    if (not state.uniq_clicked or
                            state.uniq_clicked not in dfcols):
                        if 'hostname' in dfcols:
                            selindex = dfcols.index('hostname')+1
                        else:
                            selindex = 1
                    elif state.uniq_clicked in dfcols:
                        selindex = dfcols.index(state.uniq_clicked)+1

                    state.uniq_clicked = st.selectbox(
                        'Distribution Count of', options=['-'] + dfcols,
                        index=selindex, key='distcount')

        scol1, scol2 = st.beta_columns(2)

        if state.table != "tables" and state.uniq_clicked != '-':
            uniq_df = xplore_run_unique(show_df,
                                        columns=state.uniq_clicked)
        else:
            uniq_df = pd.DataFrame()

        if state.assert_clicked:
            assert_df = xplore_run_assert(sqobjs[state.table],
                                          start_time=state.start_time,
                                          end_time=state.end_time,
                                          namespace=state.namespace.split())
        else:
            assert_df = pd.DataFrame()

        if not summ_df.empty:
            with scol1:
                st.subheader('Summary Information')
                st.dataframe(data=summ_df)

        if not uniq_df.empty:
            with scol2:
                if uniq_df.shape[0] > 32:
                    st.warning(
                        f'{state.uniq_clicked} has cardinality > 32. Displaying top 32')
                    chart = alt.Chart(
                        uniq_df.head(32),
                        title=f'{state.uniq_clicked} Distribution') \
                        .mark_bar(color='purple', tooltip=True) \
                        .encode(y=alt.Y(f'{state.uniq_clicked}:N',
                                        sort='-x'),
                                x='count')
                else:

                    chart = alt.Chart(
                        uniq_df, title=f'{state.uniq_clicked} Distribution') \
                        .mark_bar(color='purple', tooltip=True) \
                        .encode(y=alt.Y(f'{state.uniq_clicked}:N',
                                        sort='-x'),
                                x='count')
                st.altair_chart(chart)

        if state.table in ['interfaces', 'ospf', 'bgp', 'evpnVni']:
            if assert_df.empty:
                expand_assert = False
            else:
                expand_assert = True
            validate_expander = st.beta_expander('Assert',
                                                 expanded=expand_assert)
            with validate_expander:
                if not assert_df.empty:
                    st.dataframe(data=assert_df)
                elif state.assert_clicked:
                    st.write('Assert passed')
                else:
                    st.write('Assert not run')

    expander = st.beta_expander('Table', expanded=True)
    with expander:
        if not show_df.empty:
            convert_dict = {
                x: 'str' for x in df.select_dtypes('category').columns}
            st.dataframe(data=sq_gui_style(show_df.head(256)
                                           .astype(convert_dict),
                                           state.table),
                         height=600, width=2500)
        else:
            st.warning('No Data from query')

        st.experimental_set_query_params(**asdict(state))
Ejemplo n.º 4
0
    pdp_chart_data = pd.DataFrame({"x": pdp_grid, "PD": pdp_values})

    # ICE
    ice_grid, ice_values, feature_type = ice(model_fit,
                                             x,
                                             reference_feature,
                                             grid_resolution=50)
    ice_chart_data = pd.DataFrame(ice_values.T)
    ice_chart_data.columns = [str(c) for c in ice_chart_data.columns]
    ice_chart_data["index"] = ice_grid

    # ALE
    ale_grid, ale_values, feature_type = ale(model_fit, x, reference_feature)
    ale_chart_data = pd.DataFrame({"x": ale_grid, "ALE": ale_values})

    col1, col2 = st.beta_columns(2)
    with col1:
        st.write(
            alt.Chart(pdp_chart_data, title="PDP").mark_line().encode(
                x=alt.X("x", title=pretty_feature_name),
                y=alt.Y("PD", title="")).configure_title(
                    fontSize=18).properties(width=450))
    with col2:
        base = alt.Chart(title="ICE").mark_line().encode(
            x=alt.X("index", title=pretty_feature_name))
        st.write(
            alt.layer(*[
                base.encode(y=alt.Y(col, title=""))
                for col in ice_chart_data.columns if col != "index"
            ],
                      data=ice_chart_data).configure_title(
Ejemplo n.º 5
0
if app == 'Explore Data':
    about_expander = st.beta_expander('About', expanded=True)
    with about_expander:
        img = Image.open('heartattack.jpg')
        st.image(img)
        st.write("""
                Cardiovascular diseases (CVDs) are the **number 1 cause of death** globally, 
                taking an estimated 17.9 million lives each year, which accounts for 31 
                percent of all deaths worlwide. Heart failure is a common event caused 
                by CVDs and this dataset contains 12 features that can be used to predict 
                mortality by heart failure.
                """)

    st.subheader('**Explore the dataset**')
    col1, col2 = st.beta_columns(2)
    selectbox_options = col1.selectbox(
        'Transform',
        ['Head', 'Tail', 'Describe', 'Shape', 'DTypes', 'Value Count'])
    if selectbox_options == 'Head':
        input_count = col2.number_input('Count', 5, 50, help='min=5, max=50')
        st.write(df.head(input_count))
    elif selectbox_options == 'Tail':
        input_count = col2.number_input('Count', 5, 50, help='min=5, max=50')
        st.write(df.tail(input_count))
    elif selectbox_options == 'Describe':
        st.write(df.describe())
    elif selectbox_options == 'Shape':
        st.write(df.head())
        st.write('Shape: ', df.shape)
    elif selectbox_options == 'DTypes':
Ejemplo n.º 6
0
def run_eda_app():
    st.subheader("From Exploratory Data Analysis")
    # df = pd.read_csv("data/diabetes_data_upload.csv")
    df = load_data("data/diabetes_data_upload.csv")
    df_encoded = load_data("data/diabetes_data_upload_clean.csv")
    freq_df = load_data("data/freqdist_of_age_data.csv")

    submenu = st.sidebar.selectbox("Submenu", ["Descriptive", "Plots"])
    if submenu == "Descriptive":
        st.dataframe(df)

        with st.beta_expander("Data Types"):
            st.dataframe(df.dtypes)

        with st.beta_expander("Descriptive Summary"):
            st.dataframe(df_encoded.describe())

        with st.beta_expander("Class Distribution"):
            st.dataframe(df['class'].value_counts())

        with st.beta_expander("Gender Distribution"):
            st.dataframe(df['Gender'].value_counts())

    elif submenu == "Plots":
        st.subheader("Plots")

        # Layouts
        col1, col2 = st.beta_columns([2, 1])

        with col1:
            with st.beta_expander("Dist Plot of Gender"):
                fig = plt.figure()
                sns.countplot(df['Gender'])
                st.pyplot(fig)

                gen_df = df['Gender'].value_counts().to_frame()
                # st.dataframe(gen_df)
                gen_df = gen_df.reset_index()
                gen_df.columns = ["Gender Type", "Counts"]
                # st.dataframe(gen_df)

                p1 = px.pie(gen_df, names='Gender Type', values='Counts')
                st.plotly_chart(p1, use_container_width=True)

            # For Class Distribution
            with st.beta_expander("Dist Plot of Class"):
                fig = plt.figure()
                sns.countplot(df['class'])
                st.pyplot(fig)

        with col2:
            with st.beta_expander("Gender Distribution"):
                st.dataframe(gen_df)

            with st.beta_expander("Class Distribution"):
                st.dataframe(df['class'].value_counts())

        # Freq Dist
        with st.beta_expander("Frequency Dist of Age"):
            # st.dataframe(freq_df)
            p2 = px.bar(freq_df, x='Age', y='count')
            st.plotly_chart(p2)

        # Outlier Detection
        with st.beta_expander("Outlier Detection Plot"):
            fig = plt.figure()
            sns.boxplot(df['Age'])
            st.pyplot(fig)

            p3 = px.box(df, x='Age', color='Gender')
            st.plotly_chart(p3)

        # Correlation
        with st.beta_expander("Correlation Plot"):
            corr_matrix = df_encoded.corr()
            fig = plt.figure(figsize=(20, 10))
            sns.heatmap(corr_matrix, annot=True)
            st.pyplot(fig)

            p4 = px.imshow(corr_matrix)
            st.plotly_chart(p4)
Ejemplo n.º 7
0
def main():
    """Simple Login App"""

    menu = ["Home", "Login", "SignUp"]
    choice = st.sidebar.selectbox("Menu", menu)

    if choice == "Home":
        st.markdown(
            """<p style="text-align: justify;"><span style="font-size: 18px;">This dataset illustrates health status of 26 of the nation&rsquo;s largest and most urban cities as captured by 34 health <span style="white-space:pre;">&nbsp;</span>(and six demographics-related) indicators. These indicators represent some of the leading causes of morbidity and mortality in the United States <span style="white-space:pre;">&nbsp;</span>and leading priorities of national, state, and local health agencies. Public health data were captured in nine overarching categories: HIV/AIDS, cancer, nutrition/physical activity/obesity, food safety, infectious disease, maternal and child health, tobacco, injury/violence, and behavioral health/substance abuse..</span></p>
<p style="text-align: justify;"><em><strong><span style="font-size: 18px;">Source: https://bchi.bigcitieshealth.org/indicators/1827/searches/34444</span></strong></em></p>""",
            unsafe_allow_html=True)

    elif choice == "Login":
        username = st.sidebar.text_input("User Name")
        password = st.sidebar.text_input("Password", type='password')
        if st.sidebar.checkbox("Login", key='0'):

            # if password == '12345':
            create_usertable()
            hashed_pswd = make_hashes(password)

            result = login_user(username, check_hashes(password, hashed_pswd))
            if result:
                #if result>0:
                lst_indic_cat = df["indic_cat"].unique()
                indic_cat = st.sidebar.selectbox("Indicator Category",
                                                 lst_indic_cat)
                dash = st.sidebar.radio(
                    label="View Dashboard by",
                    options=["Country", "Year & Country", "Sex & Country"])
                query = "SELECT Distinct(Indicator) from df where indic_cat like '{}'".format(
                    indic_cat)
                indicators = sqldf.run(query)
                indicators = indicators['Indicator'].values.tolist()
                num_of_indicators = len(indicators)
                num_of_div = int(num_of_indicators / 2)
                if dash == "Country":
                    indx = 0
                    st.subheader("Dashboard showing different Indicators of " +
                                 indic_cat + " Category By Country")
                    if num_of_indicators == 1:
                        c_plot0, c_plot1 = st.beta_columns(2)
                        query = "SELECT Value,Place from df where Indicator like '{}'".format(
                            indicators[indx]) + " group by Place"
                        df_per_indicator = sqldf.run(query)
                        fig = get_bar_plots(df_per_indicator, indicators[indx],
                                            indic_cat, 'Place', "")
                        c_plot0.plotly_chart(fig, use_container_width=True)
                    else:
                        if num_of_indicators > 1:
                            for div in range(num_of_div):
                                c_plot1, c_plot2 = st.beta_columns(2)
                                c_plots = [c_plot1, c_plot2]
                                for i in range(2):
                                    query = "SELECT Sum(Value) Value,Place from df where Indicator like '{}'".format(
                                        indicators[indx]) + " group by Place"
                                    df_per_indicator = sqldf.run(query)
                                    fig = get_bar_plots(
                                        df_per_indicator, indicators[indx],
                                        indic_cat, 'Place', "")
                                    c_plots[i].plotly_chart(
                                        fig, use_container_width=True)
                                    indx = indx + 1
                            if num_of_indicators % 2 > 0:
                                c_plot3, c_plot4 = st.beta_columns(2)
                                query = "SELECT Value,Place from df where Indicator like '{}'".format(
                                    indicators[indx]) + " group by Place"
                                df_per_indicator = sqldf.run(query)
                                fig = get_bar_plots(df_per_indicator,
                                                    indicators[indx],
                                                    indic_cat, 'Place', "")
                                c_plot3.plotly_chart(fig,
                                                     use_container_width=True)
                else:
                    if dash == "Year & Country":
                        lst_countries = df["Place"].unique()
                        place = st.sidebar.selectbox(
                            "Select Country to Filter on", lst_countries)
                        indx = 0
                        st.subheader(
                            "Dashboard showing different Indicators of " +
                            indic_cat + " Category By Year")
                        if num_of_indicators == 1:
                            c_plot0, c_plot1 = st.beta_columns(2)
                            query = "SELECT Sum(Value) Value,Year from df where Indicator like '{}'".format(
                                indicators[indx]
                            ) + " and Place like '{}'".format(
                                place) + " group by Year"
                            df_per_indicator = sqldf.run(query)
                            fig = get_line_plots(df_per_indicator,
                                                 indicators[indx], indic_cat)
                            c_plot0.plotly_chart(fig, use_container_width=True)
                        else:
                            if num_of_indicators > 1:
                                for div in range(num_of_div):
                                    c_plot1, c_plot2 = st.beta_columns(2)
                                    c_plots = [c_plot1, c_plot2]
                                    for i in range(2):
                                        query = "SELECT Sum(Value) Value,Year from df where Indicator like '{}'".format(
                                            indicators[indx]
                                        ) + " and Place like '{}'".format(
                                            place) + " group by Year"
                                        df_per_indicator = sqldf.run(query)
                                        fig = get_line_plots(
                                            df_per_indicator, indicators[indx],
                                            indic_cat)
                                        c_plots[i].plotly_chart(
                                            fig, use_container_width=True)
                                        indx = indx + 1
                                if num_of_indicators % 2 > 0:
                                    c_plot3, c_plot4 = st.beta_columns(2)
                                    query = "SELECT Sum(Value) Value,Year from df where Indicator like '{}'".format(
                                        indicators[indx]
                                    ) + " and Place like '{}'".format(
                                        place) + " group by Year"
                                    df_per_indicator = sqldf.run(query)
                                    fig = get_line_plots(
                                        df_per_indicator, indicators[indx],
                                        indic_cat)
                                    c_plot3.plotly_chart(
                                        fig, use_container_width=True)
                    else:
                        lst_countries = df["Place"].unique()
                        place = st.sidebar.selectbox(
                            "Select Country to Filter on", lst_countries)
                        indx = 0
                        st.subheader(
                            "Dashboard showing different Indicators of " +
                            indic_cat + " Category By Sex")
                        if num_of_indicators == 1:
                            c_plot0, c_plot1 = st.beta_columns(2)
                            query = "SELECT Sum(Value) Value,Sex,Race from df where Indicator like '{}'".format(
                                indicators[indx]
                            ) + " and Place like '{}'".format(
                                place) + " group by Sex,Race"
                            df_per_indicator = sqldf.run(query)
                            fig = get_bar_plots(df_per_indicator,
                                                indicators[indx], indic_cat,
                                                'Sex', 'Race')
                            c_plot0.plotly_chart(fig, use_container_width=True)
                        else:
                            if num_of_indicators > 1:
                                for div in range(num_of_div):
                                    c_plot1, c_plot2 = st.beta_columns(2)
                                    c_plots = [c_plot1, c_plot2]
                                    for i in range(2):
                                        query = "SELECT Sum(Value) Value,Sex,Race from df where Indicator like '{}'".format(
                                            indicators[indx]
                                        ) + " and Place like '{}'".format(
                                            place) + " group by Sex,Race"
                                        df_per_indicator = sqldf.run(query)
                                        fig = get_bar_plots(
                                            df_per_indicator, indicators[indx],
                                            indic_cat, 'Sex', 'Race')
                                        c_plots[i].plotly_chart(
                                            fig, use_container_width=True)
                                        indx = indx + 1
                                if num_of_indicators % 2 > 0:
                                    c_plot3, c_plot4 = st.beta_columns(2)
                                    query = "SELECT Sum(Value) Value,Sex,Race from df where Indicator like '{}'".format(
                                        indicators[indx]
                                    ) + " and Place like '{}'".format(
                                        place) + " group by Sex,Race"
                                    df_per_indicator = sqldf.run(query)
                                    fig = get_bar_plots(
                                        df_per_indicator, indicators[indx],
                                        indic_cat, 'Sex', 'Race')
                                    c_plot3.plotly_chart(
                                        fig, use_container_width=True)
                if st.sidebar.checkbox("Some Insights", False, key='1'):
                    my_expander = st.beta_expander("Expand to View",
                                                   expanded=False)
                    with my_expander:

                        fig, ax = plt.subplots(figsize=(15, 10))
                        sns.countplot(y=df["indic_cat"])
                        ax.set_title(
                            " Dempographics followed by HIV/Aids most popular among the all! "
                        )
                        st.pyplot(fig)

                        fig, ax = plt.subplots(figsize=(15, 10))
                        sns.countplot(y=df["Race"])
                        ax.set_title(
                            " Most people with these indicators are the White, down to the Black, and the Hispanic "
                        )
                        st.pyplot(fig)

                        fig, ax = plt.subplots(figsize=(10, 5))
                        sns.countplot(y=df["Sex"])
                        ax.set_title(
                            " From the gender visualization, more people with the indicators are Females followed by the Males "
                        )
                        st.pyplot(fig)

            else:
                st.warning("Incorrect Username/Password")
    elif choice == "SignUp":
        st.subheader("Create New Account")
        new_user = st.text_input("Username")
        new_password = st.text_input("Password", type='password')

        if st.button("Signup"):
            create_usertable()
            data = user_exists(new_user)
            if data > 0:
                st.warning("Username already exists !")
            else:
                add_userdata(new_user, make_hashes(new_password))
                st.success(
                    "You have successfully created a valid Account,Login in please!"
                )
Ejemplo n.º 8
0
def main():
    st.set_page_config(page_title="Bike rental prediction", layout='wide')

    options = [
        'Home', 'EDA', 'Visualization', 'Model building and evaluation',
        'Prediction'
    ]
    choice = st.sidebar.selectbox('Choose the followings', options)

    if choice == 'Model building and evaluation':
        st.subheader(
            'Build **AutoML** models with 30 different algorithms and corresponding evaluation'
        )
        uploaded_file = st.file_uploader('', type=['csv'])
        if uploaded_file is not None:
            df = pd.read_csv(uploaded_file)
            with st.beta_expander('Expand dataframe'):
                st.dataframe(df)

            X = df.drop(['cnt', 'instant', 'dteday'], axis=1)
            Y = df['cnt']

            X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                                Y,
                                                                test_size=0.25)
            reg = LazyRegressor(verbose=0,
                                ignore_warnings=False,
                                custom_metric=None)
            models_train, predictions_train = reg.fit(X_train, X_train,
                                                      Y_train, Y_train)
            models_test, predictions_test = reg.fit(X_train, X_test, Y_train,
                                                    Y_test)

            st.subheader('2. Table of Model Performance on Test set')
            st.write(predictions_test)

            st.subheader('3. Plot of Model Performance (Test set)')

            with st.markdown('**R-squared**'):
                plt.figure(figsize=(9, 3))

                ax1 = sns.barplot(x=predictions_test.index,
                                  y="R-Squared",
                                  data=predictions_test)
                ax1.set(ylim=(0, 1))
                plt.xticks(rotation=90)
                st.pyplot(plt)

            with st.markdown('**RMSE (capped at 50)**'):

                plt.figure(figsize=(9, 3))

                ax2 = sns.barplot(x=predictions_test.index,
                                  y="RMSE",
                                  data=predictions_test)
                plt.xticks(rotation=90)
                st.pyplot(plt)

    elif choice == 'Prediction':
        st.subheader('Prediction for unseen data')
        st.sidebar.header('User Input Features')
        uploaded_file = st.sidebar.file_uploader("Upload your input CSV file",
                                                 type=["csv"])
        if uploaded_file is not None:
            input_df = pd.read_csv(uploaded_file)
        else:
            st.sidebar.subheader('Or input your features manually')

            def user_input_features():
                season = st.sidebar.selectbox('Season', np.arange(1, 5))
                yr = st.sidebar.selectbox('Year', np.arange(0, 2))
                month = st.sidebar.selectbox('Month', np.arange(1, 13))
                holiday = st.sidebar.selectbox('Is Holiday', (0, 1))
                weekday = st.sidebar.selectbox('Number of day',
                                               np.arange(1, 8))
                workingday = st.sidebar.selectbox('Is workind day', (0, 1))
                weathersit = st.sidebar.selectbox('Weather Number',
                                                  np.arange(1, 5))
                temp = st.sidebar.slider('Tempareture', 0.05, 0.86, 0.20)
                atemp = st.sidebar.slider('Atemp', 0.07, 0.84, 0.15)
                hum = st.sidebar.slider('Humadity', 0.0, 0.97, 0.55)
                windspeed = st.sidebar.slider('Windspeed', 0.02, 0.5, 0.08)
                casual = st.sidebar.slider('Casual', 2, 3410, 50)
                registered = st.sidebar.slider('Registered', 20, 6946, 5589)
                data = {
                    'season': season,
                    'yr': yr,
                    'mnth': month,
                    'holiday': holiday,
                    'weekday': weekday,
                    'workingday': workingday,
                    'weathersit': weathersit,
                    'temp': temp,
                    'atemp': atemp,
                    'hum': hum,
                    'windspeed': windspeed,
                    'casual': casual,
                    'registered': registered
                }
                features = pd.DataFrame(data, index=[0])
                return features

            input_df = user_input_features()

            st.subheader('User input features :')
            st.dataframe(input_df)

            if st.button('Start prediction'):
                model = pickle.load(open('LassoLarsIC.pkl', 'rb'))

                pred = model.predict(input_df)
                st.write('The prediction is :', pred)

    elif choice == 'EDA':
        st.subheader('Explanatory data analysis')
        uploaded_file = st.file_uploader('', type=['csv'])
        if uploaded_file is not None:
            df = pd.read_csv(uploaded_file)
            with st.beta_expander('Expand dataframe'):
                st.dataframe(df)

            with st.beta_expander('Full profile information'):
                st_profile_report(ProfileReport(df, explorative=True))

            with st.beta_expander('Display basic summary'):
                st.write(df.describe().T)
            with st.beta_expander('Display data type'):
                st.write(df.dtypes)

    elif choice == 'Visualization':
        st.subheader('Data Visualization')
        uploaded_file = st.file_uploader('', type=['csv'])
        if uploaded_file is not None:
            df = pd.read_csv(uploaded_file)
            with st.beta_expander('Expand dataframe'):
                st.dataframe(df)

            with st.beta_expander('Display bike rental along with time axis'):
                df2 = df.copy(deep=True)
                df2.dteday = pd.to_datetime(df2.dteday)
                df2.set_index('dteday', inplace=True)
                plt.figure(figsize=(20, 6))
                df2['cnt'].plot()
                st.pyplot()
                st.write(
                    'These shows that bike rental counts has seasonality and quite upwards trend.'
                )
            with st.beta_expander('Display heatmap'):
                plt.figure(figsize=(10, 6))
                sns.heatmap(df.corr(), annot=True)
                st.pyplot()
                st.write('There are some multicolliearity.')
            col1, col2 = st.beta_columns(2)
            with col1:
                with st.beta_expander(
                        'Display total bike rental counts with different seasons'
                ):
                    df.groupby('season')['cnt'].sum().plot(kind='bar')
                    st.pyplot()
                    st.write('Maximum bike rent was in season 3.')
                with st.beta_expander(
                        'Display total bike rental counts along with months and years'
                ):
                    df.groupby(['mnth',
                                'yr'])['cnt'].sum().unstack().plot(kind='bar')
                    st.pyplot()
                    st.write(
                        'This plot shows the total bike rental count of every month of 2011 and 2012'
                    )
                    st.write(
                        'From MAY to OCTOBER the total bike rental count was high in every year and total rental in every month has increased from 2011 to 2012'
                    )
                with st.beta_expander(
                        'Display the pie chart of weathersit based on bike rental'
                ):
                    plt.pie(df.groupby('weathersit')['cnt'].sum(),
                            labels=['1', '2', '3'],
                            explode=(0.05, 0, 0),
                            radius=1,
                            autopct='%0.2f%%',
                            shadow=True)
                    plt.tight_layout()
                    plt.legend(loc='upper left')
                    plt.axis('equal')
                    plt.show()
                    st.pyplot()
                    st.write(
                        'we have found total out of total bike rental count, 68.57% count was in "Clear, Few clouds, Partly cloudy, Partly cloudy" weatherand 30.27% was in " Mist + Cloudy, Mist + Broken clouds, Mist + Few clouds, Mist" weather.'
                    )
                with st.beta_expander('Display the outliers'):
                    num_var = [
                        'temp', 'atemp', 'hum', 'windspeed', 'casual',
                        'registered'
                    ]
                    for i in num_var:
                        sns.boxplot(y=i, data=df)
                        plt.title('Boxplot of ' + i)
                        plt.show()
                        st.pyplot()
                    st.write(
                        'We have found some outliers on the features - casual,windspeed and humidity'
                    )
            with col2:
                with st.beta_expander(
                        'Display the relationship between bike rental count and temperature'
                ):
                    sns.scatterplot(x='temp', y='cnt', data=df)
                    st.pyplot()
                    st.write(
                        'We found almost linear relation between temp and count.'
                    )
                with st.beta_expander(
                        'Display the relationship between bike rental count and windspeed'
                ):
                    sns.scatterplot(x='windspeed', y='cnt', data=df)
                    st.pyplot()
                    st.write('There is not much interpretation')
                with st.beta_expander(
                        'Display violine plot of seasons along with bike rental count'
                ):
                    sns.violinplot(x=df.season, y=df.cnt)
                    st.pyplot()
                    st.write(
                        'Less count was in season 1 and it is right skewed and rest 3 seasons has not exactly any long tail and more or less season 2,3,4 have similar distribution'
                    )

    elif choice == 'Home':

        image = Image.open('RentBike_25-09-17_02.jpg')
        st.image(image, use_column_width=True)
        st.title(
            'Bike rental analysis, visualization, model building, evaluation and prediction in a single window'
        )
Ejemplo n.º 9
0
def run_app():
    """Function running the streamlit app
    """
    st.set_page_config(layout="wide")
    st.title("Single Parameter Estimation From Random Sample")

    mle_estimate, mcmc_estimate = st.beta_columns(2)

    st.sidebar.title('Simulated Data')
    mu = st.sidebar.slider('\u03BC',
                           min_value=-100,
                           max_value=100,
                           value=0,
                           step=1)
    n = st.sidebar.slider('N', min_value=10, max_value=100, value=30, step=1)

    run_sampler = st.sidebar.button('Run Sampler')
    y = np.random.normal(mu, 1, size=n)

    with st.sidebar.beta_expander('Metropolis Hastings'):
        mu_init_metr = st.slider('\u03BC First ProposalS',
                                 min_value=-100,
                                 max_value=100,
                                 value=0,
                                 step=1)
        samples = st.number_input('Samples',
                                  min_value=100,
                                  max_value=10000,
                                  value=1000)
        warm_up = st.number_input('Warm-Up',
                                  min_value=100,
                                  max_value=10000,
                                  value=1000)
        proposal_width = st.slider('Proposal Width',
                                   min_value=0.,
                                   max_value=10.,
                                   value=0.1,
                                   step=0.1)
        mu_prior = st.slider('\u03BC Prior',
                             min_value=-100,
                             max_value=100,
                             value=0,
                             step=1)
        sd_prior = st.slider('\u03C3 Prior',
                             min_value=0,
                             max_value=100,
                             value=10,
                             step=1)

    with st.sidebar.beta_expander('Newton-Raphson'):
        mu_init_newt = st.slider('\u03BC Init',
                                 min_value=-100,
                                 max_value=100,
                                 value=0,
                                 step=1)
        tol = st.number_input('Tolerance',
                              min_value=1e-9,
                              max_value=0.1,
                              value=1e-9)
        maxiter = st.number_input('Maximum Number of Iterations',
                                  min_value=10,
                                  max_value=1000,
                                  value=100)
        boot = st.number_input('Number of Bootstrapped Samples',
                               min_value=1,
                               max_value=100,
                               value=30,
                               step=1)

    if run_sampler:
        mcmc_mu = metropolis_hastings(y=y,
                                      mu_init=mu_init_metr,
                                      warm_up=warm_up,
                                      samples=samples,
                                      proposal_width=proposal_width,
                                      prior_mu=mu_prior,
                                      prior_sigma=sd_prior)
        mcmc_fig = plot_solution(mu=mu, variance=1, approx_solution=mcmc_mu)
        mcmc_estimate.header('Metropolis-Hastings Estimate')
        mcmc_estimate.pyplot(mcmc_fig)

        mle_mu = maximum_likelyhood(y=y,
                                    mu_init=mu_init_newt,
                                    boot=boot,
                                    maxiter=maxiter,
                                    tol=tol)
        mle_fig = plot_solution(mu=mu, variance=1, approx_solution=mle_mu)
        mle_estimate.header('Newton-Raphson Estimate')
        mle_estimate.pyplot(mle_fig)
def print_page():
    st.markdown("# Знакомство с Python")
    st.subheader("Первая программа на Python")
    col1, col2 = st.beta_columns(2)
    with col1:
        st.code(
            """
    # Приветствие миру - традиционная 
    # первая строка в освоении
    # нового языка программирования 
    print('Привет, Мир!')
        """,
            language="python",
        )
        st.code("Привет, Мир!", language="out")

    with col2:
        st.write(
            "Любая строчка, начинающаяся с символа `#` — это комментарий, "
            "примечание для разработчика.")

        st.code("""
    # эта команда показывает ”Zen of Python”
    import this
        """)

    st.subheader("Типы переменных")
    col1, col2 = st.beta_columns(2)
    with col1:
        st.write(
            "Переменные в Python могут быть разного типа — целые числа, дробные числа, строки:"
        )

        st.code("""
    one_hundred = 100
    five_hundred = 500
    print(one_hundred + five_hundred)
            """)
        st.code("600", language="out")

        st.code("""
    first = 87.2
    second = 50.2
    third = 50.242
    print(first + second + third)
            """)
        st.code("187.642", language="out")

        st.code("""
    first = '87.2'
    second = '50.2'
    third = '50.242'
    # оператор + объединяет строки:
    print(first + second + third)
            """)
        st.code("87.250.250.242", language="out")

    with col2:
        st.write("Числа приводятся к строкам функцией `str()`:")
        st.code("""
    # объявляем две переменные разных типов:
    number = 100
    rubles = ' рублей'
    # сложить число и строку невозможно, 
    # поэтому приводим number к строке: 
    print(str(number) + rubles)
        """)
        st.code("100 рублей", language="out")

        st.write(
            "Дробные числа приводятся к целым функцией `int()`. Она не округляет числа, "
            "а отбрасывает дробную часть:")

        st.code("""
    # округление вниз, как привыкли
    print(int(3.14))
        """)
        st.code("3", language="out")

        st.code("""
    # а здесь всё равно округление вниз, 
    # хотя вроде бы так быть не должно
    print(int(2.72))
        """)
        st.code("2", language="out")

    st.subheader("Списки")
    col1, col2 = st.beta_columns(2)
    with col1:
        st.write(
            "Списки — это последовательности, похожие на массивы из других языков программирования."
            " Они записываются в квадратных скобках через запятую:")
        st.code("""
    bremen_musicians = ['Трубадур', 'Кот', In 'Пёс', 'Осёл', 'Петух']   
    print(bremen_musicians)
            """)
        st.code("[’Трубадур’, ’Кот’, ’Пёс’, ’Осёл’, ’Петух’]", language="out")

        st.write("Чтобы подсчитать, сколько в списке элементов, "
                 "вызывают стандартную функцию `len()`:")
        st.code("""
    count = len(bremen_musicians)
    print(count)
            """)
        st.code(5, language="out")
    with col2:
        st.write("Список строк можно преобразовать в одну строку. "
                 "Для этого используется метод `join()`:")
        st.code("""
    print('Представляем музыкантов: ' + ', '.join(bremen_musicians))
        """)
        st.code("Представляем музыкантов: Трубадур, Кот, Пёс, Осёл, Петух",
                language="out")
Ejemplo n.º 11
0
def main():

    # set images in middle at the sidebar
    col1, col2, col3 = st.sidebar.beta_columns([1, 6, 1])
    with col1:
        st.write("")
    with col2:
        st.image("img/ggsipu.png", width=200)
    with col3:
        st.write("")

    # set images in middle at the homepage
    col1, col2, col3 = st.beta_columns([6, 6, 6])
    with col1:
        st.write("")
    with col2:
        st.image("img/ggsipu.png", width=200)
    with col3:
        st.write("")

    #to show title on the main page and sidebar
    # st.sidebar.title("Hepatitis Mortality Prediction Web App")
    st.title("Hepatitis Mortality Prediction Web App")

    # to show image at sidebar and main page
    # st.sidebar.image('ggsipu.png',width=200)
    # st.image('ggsipu.png')

    #list menu and submenu for setting options in the list
    sidebar_menu = [
        "1.Project-Introduction", "2.Home-Page", "3.Login-Form",
        "4.Sign-up-Form"
    ]
    homepage_menu = ["1.Check-Plot", "2.Check-Prediction"]

    #sidebar subheader

    #make a selectbox in the sidebar and pass menu list given above to show choices and return choice
    menu_selected = st.sidebar.selectbox(
        "To get started, Please select from the options given below:",
        sidebar_menu)

    if menu_selected == "1.Project-Introduction":
        st.subheader("Hello, Good Morning Users")
        st.subheader(
            "Welcome to the Hepatitis Mortality Prediction Web Application created using streamlit and other python libraries, which will take inputs of dignosed data and predicts whether patient would live or die using various various machine learning models like linear regression, KNN, etc"
        )
        st.subheader("Created by:-")
        st.subheader("1.Name: Ashwani Kumar  [MCA],  Roll no: 40216404518")
        st.subheader("2.Name: Nitin Sharma   [MCA],  Roll no: 40916404518")

    #if choice is home then show subheader and a text below
    elif menu_selected == "2.Home-Page":
        st.image("./img/Awareness-Banner.png", width=700)
        st.video('https://youtu.be/IxCelFhuhQo')
        st.header("what is hepatitis and which organ it effects?".upper())
        st.subheader(
            "Hepatitis is inflammation of the liver. Inflammation is swelling that happens when tissues of the body are injured or infected. It can damage your liver. This swelling and damage can affect how well your liver functions. Hepatitis can be an acute (short-term) infection or a chronic (long-term) infection. Some types of hepatitis cause only acute infections. Other types can cause both acute and chronic infections."
        )
        st.header("what are its causes?".upper())
        st.subheader(
            "There are different types of hepatitis, with different causes: Viral hepatitis is the most common type. It is caused by one of several viruses -- hepatitis viruses A, B, C, D, and E. In the United States, A, B, and C are the most common. Alcoholic hepatitis is caused by heavy alcohol use Toxic hepatitis can be caused by certain poisons, chemicals, medicines, or supplements Autoimmune hepatitis is a chronic type in which your body's immune system attacks your liver. The cause is not known, but genetics and your environment may play a role."
        )
        st.header("How is viral hepatitis spread?".upper())
        st.subheader(
            "Hepatitis A and hepatitis E usually spread through contact with food or water that was contaminated with an infected person's stool. You can also get hepatitis E by eating undercooked pork, deer, or shellfish. Hepatitis B, hepatitis C, and hepatitis D spread through contact with the blood of someone who has the disease. Hepatitis B and D may also spread through contact with other body fluids. This can happen in many ways, such as sharing drug needles or having unprotected sex."
        )
        st.image("./img/hepatitis_body.jpg", width=700)
        st.header("Who is at risk for hepatitis?".upper())
        st.subheader(
            "The risks are different for the different types of hepatitis. For example, with most of the viral types, your risk is higher if you have unprotected sex. People who drink a lot over long periods of time are at risk for alcoholic hepatitis."
        )
        st.header("What are the symptoms of hepatitis?".upper())
        st.subheader(
            "Some people with hepatitis do not have symptoms and do not know they are infected. If you do have symptoms, they may include Fever, Fatigue, Loss of appetite, Nausea and/or vomiting, Abdominal pain, Dark urine, Clay-colored bowel movements, Joint pain, Jaundice, yellowing of your skin and eyes. If you have an acute infection, your symptoms can start anywhere between 2 weeks to 6 months after you got infected. If you have a chronic infection, you may not have symptoms until many years later."
        )
        st.header("What other problems can hepatitis cause?".upper())
        st.subheader(
            "Chronic hepatitis can lead to complications such as cirrhosis (scarring of the liver), liver failure, and liver cancer. Early diagnosis and treatment of chronic hepatitis may prevent these complications."
        )
        st.header("How is hepatitis diagnosed?".upper())
        st.subheader(
            "To diagnose hepatitis, your health care provider 1.Will ask about your symptoms and medical history ,2.Will do a physical exam, 3.Will likely do blood tests, including tests for viral hepatitis , 4.Might do imaging tests, such as an ultrasound, CT scan, or MRI, 5.May need to do a liver biopsy to get a clear diagnosis and check for liver damage"
        )
        st.image("./img/Hepatitis_A_Symptoms.jpeg", width=700)
        st.header("What are the treatments for hepatitis?".upper())
        st.subheader(
            "Treatment for hepatitis depends on which type you have and whether it is acute or chronic. Acute viral hepatitis often goes away on its own. To feel better, you may just need to rest and get enough fluids. But in some cases, it may be more serious. You might even need treatment in a hospital. There are different medicines to treat the different chronic types of hepatitis. Possible other treatments may include surgery and other medical procedures. People who have alcoholic hepatitis need to stop drinking. If your chronic hepatitis leads to liver failure or liver cancer, you may need a liver transplant."
        )
        st.header("Can hepatitis be prevented?".upper())
        st.subheader(
            "There are different ways to prevent or lower your risk for hepatitis, depending on the type of hepatitis. For example, not drinking too much alcohol can prevent alcoholic hepatitis. There are vaccines to prevent hepatitis A and B. Autoimmune hepatitis cannot be prevented."
        )
        st.image("./img/Top-banner-april-2020-2.png", width=700)

    #if choice is login then show 2 inputs for username and password and get data from the login form
    elif menu_selected == "3.Login-Form":

        #get username and password from the form
        get_username = st.text_input("Username:"******"Password:"******"welcome '{}' to the hepatitis mortality prediction webapp"
                    .format(get_username.upper()))

                #show text and select box with options from the list of submenu given menu
                activity_selected = st.selectbox(
                    "please select from the options given below:".upper(),
                    homepage_menu)

                # if checkplot activity selected from options then following code executes
                if activity_selected == "1.Check-Plot":

                    #show subheader text
                    st.subheader(
                        "showing csv file as dataframe which is used for getting data"
                        .upper())

                    # read csv file from the folder and convert into pandas dataframe
                    pd_dataframe = pd.read_csv(
                        "data/clean_hepatitis_dataset.csv")

                    #show dataframe in webapp
                    st.dataframe(pd_dataframe)

                    # take class column from dataframe then count the number of values and plot bargraph
                    pd_dataframe['class'].value_counts().plot(kind='bar')

                    #show subheader text
                    st.subheader(
                        "showing bar graph for the number of patients belongs to class 1 and 2"
                        .upper())

                    #show pyplot in webapp
                    st.pyplot()

                    # read csv file and convert into dataframe
                    freq_dataframe = pd.read_csv(
                        "data/freq_df_hepatitis_dataset.csv")

                    #show subheader text
                    st.subheader(
                        "showing bar chart for count vs age(0-150 years)".
                        upper())

                    #show bar chart in web app having column name count
                    st.bar_chart(freq_dataframe['count'])

                    #*********************************bug portion 1******************************************
                    #make a multiselector and pass list column names as arguments for options list
                    columns_names = pd_dataframe.columns.to_list()
                    # feature_selected=st.multiselect("choose a feature from the following list to show more results:".upper(),columns_names)

                    #make a new list after getting values from the columns selected above
                    new_column_dataframe = pd_dataframe[columns_names]

                    #show dataframe in webapp
                    # st.dataframe(new_column_dataframe)
                    # st.dataframe(pd_dataframe[feature_selected])

                    #make an area chart using list values from above
                    st.subheader(
                        "showing a frequency graph of all the columns in the dataframe"
                        .upper())

                    st.area_chart(new_column_dataframe)
                    # st.area_chart(pd_dataframe[feature_selected])

#  ******************************bug portion 1 ending*****************************************
#  ******************************bug portion 2 starts*****************************************
                elif activity_selected == "2.Check-Prediction":

                    #show a subheader with text
                    st.subheader(
                        "Prediction Analytics, here you can input your dygnostic details to get prediction"
                        .upper())

                    #set range in input box
                    age = st.number_input("age".upper(), 7, 80)

                    #show radio buttons having options given in male_female_dict dictionary above
                    sex = st.radio("sex".upper(),
                                   tuple(male_female_dict.keys()))

                    #show radio buttons having options given in yes_no_dict above
                    steroid = st.radio("Do you take steroid?".upper(),
                                       tuple(yes_no_dict.keys()))

                    #show radio buttons having options given in yes_no_dict above
                    antivirals = st.radio("Do you take Antivirals?".upper(),
                                          tuple(yes_no_dict.keys()))

                    #show radio buttons having options given in yes_no_dict above
                    fatigue = st.radio("Do you have fatigue?".upper(),
                                       tuple(yes_no_dict.keys()))

                    #show radio buttons having options given in yes_no_dict above
                    spiders = st.radio("Presence of spider naevi".upper(),
                                       tuple(yes_no_dict.keys()))

                    #show select box having options given in yes_no_dict above
                    ascites = st.selectbox("Ascites".upper(),
                                           tuple(yes_no_dict.keys()))

                    #show select box having options given in yes_no_dict above
                    varices = st.selectbox("presence of varices".upper(),
                                           tuple(yes_no_dict.keys()))

                    #show range input
                    bilirubin = st.number_input("bilirubin content".upper(),
                                                0.0, 8.0)

                    #show range input
                    alk_phosphate = st.number_input(
                        "alkaline phosphate content".upper(), 0.0, 296.0)

                    #show range input
                    sgot = st.number_input("Sgot".upper(), 0.0, 648.0)

                    #show range input
                    albumin = st.number_input("albumin".upper(), 0.0, 6.4)

                    #show range input
                    Prothrombin = st.number_input("Prothrombin".upper(), 0.0,
                                                  100.0)

                    #show select box having options given in yes_no_dict
                    histology = st.selectbox("Histology".upper(),
                                             tuple(yes_no_dict.keys()))

                    #making a list of features using functions
                    st.subheader(
                        "showing list of values returned from above input form"
                        .upper())
                    feature_list = [
                        age,
                        get_sex_value(sex),
                        get_yes_no_value(steroid),
                        get_yes_no_value(antivirals),
                        get_yes_no_value(fatigue),
                        get_yes_no_value(spiders),
                        get_yes_no_value(ascites),
                        get_yes_no_value(varices), bilirubin, alk_phosphate,
                        sgot, albumin,
                        int(Prothrombin),
                        get_yes_no_value(histology)
                    ]
                    st.write(feature_list)

                    #dictionary of list
                    st.subheader(
                        "showing in json format after conversion from dictionary"
                        .upper())
                    st.json({
                        "age": age,
                        "sex": sex,
                        "steroid": steroid,
                        "antivirals": antivirals,
                        "spiders": spiders,
                        "ascites": ascites,
                        "varices": varices,
                        "bilirubin": bilirubin,
                        "alk_phosphate": alk_phosphate,
                        "sgot": sgot,
                        "albumin": albumin,
                        "Prothrombin": Prothrombin,
                        "histology": histology
                    })

                    #convert into numpy array and show in webapp
                    st.subheader("After converting into numpy array:".upper())
                    single_sample = np.array(feature_list).reshape(1, -1)
                    st.write(single_sample)

                    #make a selectbox carring options given below
                    model_choice = st.selectbox("select model",
                                                ["LR", "KNN", "DecisionTree"])

                    #make button and it returns true when clicked
                    if st.button("predict"):

                        #work if model is KNN
                        if model_choice == "KNN":

                            #load model file from models folder
                            loaded_model_ML = loading_ML_model(
                                "./models/knn_hepB_model.pkl")

                            #predict from loaded model and store
                            prediction = loaded_model_ML.predict(single_sample)

                            #predict probability from loaded model and store
                            pred_prob = loaded_model_ML.predict_proba(
                                single_sample)

                        #work if model is DecisionTree
                        elif model_choice == "DecisionTree":

                            loaded_model_ML = loading_ML_model(
                                "models/decision_tree_clf_hepB_model.pkl")

                            prediction = loaded_model_ML.predict(single_sample)

                            pred_prob = loaded_model_ML.predict_proba(
                                single_sample)

                        #work if model is LR
                        else:

                            loaded_model_ML = loading_ML_model(
                                "models/logistic_regression_hepB_model.pkl")

                            prediction = loaded_model_ML.predict(single_sample)

                            pred_prob = loaded_model_ML.predict_proba(
                                single_sample)

                        #if prediction came from above is 1 then patient dies
                        if prediction == 1:

                            #show warning message
                            st.warning("Patient dies".upper())

                        else:

                            #show success message
                            st.success("Patient lives".upper())

                            #make a dictionary to store percentage of living or die
                            pred_probability_score = {
                                "Die": pred_prob[0][0] * 100,
                                "Live": pred_prob[0][1] * 100
                            }

                            #show a subheader
                            st.subheader(
                                "Prediction probability score using {}".upper(
                                ).format(model_choice))

                            #show json format in webapp
                            st.json(pred_probability_score)

                        if st.checkbox("Interpret".upper()):
                            if model_choice == "KNN":
                                loaded_model_ML = loading_ML_model(
                                    "models/knn_hepB_model.pkl")

                            elif model_choice == "DecisionTree":
                                loaded_model_ML = loading_ML_model(
                                    "models/decision_tree_clf_hepB_model.pkl")

                            else:
                                loaded_model_ML = loading_ML_model(
                                    "models/logistic_regression_hepB_model.pkl"
                                )

                            # loaded_model_ML = loading_ML_model("models/logistic_regression_model.pkl")
                            # 1 Die and 2 Live
                            df = pd.read_csv(
                                "data/clean_hepatitis_dataset.csv")
                            x = df[[
                                'age', 'sex', 'steroid', 'antivirals',
                                'fatigue', 'spiders', 'ascites', 'varices',
                                'bilirubin', 'alk_phosphate', 'sgot',
                                'albumin', 'protime', 'histology'
                            ]]
                            feature_names = [
                                'age', 'sex', 'steroid', 'antivirals',
                                'fatigue', 'spiders', 'ascites', 'varices',
                                'bilirubin', 'alk_phosphate', 'sgot',
                                'albumin', 'protime', 'histology'
                            ]
                            class_names = ['Die(1)', 'Live(2)']
                            explainer = lime.lime_tabular.LimeTabularExplainer(
                                x.values,
                                feature_names=feature_names,
                                class_names=class_names,
                                discretize_continuous=True)
                            # The Explainer Instance
                            exp = explainer.explain_instance(
                                np.array(feature_list),
                                loaded_model_ML.predict_proba,
                                num_features=13,
                                top_labels=1)
                            exp.show_in_notebook(show_table=True,
                                                 show_all=False)
                            # exp.save_to_file('lime_oi.html')
                            st.write(exp.as_list())
                            new_exp = exp.as_list()
                            label_limits = [i[0] for i in new_exp]
                            # st.write(label_limits)
                            label_scores = [i[1] for i in new_exp]
                            plt.barh(label_limits, label_scores)
                            st.pyplot()
                            plt.figure(figsize=(20, 10))
                            fig = exp.as_pyplot_figure()
                            st.pyplot()
                        else:
                            st.warning("some error takes place".upper())

                else:
                    st.warning("some error takes place".upper())

            else:

                #set warning message with text
                st.warning("Incorrect username/Password".upper())

        else:
            st.warning(
                "either you did not login to the system or you did not sign up yet"
                .upper())

#    ********************************bug 2 ending*******************************************

    elif menu_selected == "4.Sign-up-Form":

        #get username from input box
        new_username = st.text_input("username".upper())

        #get password from input box
        new_password = st.text_input("password".upper(), type='password')

        #get confirm password from input box
        confirm_password = st.text_input("confirm password".upper(),
                                         type='password')

        #if password and confirm password same
        if new_password == confirm_password and new_password != '' and confirm_password != '':

            #show success message if both password same
            st.success("password completely matched".upper())

        elif new_password == '' or confirm_password == '':

            #show warning message if password not matched
            st.warning(
                "either password box or confirm password box is empty, please fill before going ahead"
                .upper())

        else:

            #show warning message if password not matched
            st.warning("password and confirm password did not matched".upper())

        #show submit button
        if st.button("Sign up".upper()):

            #cal function in manage_db file
            create_table_db()

            #call generate hashes function and return hashed password
            hashed_new_password = generate_hash_passwords(new_password)

            #call adduserdata function in manage_db file
            warning_if_any = add_user_db(new_username, hashed_new_password)

            if warning_if_any:
                st.warning(warning_if_any.upper())

            else:
                #show success message
                st.success("new account has been created".upper())

                #show info message
                st.info(
                    "please choose login-form option from sidebar to login and start your session"
                    .upper())

        else:
            st.warning(
                "either you did not click sign up button or some failure occurs"
                .upper())

    else:
        st.warning("wrong choice, please choose again".upper())
Ejemplo n.º 12
0
def run_app():
    # GUI
    epoch_loc = st.empty()
    prog_bar = st.empty()
    loss_loc = st.empty()
    global_loss_loc = st.empty()
    col1, col2 = st.beta_columns(2)
    img_loc = col1.empty()
    stats_loc = col2.empty()
    image_meta_loc = st.empty()
    right_chart = st.empty()
    loss_chart = st.empty()
    glob_loss_chart = st.empty()
    # right_chart = st.empty()
    test_progress_bar = st.empty()
    testing_chart = st.empty()
    test_stats = st.empty()

    cuda = torch.device('cuda')
    cpu = torch.device('cpu')
    net = Net()
    net.to(cuda)

    criterion = nn.CrossEntropyLoss()
    # criterion = nn.MSELoss()
    #optimizer = optim.AdamW(net.parameters(), lr=0.01)
    optimizer = optim.AdamW(net.parameters(), lr=0.001)

    dataset = EegDataset()

    EPOCHS = 200
    losses = deque(maxlen=100)
    global_losses = deque(maxlen=100)
    right_list = deque(maxlen=100)
    wrong_list = deque(maxlen=100)
    # st.write(list(dataset))
    for epoch in range(EPOCHS):
        i = 1
        epoch_loc.write(f"EPOCH:\t{epoch}/{EPOCHS-1}")
        global_loss = torch.tensor([0.0], device=cuda)
        optimizer.zero_grad()
        right = 0
        wrong = 0
        for image in dataset:
            # sleep(1)
            prog_bar.progress(i / len(dataset))
            i += 1
            optimizer.zero_grad()
            x = image.data
            img_loc.image(image.data.numpy(), width=200)
            image_meta_loc.write(f"ID:\t{image.id}  \nCategory:\t{image.category}")

            # out = net(x.cuda().float())#.unsqueeze(0)
            out = net(x.cuda().float()).unsqueeze(0)

            out_id = torch.argmax(out.detach().cpu(), 1)
            target_id = dataset.categories.index(image.category)
            target = torch.zeros(len(dataset.categories)).float()
            target[target_id] = 1.0

            target = target.cuda()
            # target = torch.tensor([dataset.categories.index(image.category)]).cuda()
            # stats_loc.write(f"OUTPUT:\t{torch.argmax(out.detach().cpu(), 1)}  \nTARGET:\t{target.detach().cpu()}")
            stats_loc.write(f"OUTPUT:\t{out_id}  \nTARGET:\t{target_id}")

            # out = torch.round(out)
            # target = torch.round(target)
            # loss = criterion(out, target)
            loss = criterion(out, torch.tensor([target_id]).cuda())

            if out_id == target_id:
                right += 1
                loss = loss * (1 / len(dataset))
            else:
                wrong += 1
                loss = loss * 1

            losses.append(loss.detach().cpu().numpy())
            loss_chart.line_chart(
                pd.DataFrame(losses, columns=['loss',])
            )
            global_loss += loss
            loss.backward()
            optimizer.step()
            loss_loc.write(f"LOSS:\t{loss.detach().cpu()}  \nRIGHT:\t{right}/{len(dataset)}  \nWRONG:\t{wrong}/{len(dataset)}")
            # print(loss)
        right_list.append(right)
        wrong_list.append(wrong)
        rc_data = pd.DataFrame(np.array([[r,w] for r,w in zip(right_list, wrong_list)]), columns=['right', 'wrong'])
        right_chart.line_chart(rc_data)
        # wc_data = pd.DataFrame(np.array(wrong_list), columns=['wrong',])
        global_loss_loc.write(f"GLOBAL LOSS:\t{global_loss.detach().cpu()}  \nGLOB AVERAGE LOSS:\t{global_loss.detach().cpu()/len(dataset)}")
        global_losses.append(global_loss.detach().cpu().numpy())
        glob_loss_chart.line_chart(
            pd.DataFrame(global_losses, columns=['global_loss', ])
        )
        # global_loss.backward()
        # optimizer.step()

    # TESTING PHASE:
    dataset = EegDataset(testing=True)
    right = 0
    wrong = 0
    st.write('TESTING!!!!!!!!!!!!!!!!!!!/EVALUATING????')
    i = 1
    with torch.no_grad():
        for image in dataset:
            test_progress_bar.progress(i / len(dataset))
            i += 1
            x = image.data
            out = net(x.cuda().float())
            out_id = torch.argmax(out.detach().cpu(), 0)
            target_id = dataset.categories.index(image.category)
            if out_id == target_id:
                right += 1
            else:
                wrong += 1
            # chart_data = pd.DataFrame(np.array([[right, wrong]]), columns=['right', wrong])
            # testing_chart.bar_chart(chart_data)
            test_stats.write(f'RIGHT: {right}/{len(dataset)}  \nWRONG: {wrong}/{len(dataset)}')
def app():
    st.balloons()
    
    st.markdown("# Visualizations :art:")

    menu = ["Number of Tweets per Day", "Number of Retweets per Day", 
    "Number of Likes per Day", "Most Common Tweets", "Sentiment Scores", "Common Entities"]
    choice = st.selectbox("View", menu)

    if choice == "Number of Retweets per Day":
        fig1 = px.histogram(covid_data, x="datetime", color="retweets", title="Number of Retweets Per Day")
        st.write(fig1)


    elif choice == "Number of Likes per Day":
        fig2 = px.histogram(covid_data, x="datetime", color="likes" ,title="Likes Per Day")
        st.write(fig2)


    elif choice == "Most Common Tweets":
        st.write("Word Cloud for Most Common Tweets")
        stop_words = get_stop_words('english')
        concat_quotes = ' '.join(
            [i for i in covid_data.text_without_stopwords.astype(str)])
        #print(concat_quotes[:10])
        stylecloud.gen_stylecloud(  text=concat_quotes,
                                    icon_name='fab fa-twitter',
                                    palette='cartocolors.qualitative.Bold_9',
                                    background_color='white',
                                    output_name='tweets.png',
                                    collocations=False,
                                    custom_stopwords=stop_words )

        #Displaying image from a file
        Image(filename="tweets.png", width=780, height=780)
        st.image("tweets.png")

        #Display the most common words after stemming
        #
        #Create separate columns
        table_col, input_col = st.beta_columns([3,2])

        covid_data['text_stem'] = covid_data['text_stem'].apply(lambda x:str(x).split()) #Use tokenize or split, smae results
        top = Counter([item for sublist in covid_data['text_stem'] for item in sublist]) #Counts the frequency of words

        with input_col:
            top_n = st.slider("How many of the common words do you want to see?", 0, 5, 10)
            temp = pd.DataFrame(top.most_common(top_n))
            temp.columns = ['common_words', 'count']
            #temp = temp.reset_index()

        with table_col:
            fig = px.pie(temp, values='count', names='common_words',
                         title='Top Common Words',
                         hover_data=['common_words'], color_discrete_sequence=px.colors.qualitative.G10)
            fig.update_layout(showlegend=False, width=450, height=450)
            st.write(fig)
            # colorscale = [[0, '#4d004c'], [.5, '#f2e5ff'], [1, '#ffffff']]
            # fig = ff.create_table(temp, height_constant=15, colorscale=colorscale)
            # st.write(fig)
        #st.write(temp.style.background_gradient(cmap = 'Blues'))
        
    elif choice == "Sentiment Scores":
        pie_col, input_col = st.beta_columns([3,2])
       #Convert the text_stem column to string type. nrclext only takes input of type str
        covid_data['text_stem'] = covid_data['text_stem'].astype(str)
        #Create a text object
        text_object = NRCLex(' '.join(covid_data['text_stem']))

        #Create a list from the  text object
        sentiment_scores = pd.DataFrame(list(text_object.raw_emotion_scores.items())) 
        #Create a dataframe of two columns
        sentiment_scores = sentiment_scores.rename(columns={0: "Sentiment", 1: "Count"})
        with input_col:
            num_n = st.slider("Change Pie Chart Values Here", 0, 5, 10)
            sentiment_scores = sentiment_scores.head(num_n)

            btn = st.button("Show Table")
            colorscale = [[0, '#272D31'], [.5, '#ffffff'], [1, '#ffffff']]
            font=['#FCFCFC', '#00EE00', '#008B00']
            if btn:
                fig =  ff.create_table(sentiment_scores, colorscale=colorscale,
                font_colors=font)
                st.write(fig)
        
        with pie_col:
            fig = px.pie(sentiment_scores, values='Count', names='Sentiment',
            title='Top Emotional Affects',
            hover_data=['Sentiment'], color_discrete_sequence=px.colors.qualitative.Dark24)
            fig.update_traces(textposition='inside', textinfo='percent+label')

            fig.update_layout(showlegend = False, width = 450, height = 450,
            font=dict(color='#383635', size=15)
            )

            st.write(fig)

        #Create a dataframe with a dictionary of the sentiments
        st.title("Table Showing Words & Sentiments")

        sentiment_words = pd.DataFrame(list(text_object.affect_dict.items()),columns = ['words','sentiments'])

        num_o = st.slider("Change table size", 0, 50, 100)
        sentiment_words = sentiment_words.head(num_o)
        
        fig = go.Figure(data=[go.Table(columnwidth=[1, 2], header=dict(values=
        list(sentiment_words[['words', 'sentiments']].columns),
            fill_color='maroon',
        align=['left', 'center'], height=40, font=dict(color='white', size=18)),

        cells=dict(values=[sentiment_words.words, sentiment_words.sentiments],
        fill_color='lightseagreen',
        align='left'))
        ])

        fig.update_layout(margin=dict(l=5, r=5, b=10, t=10))
        st.write(fig)

    elif choice == "Common Entities":
        st.write("Word Cloud for Most Common Entities")

        # remove duplicate claims (Not really needed since dropped already)
        words = covid_data.text_stem.unique()
        # NER list we'll use - Perhaps could be expanded?
        nlp = en_core_web_sm.load()
        #nlp = spacy.load(en_core_web_sm)
        corpus = list(nlp.pipe(words[:700]))
        all_ents = defaultdict(int)
        for i, doc in enumerate(corpus):
            #print(i,doc)
            for ent in doc.ents:
                all_ents[str(ent)] += 1
        sorted_ents = pd.DataFrame(sorted(all_ents.items(), key=operator.itemgetter(1), reverse=True),columns = ['entities','count'])

        stop_words = get_stop_words('english')
        hashtags = sorted_ents['entities'].dropna().tolist()
        unique_entities=(" ").join(hashtags)
        # concat_quotes = ' '.join(
        #     [i for i in sorted_ents.entities.astype(str)])
        # #print(concat_quotes[:10])
        stylecloud.gen_stylecloud(  text=unique_entities,
                                    #file_path='concat_quotes',
                                    icon_name='fas fa-comments',
                                    palette='cartocolors.qualitative.Prism_8',
                                    background_color='white',
                                    output_name='entities.png',
                                    collocations=False,
                                    custom_stopwords=stop_words )
        
        #Displaying image from a file
        Image(filename="entities.png", width=780, height=780)
        st.image("entities.png")

    else:
        fig3 = px.histogram(covid_data, x="datetime", title="Number of Tweets Per Day")
        st.write(fig3)
    columns=['Initial', 'Final cum', 'Final net', 'Minimum', 'Maximum'],
    index=['Capital'])
my_t1.loc['Capital'] = [a0, a1, a2, a3, a4]
st.table(my_t1.style.applymap(color_change))

net_profit_prc = (df_mc['original'].sum() + guarantee) / guarantee
b0 = f'{net_profit_prc*100:10.2f}%'
annual_profit_prc = (
    (df_mc['original'].sum() + guarantee) / guarantee)**(1 / time) - 1
b1 = f'{annual_profit_prc*100:10.2f}%'

max_drawdown, max_drawdown_pct = max_dd(my_guarantee, my_result)
c0 = f'{max_drawdown:10.2f}$'
c1 = f'{max_drawdown_pct*100:10.2f}%'

mycol01, mycol02 = st.beta_columns([1, 1])

with mycol01:
    my_t2 = pd.DataFrame(columns=['Total Net', 'Total Annual'])
    my_t2.loc['Profit'] = [b0, b1]
    st.table(my_t2.style.applymap(color_change))

with mycol02:
    my_t3 = pd.DataFrame(columns=['Amount', 'Percentage'])
    my_t3.loc['Max Drawdown'] = [c0, c1]
    st.table(my_t3.style.applymap(color_change))

sharpe = my_result.cumsum().diff().mean() / my_result.cumsum().diff().std(
) * np.sqrt(252)
d0 = f'{sharpe:10.2f}'
recovery_factor = my_result.sum() / max_drawdown
Ejemplo n.º 15
0
                                         date=date_required)
else:
    st.write("Esperando por BD")

if daily_report and bd_ht:
    st.subheader('Reporte filtrado')
    st.markdown(
        'De acuerdo a la seleccion de filtros de Cargo y Servicio, tenemos los siguientes ejecutivos a formar parte del analisis de horas log diarias'
    )
    df_filter = df_report[df_report['users'].isin(df_bd_filter['Usuario Red'])]
    st.write(df_filter)

    df, sf, hf = def_cal.horas_log(df_filter)

    with st.beta_expander('Mostrar desglose...'):
        col1, col2 = st.beta_columns([3, 1])

        col1.subheader('Línea tiempo Requerido')
        col1.line_chart(hf)

        col2.subheader('Horas Log')
        col2.write(df)

    #Considerar st.area_chart, para evaluar el requerido junto a las horas log

    df_merge = df_filter.merge(df_bd_filter,
                               how='left',
                               left_on='users',
                               right_on='Usuario Red')
    df_merge_group = df_merge.groupby(
        by=['users', 'Jornada'])['Active Time'].agg([
Ejemplo n.º 16
0
                                                minNeighbors=minNeighbors)
    return face_boxes


face_boxes = detetct_faces(img)

# drawing bounding boxes
for face_box in face_boxes:
    x, y, width, height = face_box
    cv.rectangle(img=img,
                 pt1=(x, y),
                 pt2=(x + width, y + height),
                 color=(0, 255, 0),
                 thickness=2)

st.image(img, channels='BGR')

# crop faces
faces = []

for face_box in face_boxes:
    x, y, w, h = face_box
    face = img_copy[y:y + h, x:x + w]
    faces.append(face)

st.subheader('Faces Detected')
columns = st.beta_columns(5)

for i, face in enumerate(faces):
    with columns[i % 5]:
        st.image(face, channels='BGR')
customContainer = st.beta_container()

# Inside
customContainer.write("This is inside the container")

# Outside
st.write("This is outside the container")

# Outisde
st.subheader("Outside Custom Container")

# Inside
customContainer.write("This is inside too")

# Columns -> Streamlit Docs
col1, col2, col3 = st.beta_columns(3)

with col1:
    st.header("A cat")
    st.image("https://static.streamlit.io/examples/cat.jpg")

with col2:
    st.header("A dog")
    st.image("https://static.streamlit.io/examples/dog.jpg")

with col3:
    st.header("An owl")
    st.image("https://static.streamlit.io/examples/owl.jpg")

# Code Display
st.subheader("Code Display")
Ejemplo n.º 18
0
# HEADER
######################################################################

with header_container:
    st.markdown("<h1 style='text-align: center'>TT Analytics Dashboard</h1>",
                unsafe_allow_html=True)
    st.write("***")
    st.markdown("<h2 style='text-align: center'>Leaderboard</h2>",
                unsafe_allow_html=True)

######################################################################
# LEADERBOARD
######################################################################

with leaderboard_container:
    lbCol1, lbCol2 = st.beta_columns(2)

    # display leaderboard
    with lbCol1:
        # read csv
        # make a copy of the dataframe as df
        athlete_data = pd.read_csv('player_stats.csv')
        df = athlete_data.copy()

        # grab Player and Wins columns, rename,
        # remove index and convert win ratio to percent
        dfLeaderBoard = df[['Rank', 'Player', 'Win %']]
        # dfLeaderBoard.columns = ['Rank', 'Player', 'Win %']
        dfLeaderBoard.index = [""] * len(dfLeaderBoard)
        dfLeaderBoard['Win %'] = (dfLeaderBoard['Win %'] *
                                  100).astype(str) + "%"
Ejemplo n.º 19
0
    'state_name': 'State',
    'district_name': 'District',
    'block_name': 'Block Name',
    'fee_type': 'Fees'
}

st.title('Manasa says lets get vaccinated!')
st.info(
    'The CoWIN APIs are geo-fenced so sometimes you may not see an output! Please try after sometime '
)

# numdays = st.sidebar.slider('Select Date Range', 0, 100, 10)
unique_districts = list(mapping_df["district name"].unique())
unique_districts.sort()

left_column_1, right_column_1 = st.beta_columns(2)
with left_column_1:
    numdays = st.slider('Select Date Range', 0, 100, 5)

with right_column_1:
    default_dist = unique_districts.index('BBMP')
    dist_inp = st.selectbox('Select District',
                            unique_districts,
                            index=default_dist)

DIST_ID = mapping_dict[dist_inp]

base = datetime.datetime.today()
date_list = [base + datetime.timedelta(days=x) for x in range(numdays)]
date_str = [x.strftime("%d-%m-%Y") for x in date_list]
Ejemplo n.º 20
0
def run(st,data,mongocls,session_id):
    st.markdown("### Steps -")

    view_sample_data = st.checkbox("View Sample Data - ")
    if view_sample_data:

        if mongocls.get_session_info({'session_id': session_id + '_ml_df'}) is not None:
            st.dataframe(pd.DataFrame(mongocls.get_session_info({'session_id':session_id+'_ml_df'})["data_dict"]).head())
        else:
            st.dataframe(data.head())

    c_load,c_session,c_restrict_columns = st.beta_columns(3)
    if c_load.button("Reload Data!!!"):
        data = get_data(data,mongocls,session_id)


    if c_session.button("Reset Session!!!"):
        mongocls.delete_session({'session_id': session_id + '_ml_df'})

    if c_restrict_columns.checkbox("Restrict Columns: "):
        restrict_columns = st.multiselect("Restrict Columns ", data.columns.tolist())
        data = data[restrict_columns]

    expander = st.beta_expander("Data Preparation:",expanded=False)


    data = get_data(data,mongocls,session_id)
    columns = data.columns.tolist()
    with expander:
            c1,c2,c3 = st.beta_columns(3)
            fs = c1.checkbox("Feature Selection")
            if fs:
                st.text("Currently under development!!!")
                #fs_option = st.selectbox("Selection Option",['SelectKBest','RFE','PCA','LDA'])

            dimpute = c2.checkbox("Data Imputers")
            if dimpute:
                impute_options = st.selectbox("Impute Option",['SimpleImputer'])
                if impute_options:

                    imputer = dp.Imputers(dataframe=data,select_imputer=impute_options)
                    imputer.select_imputers(imputerSelect = impute_options)
                    data = imputer.fit_transform()
                    data = pd.DataFrame(data, columns=columns)
                    mongocls.delete_session({'session_id': session_id + '_ml_df'})
                    mongocls.write_session_info(
                        {'session_id': session_id + '_ml_df', 'data_dict': data.to_dict("records")})
                    st.dataframe(data.head())
    expander_enc = st.beta_expander("Data Encoding", expanded=False)
    with expander_enc:
        encode = st.checkbox("Apply Encoding")
        if encode:
            c1_encode,c2_encode,c3_encode = st.beta_columns(3)
            encoding_option = c1_encode.selectbox("Select Encoder",['LabelEncoder','OneHotEncoder','OrdinalEncoder','Binarizer','LabelBinarizer','MultiLabelBinarizer'])
            Y_col_encode = c2_encode.selectbox("Select Y (target) (Encoding)", data.columns.tolist())
            cat_columns =  c3_encode.multiselect("Select Categorical Columns to Encode",data.columns.tolist())
            encode_btn = st.button("Encode Data!!!")
            if encode_btn:
                if len(cat_columns)==0:
                    encode_cls = dp.Encoders(df=data,y=Y_col_encode)
                else:
                    encode_cls = dp.Encoders(df=data,y=Y_col_encode, cat_columns = cat_columns)
                encode_cls.select_encoder(encode_type=encoding_option)
                data = encode_cls.compile_encoding()
                st.dataframe(data.head())
                mongocls.delete_session({'session_id': session_id + '_ml_df'})
                mongocls.write_session_info(
                    {'session_id': session_id + '_ml_df', 'data_dict': data.to_dict("records")})

    expander_sample = st.beta_expander("Data Sampling", expanded=False)
    with expander_sample:
        c1, c2, c3, c4 = st.beta_columns(4)
        sample_options = c1.selectbox("Sampling Options", ["Over", "Under","RandomOverSampler"])
        sampling_ratio = c2.slider('Sampling Ratio', min_value=0.1, max_value=1.0, step=0.05)
        Y_col = c3.selectbox("Select Y (target) (Sampling)", data.columns.tolist())
        if Y_col != '':
            X_cols = c4.multiselect("Select X Columns (default is all)",
                                    [col for col in data.columns.tolist() if col != Y_col])
            if len(X_cols) <= 0:
                X_cols = [col for col in data.columns.tolist() if col != Y_col]
                X_val = data[X_cols]

            X_val = data[X_cols]
            Y_val = data[Y_col]
        else:
            st.warning("Please select Target column!!!")
        sampler_btn = st.button("Run Sampler")
        if sampler_btn:
            sample_cls = dp.Sampling(df=data[X_cols + [Y_col]], target=Y_col, sampling_option=sample_options)
            X_val, Y_val = sample_cls.run_sampler()
            data = (pd.concat([X_val, Y_val], axis=1))
            st.dataframe(data.head())
            mongocls.delete_session({'session_id': session_id + '_ml_df'})
            mongocls.write_session_info(
                {'session_id': session_id + '_ml_df', 'data_dict': data.to_dict("records")})

    expander_scale = st.beta_expander("Data Scaling", expanded=False)
    with expander_scale:
        scale = st.checkbox("Apply Scaling")
        if scale:
            c1, c2, c3 = st.beta_columns(3)
            scaling_options = c1.selectbox("Sampling Options", ["StandardScaler", "MaxAbsScaler", "MinMaxScaler","RobustScaler",
                                                                "Normalizer","PowerTransformer","QuantileTransformer"])
            Y_col = c2.selectbox("Select Y (target) (Scaling)", data.columns.tolist())
            cat_columns = c3.multiselect("Categorical Columns",[col for col in data.columns.tolist() if col != Y_col])
            scale_btn = expander_scale.button("Scale Data!!!")
            if scale_btn:
                scaling = dp.scaling(df=data,cat_columns=cat_columns,scalar_type=scaling_options,y=Y_col)
                data = scaling.compile_scalar()
                st.dataframe(data.head())
                mongocls.delete_session({'session_id': session_id + '_ml_df'})
                mongocls.write_session_info(
                    {'session_id': session_id + '_ml_df', 'data_dict': data.to_dict("records")})
                pass

    expander_model = st.beta_expander("Model Training", expanded=False)
    with expander_model:
        c1,c2,c3 =  st.beta_columns(3)
        model_type = c1.selectbox("Model Type",['Regression','Classification'])
        y_col = c2.selectbox("Select Target Variable",data.columns.tolist())
        model_exe = ml_models.MLmodels(df=data,y_column=y_col,problem_type=model_type)
        select_models = c3.multiselect("Select ML models",model_exe.get_model_list())
        run_models = st.button("Run Models - ")
        model_storage = {}
        if run_models:
            for model in select_models:
                model_exe.select_model_to_run(model_select=model)
                model_storage[model]= model_exe.compile_modeling()
                train_x, train_y, test_x, test_y = model_exe.get_train_test()
            mongocls.delete_session({'session_id': session_id + '_models_ran'})
            mongocls.write_session_info(
                {'session_id': session_id + '_models_ran','models_trained': pickle.dumps(model_storage),'train_test_data':pickle.dumps(
                    {
                        'train_x':train_x,
                        'train_y':train_y,
                        'test_x':test_x,
                        'test_y':test_y
                    }
                )})
        if len(model_storage.keys())>0:
            st.write("Model Run completed for the below models - ")
            st.code(model_storage)

    expander_metrics = st.beta_expander("Evaluation Metrics", expanded=False)
    with expander_metrics:
        #try:
            models_trained = pickle.loads(mongocls.get_session_info({'session_id': session_id + '_models_ran'})["models_trained"])
            loaded_info = pickle.loads(mongocls.get_session_info({'session_id': session_id + '_models_ran'})["train_test_data"])
            train_x = loaded_info['train_x']
            train_y = loaded_info['train_y']
            test_x = loaded_info['test_x']
            test_y = loaded_info['test_y']
            metric_selected = {}
            for model,trained_model in models_trained.items():
                st.text(model)
                metric_cls = ml_metrics.Metrics(y_test=test_y)
                metric_selected[model] = st.multiselect('Select Metrics to see for the Model ('+model+')',metric_cls.get_metric_list())
            metrics_btn = st.button("Click to see the metrics")
            if metrics_btn:
                for model,metrics in metric_selected.items():
                    for metric in metrics:
                        metric_cls.select_metrics(metric)
                        st.write(metric)
                        st.write(metric_cls.metrics_solve(estimator=models_trained[model], test_x=test_x))

        #except:
        #    st.warning("No Models trained yet!!!")
Ejemplo n.º 21
0
        Multi custom layer neural network
    """
    def __init__(self, input_size, output_size):
        super().__init__()
        self.layer1 = Mem(input_size, 10)
        self.layer2 = Mem(10, 10)
        self.layer3 = Mem(10, output_size)

    def forward(self, x):
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        return x


placeholders_ = [[col.empty() for col in st.beta_columns(1)] for x in range(5)]
placeholders = [[col.empty() for col in st.beta_columns(1)] for x in range(5)]
net = Net(12, 12)
optimizer = AdamW(net.parameters(), lr=0.001)
criterion = nn.MSELoss()

x_ = [
    torch.tensor([
        [0, 1, 0, 0],
        [1, 1, 1, 1],
        [0, 1, 0, 0],
    ], dtype=float),
    torch.tensor([
        [0, 0, 1, 0],
        [1, 1, 1, 1],
        [0, 0, 1, 0],
Ejemplo n.º 22
0
def main():
    view = st.sidebar.selectbox("Choose Report:",
                                ["Monthly Segments", "Daily Pickup", "Matrix"])

    actuals, current_df, yesterday_df, past_df = get_data()

    st.header('Arlo Hotels')
    if view == 'Daily Pickup':
        st.write('Select Data:')
        col1, col2 = st.beta_columns(2)
        with col1:
            st.date_input('As of:', value=pd.to_datetime('11/30/20'))
            year = st.selectbox('Year:', [2019, 2020, 2021], index=2)
        with col2:
            length = st.selectbox('Pickup Length:', [1, 7])
            month = MONTHS[st.selectbox('Month:',
                                        list(MONTHS.keys()),
                                        index=TODAY.month - 6)]

        if length == 1:
            pickup_df = create_pickup(current_df, yesterday_df)
        if length == 7:
            pickup_df = create_pickup(current_df, past_df)

        current_year = pickup_df[pickup_df.Date.dt.year == year]
        current_year = create_month_view(current_year, year)

        st.subheader('Current On The Books by Month')
        st.dataframe(current_year.astype('object'), width=800, height=500)

        day_df = pickup_df[(pickup_df.Date.dt.month == month)
                           & (pickup_df.Date.dt.year == year)]

        st.subheader('Current On The Books by Day')

        day_df = create_day_view(day_df)

        st.dataframe(day_df, width=800, height=800)

    if view == 'Monthly Segments':
        st.write('Select Data:')
        col1, col2 = st.beta_columns(2)
        with col1:
            st.date_input('As of', value=pd.to_datetime('11/30/20'))
            year = st.selectbox('Year', [2019, 2020, 2021], index=2)
        with col2:
            length = st.selectbox('Pickup Length', [1, 7])
            month = MONTHS[st.selectbox('Month',
                                        list(MONTHS.keys()),
                                        index=TODAY.month - 6)]

        st.subheader('Current On The Books by Segment')
        condensed = st.checkbox('Condensed Segment View')

        if length == 1:
            pickup_df = create_pickup(current_df, yesterday_df)
        if length == 7:
            pickup_df = create_pickup(current_df, past_df)

        current_month = pickup_df[(pickup_df.Date.dt.month == month)
                                  & (pickup_df.Date.dt.year == year)]

        if condensed:
            current_month['Code'] = current_month['Code'].map(CONDENSED_SEG)
        else:
            current_month['Code'] = current_month['Code'].map(FULL_SEG)

        current_month = seg_pickup(current_month)

        st.dataframe(current_month)

    if view == 'Matrix':
        st.write('Work in Progress')
        year = st.selectbox('Year', [2019, 2020, 2021], index=2)
        month = MONTHS[st.selectbox('Month',
                                    list(MONTHS.keys()),
                                    index=TODAY.month - 6)]
        data = st.radio('Select View',
                        ('On The Books', '1 Day P/U', '7 Day P/U', 'Pace',
                         'Vs. Budget', 'Vs. Forecast'))
        condensed = st.checkbox('Condensed Segment View')

        if data == '7 Day P/U':
            pickup_df = create_pickup(current_df, past_df)
        else:
            pickup_df = create_pickup(current_df, yesterday_df)

        current_month = pickup_df[(pickup_df.Date.dt.month == month)
                                  & (pickup_df.Date.dt.year == year)]
        if condensed:
            current_month['Code'] = current_month['Code'].map(CONDENSED_SEG)
        else:
            current_month['Code'] = current_month['Code'].map(FULL_SEG)

        if data == 'On The Books':
            current_month = current_month.groupby(['Code', 'Date'])[[
                'Res', 'Rev'
            ]].sum().unstack().swaplevel(0, 1, axis=1).sort_index(axis=1)
        else:
            current_month = current_month.groupby(['Code', 'Date'])[[
                'Res p/u', 'Rev p/u'
            ]].sum().unstack().swaplevel(0, 1, axis=1).sort_index(axis=1)

        st.dataframe(current_month)
def mostrarPantallaSeleccionEstudios(
        user):  #FALTAN CONDICIONES DE REFERENCIAS Y LOADBEFORE
    if user != "Seleccionar..." and user is not None:
        conectarBd()
        if st.checkbox("Ver avance"):
            mostrarAvance(True)
        if os.path.exists("inclusion"):
            try:
                with open('inclusion', 'r') as fp:
                    paper_dict = json.loads(json.load(fp))
                    paper = Paper.objects.get(doi=paper_dict["_id"])
                    if paper.inclusion1 is None: number = 1
                    else:
                        if paper.user_inclusion1 == user or paper.inclusion2 is not None:
                            os.remove("inclusion")
                            paper, number = elegirPaper(user)
                        with open('inclusion', 'w') as fp:
                            json.dump(paper.to_json(), fp)
                        number = 2
            except:  #el archivo inclusion está corrupto y se debe eliminar
                os.remove("inclusion")
                paper = None
        else:
            paper, number = elegirPaper(user)
            if paper is not None:
                with open('inclusion', 'w') as fp:
                    json.dump(paper.to_json(), fp)
        if paper is None:
            st.error(
                "No existen más papers en la base de datos que usted pueda verificar sin introducir un sesgo en el review."
            )
        else:
            show_warning = False
            if paper.on_revision is not None:
                st.success(
                    "Este paper fue recuperado de una sesión incompleta anterior."
                )  #muestra mensaje de exito
            else:
                show_warning = True
                paper.on_revision = user
                paper.save()
            st.write(
                "Lea el título y abstract del siguiente artículo y marque si cumple alguna de las siguientes condiciones."
            )
            if paper.title is not None:
                st.markdown("#### Título")
                st.write(paper.title)
            if paper.abstract is not None:
                st.markdown("#### Abstract")
                st.write(paper.abstract)
            if paper.doi is not None:
                st.markdown("#### Doi")
                st.markdown("[" + paper.doi + "](https://doi.org/" +
                            paper.doi + ")")
            if st.button("Cambiar paper"):
                del paper.on_revision
                paper.save()
                os.remove("inclusion")
            st.markdown("#### Criterios")
            col1, col2 = st.beta_columns(2)
            with col1:
                st.markdown("##### Inclusión")
                ci1 = st.checkbox(
                    "1. El estudio NO utiliza algún proceso de extracción de información automatizado sobre imágenes de cualquier región del espectro electromagnético en alguna de sus etapas."
                )
                ci2 = st.checkbox(
                    "2. El estudio NO se enfoca en la medición de variables visuales de interés vitícola. Entendemos por esto a toda información necesaria para la toma de decisiones agronómica que se manifiesta de forma visual en alguna parte de la planta de vid."
                )
            with col2:
                st.markdown("##### Exclusión")
                ce1 = st.checkbox(
                    "1.  El estudio utiliza como entrada imágenes satelitales."
                )
                ce2 = st.checkbox(
                    "2.  El algoritmo opera sobre información electromagnética que NO viene en forma de imagen (entiéndase representación visual bidimensional a partir de una matriz numérica)."
                )
                ce3 = st.checkbox(
                    "3.  El paper está orientado a automatismo de la gestión, NO a medición de variables."
                )
                ce4 = st.checkbox("4.  El estudio NO está escrito en Inglés.")
                ce5 = st.checkbox(
                    "5.  La publicación del estudio NO se sometió a un proceso de revisión por pares."
                )
            st.markdown("#### Comentarios")
            comments = st.text_area(
                "En el caso de que tenga alguna duda con la decisión qué tomó, vuelquela en el siguiente apartado para que sea tenida en cuenta en la próxima reunión. (Si no hay texto se asume que se ha tomado la decision con plena confidencia)"
            )  #text area para colocar el comentario
            guardar = st.button("Guardar")
            if show_warning:
                st.warning(
                    "El paper a revisar ha cambiado. \n" +
                    "Desplácese hacia arriba para analizar su contenido. \n" +
                    "Asegúrese de no presionar el botón 'Guardar' hasta modificar los checkboxes de acuerdo a su revisión."
                )
            if guardar:
                del paper.on_revision
                if ci1 or ci2 or ce1 or ce2 or ce3 or ce4 or ce5:
                    criteria = []
                    if ci1: criteria.append("CI1")
                    if ci2: criteria.append("CI2")
                    if ce1: criteria.append("CE1")
                    if ce2: criteria.append("CE2")
                    if ce3: criteria.append("CE3")
                    if ce4: criteria.append("CE4")
                    if ce5: criteria.append("CE5")
                    if number == 1:
                        paper.inclusion1 = False
                        paper.user_inclusion1 = user
                        paper.criteria_inclusion1 = criteria
                        if comments is not None: paper.comments1 = comments
                    if number == 2:
                        paper.inclusion2 = False
                        paper.user_inclusion2 = user
                        paper.criteria_inclusion2 = criteria
                        if comments is not None: paper.comments2 = comments
                    mess = "Se ha guardado su decisión de excluir el artículo " + paper.title + " ya que hay conflictos con los siguientes criterios: "
                    for cr in criteria:
                        mess = mess + "\n " + cr
                    st.success(mess)
                else:
                    if number == 1:
                        paper.inclusion1 = True
                        paper.user_inclusion1 = user
                        if comments is not None: paper.comments1 = comments
                    if number == 2:
                        paper.inclusion2 = True
                        paper.user_inclusion2 = user
                        if comments is not None: paper.comments2 = comments
                    st.success(
                        "Se ha guardado su decisión de incluir el artículo " +
                        paper.title)
                paper.save()
                if st.button("Revisar otro paper"):
                    del paper.on_revision
                    paper.save()
                    os.remove("inclusion")
                st.json(paper.to_json())
#commande pour lancer le truc : streamlit run graph.py

import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
import pydeck as pdk

def load_data(nrows):
    data = pd.read_json("https://api.spacexdata.com/v3/launches")
    data["launch_date_utc"] = pd.to_datetime(data["launch_date_utc"])
    return data

data = load_data(100000)

row1_1, row1_2 = st.beta_columns((3,2))

with row1_1:
    st.title("Choix de l'année")
    YEAR_SELECTED = st.slider("Année", 2006, 2020)

with row1_2:
    st.write(
    """
    ##
    Visualisation des lancements et du nombre de lancement au cours des années
        """)

filtered = data[
    (data["launch_date_utc"].dt.year >= YEAR_SELECTED) & (data["launch_date_utc"].dt.year < (YEAR_SELECTED + 1))
    ]
Ejemplo n.º 25
0
def main():

    menu = [
        "Team", "Lieu d'intérêt", "Evénement", "Produit", "Itinéraire",
        "Maintenance"
    ]
    choice = st.sidebar.radio("Menu", menu)

    if choice == "Team":

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        st.markdown(
            "<h1 style='text-align: center; font-size:15px; color:#A11F40;'>Qu'est ce que DATAtourisme ?</h1>",
            unsafe_allow_html=True)

        st.markdown(
            "<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>",
            unsafe_allow_html=True)

        col1, col2, col3 = st.beta_columns((1, 13, 1))

        with col1:

            st.markdown("")

        with col2:
            st.markdown(
                "DATAtourisme est un dispositif national visant à faciliter l’accès aux données publiques d’information touristique produites à travers les territoires par les offices de tourisme et les comités départements ou régionaux du tourisme. Il se matérialise par une plateforme de collecte, de normalisation et de diffusion de données en open data, directement reliée aux bases de données territoriales, et repose sur l’animation d’une communauté d’utilisateurs. Le dispositif est copiloté par la Direction générale des entreprises et la fédération ADN Tourisme. Les données collectées sont relatives au recensement de l’ensemble des événements et points d’intérêt touristiques de France (musées, monuments, sites naturels, activités, itinéraires, expos et concerts, etc)",
                unsafe_allow_html=True)

        with col3:
            st.markdown("")

        st.markdown(
            "<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>",
            unsafe_allow_html=True)

        st.markdown(
            "<h1 style='text-align: center; font-size:29px; color:#57565B;'></h1>",
            unsafe_allow_html=True)

        if st.button("Team"):
            st.balloons()


#		st.markdown("<h1 style='text-align: center; font-size:29px; color:#57565B;'>Team</h1>", unsafe_allow_html=True)

        col1, col2, col3, col4, col5 = st.beta_columns(5)

        with col1:

            st.image("cm1.jpg", use_column_width=True)
            st.markdown("""**Carla&#8239;Moreno**""")
            st.markdown("""*Scrum Master*""")
            st.markdown(link1, unsafe_allow_html=True)

        with col2:

            st.image("cc.jpg", use_column_width=True)
            st.markdown("""**Corentin&#8239;Guillo**""")
            st.markdown("""*Product Owner*""")
            st.markdown(link4, unsafe_allow_html=True)

        with col3:

            st.image("Yvanne.jpg", use_column_width=True)
            st.markdown("""**Yvanne&#8239;Euchin**""")
            st.markdown("""*Equipe Tech*""")
            st.markdown(link2, unsafe_allow_html=True)

        with col4:
            st.image("md.jpg", use_column_width=True)
            st.markdown("""**Michael&#8239;Desforges**""")
            st.markdown("""*Equipe Tech*""")
            st.markdown(link, unsafe_allow_html=True)

        with col5:
            st.image("ab.jpg", use_column_width=True)
            st.markdown("""**Amar&#8239;Barache**""")
            st.markdown("""*Equipe Tech*""")
            st.markdown(link5, unsafe_allow_html=True)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

        page_bg_img = '''
		<style>
		body {
		background-image: url("https://i.ibb.co/cD9CndX/nuages2.jpg");
		background-size: cover;
		}
		</style>
		'''

        st.markdown(page_bg_img, unsafe_allow_html=True)

    if choice == "Produit":
        data = data1

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        st.markdown(
            "<h1 style='text-align:center; font-size:29px; color: #57565B;'>Produit</h1>",
            unsafe_allow_html=True)

        if st.checkbox('voir dataframe'):
            st.write(data.iloc[0:100, :])

        f" POI : **{len(data1.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

        f" Créateurs de données : **{len(data1.createur_donnée.unique())}**"

        f" Fournisseurs : **{len(data1.fournisseur.unique())}**"

        f" Villes : **{len(data1.ville.unique())}**"

        f" POI avec photo :  **{int(round(data1.photo.sum()/len(data1.photo.index)*100))}%**"

        st.markdown(""" # **Densité de POI** """)

        fig = px.density_mapbox(
            data,
            lat='latitude',
            lon='longitude',
            radius=4,
            center={
                "lat": 46.037763,
                "lon": 4.4
            },
            zoom=4,
            color_continuous_midpoint=5,
            mapbox_style='carto-positron',
            color_continuous_scale=['blue', 'grey', 'darkgrey', 'red', 'red'])
        fig.update_layout(coloraxis_showscale=False,
                          margin=dict(l=0, r=0, b=0, t=0, pad=4))
        fig.update_traces(hoverinfo='skip', hovertemplate=None)
        st.plotly_chart(fig)

        st.markdown("""# **Par départements**""")

        fig = px.choropleth_mapbox(
            data,
            geojson=france_regions_geo,
            color=data.code_departement.value_counts(),
            locations=data.code_departement.value_counts().index.tolist(),
            featureidkey='properties.code',
            opacity=1,
            center={
                "lat": 46.037763,
                "lon": 2.062783
            },
            mapbox_style="carto-positron",
            zoom=4)

        fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
        st.plotly_chart(fig)

        st.markdown(""" # **Répartition des sous-categories** """)

        x = list(
            data.sous_categorie.str.split(
                ',', expand=True).stack().explode().value_counts().drop(
                    "HébergementProduit", axis=0).index)
        y = list(
            data.sous_categorie.str.split(
                ',', expand=True).stack().explode().value_counts().drop(
                    "HébergementProduit", axis=0))
        fig = px.bar(x=x, y=y, color_discrete_sequence=['#A11F40'])
        fig.update_layout(margin={
            "r": 0,
            "t": 0,
            "l": 0,
            "b": 0
        },
                          showlegend=False,
                          yaxis=dict(title=None),
                          xaxis=dict(title=None, type="category"))
        st.plotly_chart(fig)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

    elif choice == "Evénement":
        data = data2

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        st.markdown(
            "<h1 style='text-align:center; font-size:29px; color: #57565B;'>Evénement</h1>",
            unsafe_allow_html=True)

        if st.checkbox('voir dataframe'):
            st.write(data.iloc[0:100, :])

        f" POI : **{len(data2.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

        f" Créateurs de données : **{len(data2.createur_donnée.unique())}**"

        f" Fournisseurs : **{len(data2.fournisseur.unique())}**"

        f" Villes : **{len(data2.ville.unique())}**"

        f" POI avec photo :  **{int(round(data2.photo.sum()/len(data2.photo.index)*100))}%**"

        st.markdown(""" # **Densité de POI** """)

        fig = px.density_mapbox(
            data,
            lat='latitude',
            lon='longitude',
            radius=4,
            center={
                "lat": 46.037763,
                "lon": 4.4
            },
            zoom=4,
            color_continuous_midpoint=5,
            mapbox_style='carto-positron',
            color_continuous_scale=['blue', 'grey', 'darkgrey', 'red', 'red'])
        fig.update_layout(coloraxis_showscale=False,
                          margin=dict(l=0, r=0, b=0, t=0, pad=4))
        fig.update_traces(hoverinfo='skip', hovertemplate=None)
        st.plotly_chart(fig)

        st.markdown("""# **Par départements**""")

        fig = px.choropleth_mapbox(
            data,
            geojson=france_regions_geo,
            color=data.code_departement.value_counts(),
            locations=data.code_departement.value_counts().index.tolist(),
            featureidkey='properties.code',
            opacity=1,
            center={
                "lat": 46.037763,
                "lon": 2.062783
            },
            mapbox_style="carto-positron",
            zoom=4)

        fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
        st.plotly_chart(fig)

        st.markdown(""" # **Répartition des sous-categories** """)

        x = list(
            data.sous_categorie.str.split(
                ', ', expand=True).stack().explode().value_counts().index)
        y = list(
            data.sous_categorie.str.split(
                ', ', expand=True).stack().explode().value_counts())
        fig = px.bar(x=x, y=y, color_discrete_sequence=['#A11F40'])
        fig.update_layout(margin={
            "r": 0,
            "t": 0,
            "l": 0,
            "b": 0
        },
                          showlegend=False,
                          yaxis=dict(title=None),
                          xaxis=dict(title=None, type="category"))
        st.plotly_chart(fig)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

    elif choice == "Lieu d'intérêt":
        data = data3

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        st.markdown(
            "<h1 style='text-align:center; font-size:29px; color: #57565B;'>Lieux d'intérêt</h1>",
            unsafe_allow_html=True)

        if st.checkbox('voir dataframe'):
            st.write(data.iloc[0:100, :])

        f" POI : **{len(data3.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

        f" Créateurs de données : **{len(data3.createur_donnée.unique())}**"

        f" Fournisseurs : **{len(data3.fournisseur.unique())}**"

        f" Villes : **{len(data3.ville.unique())}**"

        f" POI avec photo :  **{int(round(data3.photo.sum()/len(data3.photo.index)*100))}%**"

        st.markdown(""" # **Densité de POI** """)

        fig = px.density_mapbox(
            data,
            lat='latitude',
            lon='longitude',
            radius=4,
            center={
                "lat": 46.037763,
                "lon": 4.4
            },
            zoom=4,
            color_continuous_midpoint=5,
            mapbox_style='carto-positron',
            color_continuous_scale=['blue', 'grey', 'darkgrey', 'red', 'red'])
        fig.update_layout(coloraxis_showscale=False,
                          margin=dict(l=0, r=0, b=0, t=0, pad=4))
        fig.update_traces(hoverinfo='skip', hovertemplate=None)
        st.plotly_chart(fig)

        st.markdown("""# **Par départements**""")

        fig = px.choropleth_mapbox(
            data,
            geojson=france_regions_geo,
            color=data.code_departement.value_counts(),
            locations=data.code_departement.value_counts().index.tolist(),
            featureidkey='properties.code',
            opacity=1,
            center={
                "lat": 46.037763,
                "lon": 2.062783
            },
            mapbox_style="carto-positron",
            zoom=4)

        fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
        st.plotly_chart(fig)

        st.markdown(""" # **Répartition des sous-categories** """)

        x = list(
            data.sous_categorie.str.split(
                ', ', expand=True).stack().explode().value_counts().index)
        y = list(
            data.sous_categorie.str.split(
                ', ', expand=True).stack().explode().value_counts())
        fig = px.bar(x=x, y=y, color_discrete_sequence=['#A11F40'])
        fig.update_layout(margin={
            "r": 0,
            "t": 0,
            "l": 0,
            "b": 0
        },
                          showlegend=False,
                          yaxis=dict(title=None),
                          xaxis=dict(title=None, type="category"))
        st.plotly_chart(fig)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

    elif choice == "Itinéraire":
        data = data4

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        st.markdown(
            "<h1 style='text-align:center; font-size:29px; color: #57565B;'>Itinéraire</h1>",
            unsafe_allow_html=True)

        if st.checkbox('voir dataframe'):
            st.write(data.iloc[0:100, :])

        f" **POI** : **{len(data4.index)}** sur **{len(data1.index)+len(data2.index)+len(data3.index)+len(data4.index)}** au total"

        f" Créateurs de données : **{len(data4.createur_donnée.unique())}**"

        f" Fournisseurs : **{len(data4.fournisseur.unique())}**"

        f" Villes : **{len(data4.ville.unique())}**"

        f" POI avec photo :  **{int(round(data4.photo.sum()/len(data4.photo.index)*100))}%**"

        st.markdown(""" # **Densité de POI** """)

        fig = px.density_mapbox(
            data,
            lat='latitude',
            lon='longitude',
            radius=4,
            center={
                "lat": 46.037763,
                "lon": 4.4
            },
            zoom=4,
            color_continuous_midpoint=5,
            mapbox_style='carto-positron',
            color_continuous_scale=['blue', 'grey', 'darkgrey', 'red', 'red'])
        fig.update_layout(coloraxis_showscale=False,
                          margin=dict(l=0, r=0, b=0, t=0, pad=4))
        fig.update_traces(hoverinfo='skip', hovertemplate=None)
        st.plotly_chart(fig)

        st.markdown("""# **Par départements**""")

        fig = px.choropleth_mapbox(
            data,
            geojson=france_regions_geo,
            color=data.code_departement.value_counts(),
            locations=data.code_departement.value_counts().index.tolist(),
            featureidkey='properties.code',
            opacity=1,
            center={
                "lat": 46.037763,
                "lon": 2.062783
            },
            mapbox_style="carto-positron",
            zoom=4)

        fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
        st.plotly_chart(fig)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

    elif choice == "Maintenance":

        image = Image.open('DATAtourisme.png')
        st.image(image, use_column_width=True, output_format='PNG')

        mdp = st.text_input("Mot de passe ?")

        st.write()
        if mdp == "Les+tour1stes.":
            if st.checkbox('voir dataframe'):
                st.write(data_erreur)
                st.markdown("")
                download = st.button('télécharger')
                if download:
                    csv = data_erreur.to_csv(index=False)
                    b64 = base64.b64encode(csv.encode()).decode()
                    linko = f'<a href="data:file/csv;base64,{b64}" download="data_erreur.csv">Download csv file</a>'
                    st.markdown(linko, unsafe_allow_html=True)

            f" Départements sans fournisseurs : **{data_erreur[data_erreur.fournisseur.isna()].code_departement.unique()}**"
            f" Départements sans créateur : **{data_erreur[data_erreur.createur_donnée.isna()].code_departement.unique()}**"
            f" Fournisseurs sans région : **{data_erreur[data_erreur.region.isna()].fournisseur.unique()}**"
            st.markdown("")
            st.markdown(""" # **Carte des erreurs latitude & longitude** """)
            st.markdown("")
            st.map(data_erreur_map)

        image = Image.open('WCS.png')
        st.image(image, use_column_width=True, output_format='PNG')

    else:
        st.subheader("""  """)
Ejemplo n.º 26
0
import streamlit as st
import ktrain
import pickle

from displacy_utils import *

st.set_page_config(layout="wide")

header = st.beta_container()

text_input, text_output = st.beta_columns(2)


def get_predictions(text):
    predictor = ktrain.load_predictor('./predictor')
    return predictor.predict(text, return_proba=True)


with header:
    st.title("Atlas Research Named Entity Recognition Demo")

with text_input:
    st.header("Text Input")
    user_input = st.text_area(
        "Add your clinical notes below (up to 250 characters):",
        value="",
        height=600)

with text_output:
    st.header("Tagged Output")
    if user_input != "":
Ejemplo n.º 27
0
def main():
    global al_score, dl_score
    st.title("MNIST - An Ng.")

    X_train, X_test, y_train, y_test = prepare_data()
    st.markdown('**Shape**')
    st.write('\nTraining set :', X_train.shape, "\nTest set :", X_test.shape)

    X_train, y_train = preprocess_data(X_train, y_train.reshape(-1, 1))
    X_test, y_test = preprocess_data(X_test, y_test.reshape(-1, 1))

    # general_config()
    radio_btn = st.radio("Approach", ("Deep Learning", "Active Learning"))

    if radio_btn == "Deep Learning":
        col1, col2 = st.beta_columns([1, 2])

        #params
        with col1:
            dl_expander = st.beta_expander("Params", expanded=True)
            with dl_expander:
                lr, epochs, batch_size = general_config()
        #display

        with col2:
            if st.button("Train"):
                #training
                with st.beta_container():
                    model = PassiveLearner(X_train, y_train, X_test, y_test,
                                           epochs, batch_size, lr)
                    with st.spinner('Training...'):
                        model.train()
                    st.balloons()
                    st.success("Train Successfully")

                    dl_score = model.evaluate(X_test, y_test)
                    st.write("Accuracy of Deep learning: ", dl_score)

    else:
        col1, col2 = st.beta_columns([1, 2])

        #params
        with col1:
            al_expander = st.beta_expander("Params", expanded=True)
            with al_expander:
                lr, epochs, batch_size = general_config()
                n_initial, n_queries, query_strategy = al_config()

                if query_strategy == 'uncertainty_sampling':
                    query_strategy = uncertainty_sampling
                else:
                    query_strategy = entropy_sampling
        #display
        with col2:
            if st.button("Train"):
                #training
                with st.beta_container():
                    model = CustomAcitveLearner(X_train, y_train, X_test,
                                                y_test, epochs, batch_size, lr,
                                                n_initial, n_queries,
                                                query_strategy)

                    with st.spinner('Training...'):
                        model.train()

                    st.balloons()
                    st.success("Train Successfully")

                    al_score = model.evaluate(X_test, y_test)
                    st.write("Accuracy of Active learning: ", al_score)
        f"""
    <style>
    .reportview-container .main .block-container{{max-width: 1000px;}}
    </style>
    """,
        unsafe_allow_html=True,
    )

    #---Title---#
    st.markdown(
        "<h1 style='text-align: center; font-size: 300%; margin: 0px 0px 100px 0px; text-shadow: 3px 5px 5px grey;'>Business Intelligence</h1>",
        unsafe_allow_html=True)
    # st.markdown("""## **You are now in the data analysis section 📊**""")

    #---Cards---#
    col1, col2, col3, col4 = st.beta_columns((20, 20, 20, 20))

    col1.markdown(f'''
    <div class="card text-white bg-info mb-3" style="width: 18rem">
        <div class="card-body">
            <h4 class="card-title" style='font-size: 150%; text-align:center; width=400;'>Total claims</h4>
            <p class="card-text" style='font-size: 135%; text-align:center; width=400;'><b>{claims['amount'].sum():,d}</b></p>
        </div>
    </div>''',
                  unsafe_allow_html=True)

    col2.markdown(f'''
    <div class="card text-white bg-info mb-3" style="width: 18rem;">
        <div class="card-body">
            <h4 class="card-title" style='font-size: 150%; text-align:center; width=400;'>Covid claims</h4>
            <p class="card-text" style='font-size: 135%; text-align:center; width=400;'><b>{claims['amount'][1]:,d}</b></p>
Ejemplo n.º 29
0
def app():

    # year-end summary
    fig = plot_year_summary()
    f_year = go.FigureWidget(fig)
    st.plotly_chart(f_year)

    st.title('Breakdown by Actor')
    st.write(
        'This section provides a summary of how bail type and bail amount depend on the person setting the bail (hereby referred to as the actor).'
    )

    # ----------------------------------
    #  interactive summary plots
    # ----------------------------------
    st.subheader("Comparison of bail type")
    # load data for interactive plot
    df_magistrate_2020, df_magistrate_2021 = load_data()
    # prepare data
    bail_type = ["Monetary", "ROR", "Unsecured", "Nonmonetary", "Denied"]
    bail_type_count = [
        "Monetary_count", "ROR_count", "Unsecured_count", "Nonmonetary_count",
        "Denied_count"
    ]

    data_2020 = np.array(df_magistrate_2020[bail_type]).transpose()
    count_2020 = np.array(df_magistrate_2020[bail_type_count]).transpose()
    names_2020 = list(df_magistrate_2020['magistrate'].values)
    total_2020 = df_magistrate_2020['Total'].astype(int)
    bail_set_2020 = df_magistrate_2020['bail_amount']

    data_2021 = np.array(df_magistrate_2021[bail_type]).transpose()
    count_2021 = np.array(df_magistrate_2021[bail_type_count]).transpose()
    names_2021 = list(df_magistrate_2021['magistrate'].values)
    total_2021 = df_magistrate_2021['Total'].astype(int)
    bail_set_2021 = df_magistrate_2021['bail_amount']

    # Initialize figure
    fig = go.Figure()

    ##### add traces for 2020
    for i in range(5):

        # text
        text = [str(item) + "%" if item > 6 else "" for item in data_2020[i]]

        # hover text
        # include monetary bail
        if i == 0:
            hovertext = [
                "name: " + name + "<br>" + "percentage: " + str(perct) + "%" +
                "<br>" + "case count: " + str(case) + " / " + str(total) +
                "<br>" + "total monetary bail amount set: " + str(amount)
                for name, perct, case, total, amount in zip(
                    names_2020, data_2020[i], count_2020[i], total_2020,
                    bail_set_2020)
            ]
        else:
            hovertext = [
                "name: " + name + "<br>" + "percentage: " + str(perct) + "%" +
                "<br>" + "case count: " + str(case) + " / " + str(total)
                for name, perct, case, total in zip(names_2020, data_2020[i],
                                                    count_2020[i], total_2020)
            ]

        fig.add_trace(
            go.Bar(y=names_2020,
                   x=data_2020[i],
                   text=text,
                   textposition="inside",
                   name=bail_type[i],
                   hoverinfo='text',
                   hovertext=hovertext,
                   orientation='h'))

    ##### add traces for 2021
    for i in range(5):

        # text
        text = [str(item) + "%" if item > 6 else "" for item in data_2021[i]]

        # hover text
        # include monetary bail
        if i == 0:
            hovertext = [
                "name: " + name + "<br>" + "percentage: " + str(perct) + "%" +
                "<br>" + "case count: " + str(case) + " / " + str(total) +
                "<br>" + "total monetary bail amount set: " + str(amount)
                for name, perct, case, total, amount in zip(
                    names_2021, data_2021[i], count_2021[i], total_2021,
                    bail_set_2021)
            ]
        else:
            hovertext = [
                "name: " + name + "<br>" + "percentage: " + str(perct) + "%" +
                "<br>" + "case count: " + str(case) + " / " + str(total)
                for name, perct, case, total in zip(names_2021, data_2021[i],
                                                    count_2021[i], total_2021)
            ]

        fig.add_trace(
            go.Bar(
                y=names_2021,
                x=data_2021[i],
                text=text,
                textposition="inside",
                name=bail_type[i],
                hoverinfo='text',
                hovertext=hovertext,
                orientation='h',
                visible=False  # hide in initial plot
            ))

    fig.update_layout(barmode='stack',
                      legend={'traceorder': 'normal'},
                      xaxis_title="percentage",
                      yaxis_title="magistrate",
                      legend_title="bail type")

    # update
    fig.update_layout(updatemenus=[
        dict(
            active=0,
            x=-0.35,
            xanchor='left',
            y=0.9,
            yanchor='top',
            buttons=list([
                dict(label="2020",
                     method="update",
                     args=[{
                         "visible": [
                             True, True, True, True, True, False, False, False,
                             False, False
                         ]
                     }, {
                         "title": "Bail type by actor in 2020"
                     }]),
                dict(label="2021",
                     method="update",
                     args=[{
                         "visible": [
                             False, False, False, False, False, True, True,
                             True, True, True
                         ]
                     }, {
                         "title": "Bail type by actor in 2021"
                     }])
            ]),
        )
    ])

    fig.update_layout(annotations=[
        dict(text="Select year",
             x=-0.35,
             xref="paper",
             y=0.98,
             yref="paper",
             align="left",
             showarrow=False)
    ])

    # Update plot sizing
    fig.update_layout(margin=dict(t=100, b=0, l=0, r=0),
                      title="Bail type by actor in 2020")

    f2 = go.FigureWidget(fig)
    st.plotly_chart(f2)

    st.write(
        "The above figure summarizes the percentage of bail types set by each actors. \
            For the year 2020, we selected 10 actors that handled the highest number of cases. \
            For the year 2021, we summarize the data upto March 31, 2021. \
            Hover your mouse over the figure for further details.")

    st.write(
        "**<font color='red'>Note to PBF</font>**: For every case in which bail was denied, there was no magistrate information found. Is this correct? ",
        unsafe_allow_html=True)
    ##### 2020 Summary plots #####

    # Explain selection of magistrates (Those who handled more than 500 cases)
    # Some timeline (Many were involved consistently throughout the year. Some were seasonal)
    # Explain 'Others': Those who set fewer than 500 cases. Total number of those labeled as "Others"

    # number of cases
    """
    st.header("1. Year-End Summary by Actor")
    st.subheader("Number of cases handled by each magistrate")

    _, col, _ = st.beta_columns([1,2,1])
    image = Image.open('figures/magistrate_case_count.png')
    col.image(image)
    st.write("In the year 2020, bail was set by 37 different people. We provide a summary of the bail type and bail amount for cases handled by the nine magistrates who handled more than 300 cases in the year 2020.")

    # bail type
    st.subheader("Percentage of bail type for each magistrate")
    """
    """
    st.write("**<font color='red'>Question for PBF</font>**: Would you prefer the following pie chart or the stacked bar chart?",  unsafe_allow_html=True)
    image = Image.open('figures/magistrate_type_summary.png')
    st.image(image, use_column_width=True)

    image = Image.open('figures/magistrate_type_summary_bar.png')
    st.image(image)
    """

    # bail amount
    st.subheader("Comparison of bail amount")

    df_monetary = pd.read_csv("data/cleaned/app_magistrate_amount.csv",
                              index_col=0)
    df_monetary_2020 = df_monetary[df_monetary["year"] == 2020]
    df_monetary_2021 = df_monetary[df_monetary["year"] == 2021]

    names_2020 = df_monetary_2020.groupby(
        "magistrate")["bail_amount"].median().sort_values()
    names_2021 = df_monetary_2021.groupby(
        "magistrate")["bail_amount"].median().sort_values()

    fig = go.Figure()

    # add traces for 2020
    for name in names_2020.index:
        data = df_monetary_2020[df_monetary_2020["magistrate"] ==
                                name].bail_amount
        fig.add_trace(go.Box(x=data, name=name.split(',')[0],
                             hoverinfo='skip'))

    # add traces for 2021
    for name in names_2021.index:
        data = df_monetary_2021[df_monetary_2021["magistrate"] ==
                                name].bail_amount
        fig.add_trace(
            go.Box(x=data,
                   name=name.split(',')[0],
                   hoverinfo='skip',
                   visible=False))

    # update
    fig.update_layout(updatemenus=[
        dict(
            active=0,
            x=-0.5,
            xanchor='left',
            y=0.9,
            yanchor='top',
            buttons=list([
                dict(label="2020",
                     method="update",
                     args=[{
                         "visible": [True] * len(names_2020) +
                         [False] * len(names_2021)
                     }, {
                         "title": "Bail amount by actor in 2020"
                     }]),
                dict(label="2021",
                     method="update",
                     args=[{
                         "visible": [False] * len(names_2020) +
                         [True] * len(names_2021)
                     }, {
                         "title": "Bail amount by actor in 2021"
                     }])
            ]),
        )
    ])

    fig.update_layout(xaxis_range=[0, 300000],
                      showlegend=False,
                      title="Bail amount by actor in 2020",
                      xaxis_title="amount",
                      yaxis_title="actor",
                      annotations=[
                          dict(text="Select year",
                               x=-0.5,
                               xref="paper",
                               y=0.98,
                               yref="paper",
                               align="left",
                               showarrow=False)
                      ])
    f3 = go.FigureWidget(fig)
    st.plotly_chart(f3)

    fig.update_layout(xaxis_range=[0, 300000],
                      showlegend=False,
                      title="Bail amount by actor in 2020",
                      xaxis_title="amount",
                      yaxis_title="actor")

    #image = Image.open('figures/magistrate_amount_summary.png')
    #_, col, _ = st.beta_columns([1, 5, 1])
    #col.image(image, use_column_width = True)
    st.write(
        "The above box plot compares the monetary bail amount set by different actors for the year 2020. \
            For each actor, the vertical line in the colored box represents the median bail amount set by that actor. \
            The colored boxes represent the 25% to 75% range of the bail amount set by the magistrate. The dots represent outliers."
    )
    st.write(
        "On average (median), the bail amount set by Connor, Bernard, and Rigmaiden-DeLeon ($50k) is higher than the bail amount set by others ($25k). \
            Moreover, Connor and Bernard seem to have set a wider range of bail amounts than other actors. "
    )

    ##### Comparison controling for offense types #####

    st.header("Analysis with controlled offense types")
    st.write(
        "While the above analysis provides a useful year-end summary, it does not provide a fair comparison of the actors. \
            In particular, the differences among actors may stem from the fact that some actors may have handled more cases with more severe charges."
    )

    st.write(
        "We compared the bail type and bail amount set by the actors while controlling for the difference in the charges. \
            We selected size actors (Bernard, Rainey, Rigmaiden-DeLeon, Stack, E-Filing Judge, and O'Brien) that handled more than 1000 cases in the year 2020. \
            We then conducted a matched study where we sampled cases with the same charges that were handled by the six actors."
    )

    st.write(
        "The following results were obtained from the 3264 cases (544 per magistrate) that were sampled. Ideally, there shouldn't be any noticeable difference across actors."
    )
    st.write(
        "Note that due to the sampling nature of the matched study, the matched dataset will vary across samples. However, the general trends observed below were consistent across multiple samples."
    )
    # bail type
    st.subheader("Percentage of bail type for each magistrate")
    #st.write("**<font color='red'>Question for PBF</font>**: Would you prefer the pie chart or the bar chart?",  unsafe_allow_html=True)
    image = Image.open('figures/magistrate_matched_type.png')
    st.image(image, use_column_width=True)

    #image = Image.open('figures/magistrate_matched_type_bar.png')
    #st.image(image)
    st.write(
        "When we control for the offense types, all actors set monetary bail to 31%-44% of their cases."
    )

    # bail amount
    st.subheader("Monetary bail amount set by each magistrate")
    st.write(
        "In the box plot, the colored bars represent the 25% to 75% range of the bail amount set by the magistrate.",
        unsafe_allow_html=True)
    _, col, _ = st.beta_columns([1, 5, 1])
    image = Image.open('figures/magistrate_matched_amount.png')
    col.image(image, use_column_width=True)
    """
    _, col, _ = st.beta_columns([1, 10, 1])
    image = Image.open('figures/magistrate_matched_amount_countplot.png')
    col.image(image, use_column_width = True)
    """
    st.write(
        "Even when we control for offense types, we see a difference in the monetary bail amount across actors.\
            While the median bail amounts are similar, comparing the colored boxes (which indicates the 25% - 75% range of bail amounts) show that Bernard, Rainey, and Rigmaiden-DeLeon tend to set higher bail amounts than the others."
    )

    st.write(
        "**<font color='red'>Note to PBF</font>**: The dashboard mockup contained two extrafigures: `DAO bail request breakdown` and `DAO vs magistrates`. However, we currently don't have the data.",
        unsafe_allow_html=True)
Ejemplo n.º 30
0
def write():
    #write is smart...it stops you from loading the every page when you import
    #^Above notes are just my musings
    import streamlit as st
    import matplotlib.pyplot as plt
    import pandas as pd
    import wordcloud
    import seaborn as sea

    username = st.text_input("Enter username here:")
    #plays song on the beach
    #eventually I should let this personalize
    boolean = False
    if len(username) > 0:
        try:
            df = pd.read_csv(username + ".csv")
            boolean = True
        except:
            st.write("username doesn't exist!")
    if boolean:
        audio_file = open('songonthebeach.ogg', 'rb')
        audio_bytes = audio_file.read()
        st.audio(audio_bytes, format='audio/ogg')
        #this reads our rastaman, example user csv
        df = pd.DataFrame(df)
        #str = random.choice(quote_list)
        #st.write(str)
        df = df.dropna()
        df.columns = ["score", "sentence", "date"]
        score = df["score"]
        #recent = the most recent score
        try:
            recent = score[len(score)-1]
            if recent == 0:
                st.write("Days like these come, and it's perfectly fine to be upset when difficulties arise. What you should remember is that days like these pass too, and that even when these times are dark, you still have friends, family, external resources to reach out too. Check out the resources tab for ways you can improve now.") 
        except:
            st.write("Your username exists but we didn't save your score. Sorry about that! Please insert your journal entry again and press save my score again to save it officially. This is a known bug thart occurs when a username is first created, but not after!")
        #below are placeholders for personalized notes. should add functionality for this l8r
        #if recent == 2:
        #    st.write("You're doing well today. I hope you keep up the progress.")
        #if recent == 1:
        #    st.write("You're not feeling so great today, and that's okay. Know I'll always care about you.")
        

        #code where if the last five have been super happy play Photograph


        col1, col2, col3 = st.beta_columns(3)

        #need to make this graph look better. should add a time slider too. would be cool if when a person hovers over a point they see the journal entry for it.
        with col1:
            #df["date"] = pd.to_datetime(df["date"])
            fig, ax = plt.subplots()
            df2 = df[["score", "date"]]
            df2["date"] = pd.to_datetime(df2["date"])
            df2['week_num'] = df2['date'].dt.strftime("%W")
            df2['day_num'] = df2['date'].dt.weekday
            df_wide = df2.pivot_table(index='week_num',columns='day_num',values='score')
            ax = sea.heatmap(df_wide)
            st.pyplot(fig)
        #have to take down this labelled_journal_entries csv before we release. If not, we release a lot of people's personal data.
        #need to add a slider for time here. maybe for mood too.
        with col2:
            #LJE = LJE[LJE["score"] < 4]
            from wordcloud import WordCloud
            wordcloud2 = WordCloud(background_color='white').generate(' '.join(df['sentence']))
            fig, ax = plt.subplots()
            plt.imshow(wordcloud2)
            plt.axis("off")
            st.pyplot(fig)
        #need to add sentiment-dependent emojis to output searches
        with col3:
            word = st.text_input("Input word you want to search for")
            if len(word) > 2:
                entries = ' '.join(df['sentence'])
                arr = entries.split('.')
                str = " "
                for i in range(0, len(arr)):
                    if word in arr[i]:
                        str = arr[i]
                        st.markdown(str)