示例#1
0
文件: app.py 项目: LuisValgoi/predia
    return mlp_regressor

########################################################################

# criando um dataframe
data = get_data()

# treinando os modelos
LSTM = train_model_lstm()
GB = train_model_gb()
MLP = train_model_mlp()

########################################################################

# título
st.title("PREDIA – Modelo Multifatorial")
# subtítulo
githublink = """
App utilizado para exibir a solução de Machine Learning construída para a predição de almoços do Restaurante Nostra Bréscia (<a href="https://github.com/LuisValgoi/predia" target="_blank">Github</a>)
"""
st.markdown(githublink, unsafe_allow_html=True)

########################################################################

# verificando o dataset
st.subheader("Selecionando apenas um pequeno conjunto de atributos")
allcols = ['DATA', 'VENDAS', 'FDS', 'DATA_FESTIVA', 'VESPERA_DATA_FESTIVA', 'POS_DATA_FESTIVA', 'FERIADO', 'ALTA_TEMPORADA', 'QTD_CONCORRENTES', 'TEMPERATURA', 'UMIDADE', 'VENDAS_ONTEM']
defaultcols = ['DATA', 'VENDAS', 'FDS', 'DATA_FESTIVA', 'FERIADO', 'ALTA_TEMPORADA', 'QTD_CONCORRENTES', 'TEMPERATURA', 'VENDAS_ONTEM']
cols = st.multiselect("", allcols, default=defaultcols)
st.dataframe(data[cols].head(10))
def app():
    page = st.sidebar.radio(
        label="",
        options=["Play with demo", "Try it yourself!"],
    )

    st.sidebar.header("Optimization Settings")
    include_location_optimization = st.sidebar.checkbox(
        label="Include location optimization", value=True)
    fairness_weight = st.sidebar.slider(label="Fairness Weight",
                                        min_value=0,
                                        max_value=50,
                                        value=0,
                                        step=1)
    fill_schedule_weight = st.sidebar.slider(
        label="Fill Schedule Weight",
        min_value=0,
        max_value=50,
        value=5,
        step=1,
    )
    max_unfairness = st.sidebar.slider(
        label="Max Unfairness (Max Employee Score - Min Employee Score)",
        min_value=-1,
        max_value=50,
        value=-1,
        step=1,
    )
    parameters: ConstraintParameters = ConstraintParameters(
        max_unfairness=max_unfairness,
        fairness_weight=fairness_weight,
        fill_schedule_weight=fill_schedule_weight,
        include_location_optimization=include_location_optimization,
    )

    st.title("Scheduling App")
    st.subheader("Optimized using Google OR-Tools in Python")

    constraints: Constraints = Constraints(
        raw_slot_constraints=pd.DataFrame(),
        slot_constraints=pd.DataFrame(),
    )
    roster: pd.DataFrame = pd.DataFrame()

    if page == "Play with demo":
        constraints = read_constraints(
            constraints_xlsx="demo_constraints.xlsx",
            parameters=parameters,
        )
        roster = read_roster("demo_roster.csv")
    else:
        st.markdown(
            get_excel_download_link(
                excel_file="demo_constraints.xlsx",
                label="Download Example Constraints",
                output_filename="demo_constraints.xlsx",
            ),
            unsafe_allow_html=True,
        )
        constraints_file = st.file_uploader(label="Constraints File Upload",
                                            type="xlsx")
        st.markdown(
            get_table_download_link(
                df=pd.read_csv("demo_roster.csv"),
                label="Download Example Roster",
                output_filename="demo_roster.csv",
                index=False,
            ),
            unsafe_allow_html=True,
        )
        roster_file = st.file_uploader(label="Roster File Upload", type="csv")
        if constraints_file is not None:
            constraints_file.seek(0)
            constraints = read_constraints(
                constraints_xlsx=constraints_file,
                parameters=parameters,
            )
        if roster_file is not None:
            roster_file.seek(0)
            roster = read_roster(roster_file)

    if not constraints.slot_constraints.empty and not roster.empty:
        optimal_schedule: Schedule = create_optimal_schedule(
            constraints=constraints,
            roster=roster,
            parameters=parameters,
        )
        st.header("Schedule Constraints")
        st.write(constraints.raw_slot_constraints)

        st.header("Roster")
        st.write(roster)

        if parameters.include_location_optimization:
            st.header("Bench Constraints")
            st.write(constraints.raw_bench_constraints)
            st.header("Lab Separation")
            st.write(constraints.raw_lab_separation)
            for lab in constraints.raw_lab_maps:
                st.header(f"{lab}")
                st.write(constraints.raw_lab_maps[lab])

        demand_heatmap = create_demand_heatmap(roster=roster)
        st.plotly_chart(demand_heatmap)

        st.header("Optimal Schedule")
        st.write(
            f"Shift Optimization Score: {optimal_schedule.objective_score}")
        st.write(f"Shifts Filled: {optimal_schedule.total_shifts_filled} "
                 f"out of {optimal_schedule.total_possible_shifts}")
        if parameters.include_location_optimization:
            st.write(f"Bench Optimization Score"
                     f": {optimal_schedule.bench_objective_score}")
            average_bench_distance: float = statistics.mean(
                optimal_schedule.bench_optimization_average_distance.values())
            st.write(f"Average Distance b/w home bench and shift bench: "
                     f"{average_bench_distance}")
        st.write(optimal_schedule.pretty_employee_schedule)
        st.markdown(
            get_table_download_link(
                df=optimal_schedule.pretty_employee_schedule,
                label="Download Optimal Schedule",
                output_filename="optimal_employee_schedule.csv",
            ),
            unsafe_allow_html=True,
        )
        score_boxplot = create_score_boxplot(
            optimal_schedule=optimal_schedule.pretty_employee_schedule)
        st.plotly_chart(score_boxplot)
    else:
        st.write("Please upload constraints and roster")
示例#3
0
import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk
import plotly.express as px

DATA_URL = ("D:\Tutorials\Coursera\Rhyme Streamlit Project\dataset.csv")
st.title("Motor Vehicle Collisons in NYC")
st.markdown(
    "This application is a streamlit dashboard used to analyze Motor vehicle collison in NYC"
)


@st.cache(persist=True)
def load_data(nrows):
    data = pd.read_csv(DATA_URL,
                       nrows=nrows,
                       parse_dates=[['CRASH_DATE', 'CRASH_TIME']])
    data.dropna(subset=['LATITUDE', 'LONGITUDE'], inplace=True)
    lowercase = lambda x: str(x).lower()
    data.rename(lowercase, axis='columns', inplace=True)
    data.rename(columns={'crash_date_crash_time': 'date/time'}, inplace=True)
    return data


data = load_data(100000)
original_data = data

st.header("Where are the most people Injured?")
injured_people = st.slider("Number of Persons Injured", 0, 19)
st.map(
示例#4
0
import streamlit as st
import pickle

st.set_page_config(page_icon='', initial_sidebar_state='expanded')

st.title('Beyonce or Rihanna Lyrics Classifier')

st.write('Use the sidebar to select a page to view.')

page = st.sidebar.selectbox('Page', ('About', 'EDA', 'Make a prediction'))


@st.cache
def load_data():
    ladies = pd.read_csv('lyrics_and_artist.csv', encoding='latin-1')
    return ladies


if page == 'About':
    st.subheader('About this project')
    st.markdown(
        '''This is a Streamlit app that hosts my Beyonce vs. Rihanna SVM model, with count vectorized text.
    For each of these artists, I gathered the lyrics for their top 75 most popular songs (not including remixes & features), according to the Genius song lyric site.



| Top 75 most popular songs for beyonce         | Top 75 most popular songs for Rihanna         |
|-----------------------------------------------|-----------------------------------------------|
| Song 1: "Drunk in Love"                       | Song 1: "Work"                                |
| Song 2: "Formation"                           | Song 2: "Love on the Brain"                   |
| Song 3: "Partition"                           | Song 3: "Needed Me"                           |
                    progress_bar.progress(min(counter / length, 1.0))
    # Finally, we remove these visual elements by calling .empty().
    finally:
        if weights_warning is not None:
            weights_warning.empty()
        if progress_bar is not None:
            progress_bar.empty()


WEBRTC_CLIENT_SETTINGS = ClientSettings(
    rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
    media_stream_constraints={"video": True, "audio": True},
)


st.title("Face Detection systme")
st.write("Maza Aaya")
cascPath =  "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

class VideoTransformer(VideoTransformerBase):
  def transform(self, frame):
    frame = frame.to_ndarray(format="bgr24")
    gray  = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(gray,scaleFactor = 1.1,minNeighbors = 5,minSize=(30,30))
    for (x,y,w,h) in faces:
      cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
    return frame
        
webrtc_streamer(key="example", video_transformer_factory=VideoTransformer)
import streamlit as st
import about_data as ad
import data_preview as dp
import eda as ed
import data_prediction as d_p
def sidebar():
    
    st.sidebar.title("About")
    st.sidebar.info(
        "This an open source project. " 
        "This app is maintained by **Rohan Gupta**. " 
        "Go check out my [Github account](https://github.com/rohan300557) :grinning: ")


st.title('Adult Census Income')

if(st.sidebar.checkbox('About Dataset')):
    st.image("data/adult_income.jpg", use_column_width = True)
    ad.main()
if(st.sidebar.checkbox('Data Preview')):
    st.image("data/adult_income.jpg", use_column_width = True)
    dp.main()
if(st.sidebar.checkbox('EDA')):
    st.image("data/adult_eda.jpg", use_column_width = True)
    ed.main()
if(st.sidebar.checkbox('Income Predictor')):
    st.image("data/adult_income.jpg", use_column_width = True)
    d_p.main()
else:
    st.image("data/adult_income.jpg", use_column_width = True)
    sidebar()
示例#7
0
                                   fill='rgb(44,125,246)',
                                   dot="false",
                                   y_axis_id='loss_axis')
        getattr(epoch_chart, type)(type='monotone',
                                   data_key='acc',
                                   stroke='#82ca9d',
                                   fill='#82ca9d',
                                   dot="false",
                                   y_axis_id='acc_axis')
        # HACK: Use get_report_ctx() to grab root delta generator in an i9e
        # world.
        # TODO: Make this file not need _native_chart
        return get_report_ctx().root_dg._native_chart(epoch_chart)


st.title('MNIST CNN')

(x_train, y_train), (x_test, y_test) = mnist.load_data()

img_width = 28
img_height = 28

x_train = x_train.astype('float32')
x_train /= 255.
x_test = x_test.astype('float32')
x_test /= 255.

#reshape input data
x_train = x_train.reshape(x_train.shape[0], img_width, img_height, 1)
x_test = x_test.reshape(x_test.shape[0], img_width, img_height, 1)
示例#8
0
def home_page():
    # Setting the title -
    st.title("TAMIDS Data Science Competition")

    # Desription -
    st.markdown("""
                <p style='text-align: justify;'>
                
                The 2021 TAMIDS Data Science Competition concerns the role of money in US Presidential Elections. The key
             idea of democracy is that every citizen should have input, via a vote, as to who is elected. Enormous amounts of
             money are expended by political campaigns to engage with voters, and so fundraising has become a major
             activity by candidates and other actors. Donations are an additional way for constituents to get involved in political
             races. Unions and corporations are able to donate through Political Action Committees (PACs), while the
             2010 Citizens United ruling by the US Supreme Court has removed caps on corporate donations via PACs and
             allowed campaign ads to be published or broadcast anonymously.  
                
                </p>
                """,
                unsafe_allow_html=True)

    # Problem Statement -
    st.write("""
             ## Problem Statement
             """)
    st.markdown("""
                <p style='text-align: justify;'>
             Money has a huge impact on US presidential elections. The aim is to look into the depth of how political parties spend 
             and get money as donations during the Presidential elections. As an analyst, we have to observe patterns, 
             check the effectiveness of the expenditures and provide some inferences and recommendations as to where to 
             invest the money for the next Presidential elections. 
             </p>
                """,
                unsafe_allow_html=True)

    # Data Collection and Pre-processing -
    st.write("""
             ## Data Collection and Pre-processing
             """)
    st.markdown("""
                <p style='text-align: justify;'>
             The analysis has been made on two groups of data: Donations and Expenditures. We created a dataset 
             to analyze the Donations received by the two major political parties (i.e. Democrats and Republicans). 
             The data from the major corporate donations have been taken into account. The corporate donation data 
             has been segregated based on the industry sector i.e. Finance, Healthcare, Defence, law, Energy, etc. 
             </p>
                """,
                unsafe_allow_html=True)
    st.markdown("""
                <p style='text-align: justify;'>
             Donation data over the years have been collected and consolidated into a single datasheet. 
             Additionally, a state column has been created based on the location of the Corporate Headquarters. 
             </p>
                """,
                unsafe_allow_html=True)
    st.markdown("""
                <p style='text-align: justify;'>
             Data associated with different political parties for each election year was collected and analyzed. 
             At first, the features were cleaned and null entries corresponding to the state were removed. 
             Further, the data was merged to create a dataset, where for each state, the expenditure for political 
             parties as well as the share of vote they received for each election year is reported. We also worked on 
             the expenditure data set, categorized the purpose of different investments made by each political party 
             for further analysis. 
             Once it was done, we looked into census data and pruned it to make it mergeable with the previously 
             constructed data set. Since there are multiple races, we cut it down to three, namely: White population, 
             Black population and Other population. In this way, data cleaning and feature engineering was done.
 
             </p>
                """,
                unsafe_allow_html=True)

    # Overview -
    st.write("""
             ## Methodology
             """)
    st.markdown("""
                <p style='text-align: justify;'>
                    
                * **Feature Engineering:** After cleaning the dataset, some more features were constructed which includes population of several races as well as changing the total number of votes to percentage of votes. Further, we changed the expenditure amount in millions of dollars and population in 100,000. This helped in creating a better data which will be further used in unsupervised learning. 
                * **Unsupervised Learning:** Once suitable features were engineered, we moved to some clustering methods. We approached the data in several ways using KNN, AgglomerativeClustering, Dendrograms and Topological Data Analysis. Since the data points are not large enough, we didn’t keep the number of clusters as a hard number. Rather, with the mapper package, we see a better picture of our clusters which brings us to the visualizations. 
                * **Dynamic Visualization:** The graph which contains clusters is colored in a way which represents much better graphics along with information for every node. We host a website to represent different findings we have with an option to choose the party the analyst would like to know about. For each year, anyone on the website can look into how money or people of different races are related to vote shares of different parties for the past three elections as well as which institution prefers which party. Therefore, the website we have designed is very dynamic and suitable for everyone.

             </p>
                """,
                unsafe_allow_html=True)

    # Navigation -
    st.write("")
    st.info("Please navigate using the select box in the sidebar on the left.")
示例#9
0
def expenditure_analysis():
    # Setting the title -
    st.title("Expenditure and Demographics Analysis!")

    # Desription -
    st.markdown("""
                <p style='text-align: justify;'>
                   The key idea of democracy is that every citizen should have input, via a vote, as to who is elected. Enormous amounts of
             money are expended by political campaigns to engage with voters, and so fundraising has become a major
             activity by candidates and other actors. The money is spent for various purposes.
                </p>""",
                unsafe_allow_html=True)

    st.write("")

    # Getting the initial image -
    col1, col2, col3 = st.beta_columns((1, 2.5, 1))
    image = Image.open(
        'Expenditure_Demographics_Analysis/Data_Clean_Preprocess/Initial_Overview.png'
    )
    col2.image(image)

    # Showing inital analysis -
    st.markdown("""
                <p style='text-align: justify;'>
                   The above graph demonstrates the trend in amount expenditure of each party for the last 
               10 years. From the graph, the first obvious conclusion is: The campaigning expenditure 
               for each party increased five-fold for the last presidential year. This increased the 
               total voting numbers. Another subtle inference is the change and the difference in the 
               expenditure of Republicans and Democrats from the last presidential election to the 2020 
               presidential election.
                </p>""",
                unsafe_allow_html=True)

    st.write(" ")
    # State-wise graphs -
    st.markdown("""
                <p style='text-align: justify;'>
                   After analyzing the bigger picture, the next thing needed is “micro-analysis”. From looking 
             at a national scope, we switch to states and start looking at different expenses. The 
             dataset which comprised various purposes of expenditure was categorized using NLP with 
             categories: Advertisement, Communications, Logistics, and others.
                </p>""",
                unsafe_allow_html=True)
    st.write(" ")

    col1, col2 = st.beta_columns((1, 1))
    # Getting party from the user -
    party_selected = col1.selectbox("Select Party",
                                    ['Democrats', 'Republicans'])

    # Getting expenditure from the user -
    expenditure_category_selected = col2.selectbox("Select Expenditure", [
        "All Expenses", "Communiations Expenses", "Advertisement Expenses",
        "Logistics Expenses", "Others"
    ])

    # Getting the graph -
    get_party_exp_graph(party_selected, expenditure_category_selected)

    # Geting the sponding explanation -
    get_graph_inference(party_selected)

    st.write("---")
    # DIFFERENCE PLOT -

    st.write("""
             ## How much does investment help?
             """)
    st.markdown("""
                <p style='text-align: justify;'>
                From the previous graph, we can see that each party wanted to go all in this time and win the elections. 
             But does investment always lead to an increase in the voting percentage? To answer this question we defined a 
             Return of Investment index for different states based on how much does campaigning influences the results for both parties. 
             </p>""",
                unsafe_allow_html=True)
    st.write(" ")

    # Choosing party to analyze vote difference.
    col1, col2, col3 = st.beta_columns((1, 1.5, 1))
    party_selected_2 = col2.selectbox(
        "Choose a party to analyze vote difference over years - ",
        ['Democrats', 'Republicans'])
    st.write(" ")

    # Getting vote difference graphs -
    get_vote_diff_graphs(party_selected_2)

    # Getting inference, result, analysis -
    st.write("""
             ### **Inference**
             """)
    st.markdown("""
                <p style='text-align: justify;'>
             The graphs are divided into two subgraphs where one corresponds to the states where the percentage of votes received by 
             Republicans/Democrats increased and the other subgraph where we see the states when the percentage of votes received by 
             Republicans/Democrats decreased between two presidential elections.  
              </p>""",
                unsafe_allow_html=True)

    st.markdown("""
                <p style='text-align: justify;'>          
             The first important question, whether investing always helps is answered through all the graphs. In various states, 
             the Republicans lost votes despite an increase in expenditure of millions of dollars. The ROI for republicans is positive 
             (significantly larger than 0) for the states (except Utah) where they lost, which means they reduced their expenditures there. 
             In 2016 in Utah, they reduced their investment and therefore lost a lot of votes (more than 25%), however, the state remained 
             red. But the next presidential election, they invested more and were able to get the votes in their favor. If we look at the 
             Democrats data, only five states witnessed a surge in blue votes whereas in 2020 all the states had an increase in the number 
             of votes for Democratic party. Most of the states with high ROI went Blue, except Utah in 2020. Because of a decrease 
             in Republican votes in 2016, Democrats invested just a little in 2020 and were able to secure 10% more votes than in 2016, 
             thereby giving a huge ROI for the same. This way, the graph helps us understand the trends and the power of campaigning on the 
             minds of different people beautifully.
             </p>""",
                unsafe_allow_html=True)

    st.write("---")

    # Entering the final plot of Tushar -
    st.write("""
             ## People, Money, and Voting!""")

    st.markdown("""
             <p style='text-align: justify;'>
             A scatter plot with population data, expenditure data, the voting percentage for three presidential election years 
             tells us about some correlation between the certain population in some states and how they affect the electoral votes 
             in their respective states.
             </p>""",
                unsafe_allow_html=True)

    # Choosing party to analyze vote difference.
    col1, col2, col3 = st.beta_columns((1, 1.5, 1))
    party_selected_3 = col2.selectbox(
        "Choose a party to analyze overall graphs - ",
        ['Democrats', 'Republicans'])
    st.write(" ")

    # Getting vote difference graphs -
    get_overall_graphs(party_selected_3)

    # Get overall inference -
    get_overall_inference(party_selected_3)
示例#10
0
    tag = intents_list[0]['intent']
    list_of_intents = intents_json['intents']
    for i in list_of_intents:
        if i['tag'] == tag:
            result = random.choice(i['responses'])
            break
    return result


# get user input from text_input
def get_text():
    input_text = st.text_input("You: ", "")
    return input_text


st.title("Laura ULK ChatBot")

html_temp = """
<div style="background-color:black;padding:10px">
<h5 style="color:white;"> What would you like to know about programs at ULK?</h5>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
# st.text("What would you like to know about programs at ULK?")
st.text(
    "type your question in the field below and press enter and get your answer"
)

with st.spinner("Loading Model Into Memory..."):
    model = loadModel()
                 y=vc.values,
                 labels=dict(x="Transacciones", y="Cantidad"))
    fig.update_layout(xaxis=dict(
        tickmode='array', tickvals=[0, 1], ticktext=['Normal', 'Fraude']))
    return fig


@st.cache
def con_fraude(data):
    return data[data['is_fraud'] == 1]


if __name__ == "__main__":

    with st.sidebar:
        st.title("Team Cheems - 31")
        st.header("Navegación")
        mode = st.radio(
            "Menu",
            ["Reto NDS", "EDA"],
        )
        #st.subheader("Select a state or all US states:")
        #all_states = st.checkbox("All US States", True)
        #locations = np.append(["USA Total"], states)
        #state = st.selectbox("State", states, index=37)
    if mode == 'Reto NDS':
        header = st.beta_container()
        dataset = st.beta_container()
        viz = st.beta_container()
        with header:
            st.title('Detección de fraude')
示例#12
0
def page_dashboard(state):
    st.title("Informacoes iniciais para o usuario")
示例#13
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 17 14:37:45 2020

@author: EmileVDH
"""
#PACKAGES
import pandas as pd
import streamlit as st
import os
import numpy as np
import seaborn as sns

st.title("Good Bad EDA Function")

####################import the data csv
st.header('1. Upload Your Data')
#Widget to upload file
uploaded_file = st.file_uploader("Choose a csv file", type="csv")
#show total records and all the columns imported.

df = pd.read_csv(uploaded_file)

st.text("Variable list:")
st.table(df.columns)

##    ##select the varible for time limiter variable any calendar object??
#time = st.selectbox('Which varible will be your Time Limiter?',df.columns)
##
#time_split_value=st.slider(time)
示例#14
0
def plot_array_directivity():
    st.title('Source/Vibrator array analysis ')

    my_expander1 = st.expander("General parameters:", expanded=True)
    with my_expander1:
        col1, col2, col3, col4, col5 = st.columns(5)
        with col1:
            no_of_vibs = st.number_input('Number of vibrators in one array:',1,9,1,1)
        with col4:
            max_freq =  st.number_input('Select maximum frequency',1,250,150,1)
            #inline_view= st.selectbox('Produce inline view plot',(True,False))
        with col2:
            include_ghost= st.selectbox('Include the source ghost',(True,False))
            #crossline_view= st.selectbox('Produce crossline view plot',(False,True))
        with col3:
            ff_pos = st.number_input('Far field distance (m)',100,9000,9000,100)
        with col5:
            frequency_birdseye = st.number_input('Select birdseye frequency',1,250,40,1)

        inline_pos = np.zeros((50))
        crossline_pos = np.zeros((50))
        depth_pos = np.zeros((50))
        source_type = ["" for x in range(50)]

        signature=[]
        sampling_interval=[]

    my_expander2 = st.expander("The individual source elements:", expanded=True)
    with my_expander2:
        col1, col2, col3, col4, col5 = st.columns(5)
        key_count=0

        try:
            inline_pos_default = np.load("inline.npy")
        except:
            inline_pos_default=np.zeros((50)) #up to 50 source elements supported
            np.save('inline.npy', inline_pos_default)

        try:
            crossline_pos_default = np.load("xline.npy")
        except:
            crossline_pos_default=np.zeros((50)) #up to 50 source elements supported
            np.save('xline.npy', crossline_pos_default)

        try:
            depth_pos_default = np.load("depth.npy")
        except:
            depth_pos_default=5*np.ones((50)) #up to 50 source elements supported
            np.save('depth.npy', depth_pos_default)

        try:
            with open ('type.pkl', 'rb') as fp:
                type_default = pickle.load(fp)
        except:
            type_default=[]
            for k in range(0,50):
                type_default.append('predef')
            with open('type.pkl', 'wb') as fp:
                pickle.dump(type_default, fp)

        with col1:
            st.write('Inline position (m)')
            for i in range(0, no_of_vibs):
                key_count = key_count+1 #to get a uniq key for every entry
                inline_pos[i] = st.number_input('Vib #'+str(i+1)+':',-3000.0,3000.0,inline_pos_default[i], 0.5, None, key=key_count)
                inline_pos_default[i] = inline_pos[i]
            #save the pos in each iteration
            np.save('inline.npy', inline_pos)

        with col2:
            st.write('Crossline position (m)')
            for i in range(0, no_of_vibs):
                key_count = key_count+1 #to get a uniq key for every entry
                crossline_pos[i] = st.number_input('Vib #'+str(i+1)+':',-3000.0,3000.0,crossline_pos_default[i], 0.5, None, key=key_count)
                crossline_pos_default[i] =crossline_pos[i]
            #save the pos in each iteration
            np.save('xline.npy', crossline_pos)

        with col3:
            st.write('Depth (m)')
            for i in range(0, no_of_vibs):
                key_count = key_count+1 #to get a uniq key for every entry
                depth_pos[i] = st.number_input('Vib #'+str(i+1)+':',0.0,50.0,depth_pos_default[i],0.5,None ,key=key_count)
                depth_pos_default[i] = depth_pos[i]
            #save the pos in each iteration
            np.save('depth.npy', depth_pos)

        with col4:
            st.write('Source_type')
            for i in range(0, no_of_vibs):
                key_count = key_count+1 #to get a uniq key for every entry
                source_type[i]=  st.selectbox('Type of input:',[type_default[i], 'predef','LF','HF_omni','HF_dir','From file'],key=key_count)
                type_default[i] = source_type[i]
            with open('type.pkl', 'wb') as fp:
                pickle.dump(type_default, fp)


        with col5:
            #TODO - enable users to read the full Nucleus DB....
            st.write('Signature file upload')
            signature=[] #these are just some default signatures to read in.... tor testing
            dir_name="Gun_Database"
            file_gun=[ os.path.join(dir_name, "45_cluster_6m.far"),
            os.path.join(dir_name,"45_cluster_6m.far"),
            os.path.join(dir_name,"45_cluster_6m.far"),
            os.path.join(dir_name,"250_cluster_9m.far"),
            os.path.join(dir_name,"180_single_6m.far"),
            os.path.join(dir_name,"100_cluster_9m.far"),
            os.path.join(dir_name,"100_cluster_6m.far"),
            os.path.join(dir_name,"80_single_6m.far")]

            dir_name="Vib_Database"
            file_hf_dir=[os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_0deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_DIR.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_180deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_DIR.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_90deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_DIR.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_270deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_DIR.data")]

            file_hf_omni=[os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_0deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_180deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_90deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_270deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_1_OBN_OMNI.data")]

            file_lf_omni=[os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_0deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_2_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_180deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_2_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_90deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_2_OBN_OMNI.data"),
                       os.path.join(dir_name,"v17_OUTPUT_DOWNSWEEP_270deg_phase_sec_disp_acc_Hz_rollrad_VIBGROUP_2_OBN_OMNI.data")]

            sampling_interval=[]
            max_len = 0
            for i in range(0, no_of_vibs):
                key_count = key_count+1 #o get a uniq key for every entry
                if(source_type[i]=="From file"):
                    file = st.file_uploader("Choose a file (on server)", key=key_count)
                    try:
                        [sig, si] = get_signature_from_file(file)
                    except:
                        st.write('You need to pick a source signature file')
                        return 0

                if(source_type[i]=='HF_omni'):
                    [sig, si] = readSignature2(file_hf_omni[i])

                if(source_type[i]=='HF_dir'):
                    [sig, si] = readSignature2(file_hf_dir[i])

                if(source_type[i]=='LF' ):
                    [sig, si] = readSignature2(file_lf_omni[i])

                if(source_type[i]=='predef'): #just default some air-gun files
                    [sig, si] = readSignature(file_gun[i])

                signature.append(sig)
                sampling_interval.append(si)

                if len(sig)>max_len:
                    max_len = len(sig)

            #go through - and check that all signatures have the same length - if not - we pad with zeros
            for i in range(0, no_of_vibs):
                #print("men and maxlen:",len(signature[i]),max_len)
                try:
                    if (len(signature[i]) < max_len):
                        tmp = np.zeros((max_len))
                        tmp[0:len(signature[i])] = signature[i]
                        signature[i] = tmp
                except:
                    print("hmmm")

            #convert the signature list to a numpy array (for speed)
            signature = np.asarray(signature, dtype=np.float32)
            #print("Signature.shape=", signature.shape)

    my_expander3 = st.expander("Plot source layout:", expanded=False)
    with my_expander3:
        col1, col2, col3 = st.columns(3)
        with col1:
            fig = go.Figure()
            fig.add_trace(go.Scatter(x=inline_pos[0:no_of_vibs], y=crossline_pos[0:no_of_vibs], mode='markers',  marker_size=12, marker_symbol='star'))
            fig.update_layout(title='Source layout (birdseye)',  xaxis_title='Inline (m)',yaxis_title='Xrossline (m)')
            st.plotly_chart(fig)
        with col2:
            fig = go.Figure()
            fig.add_trace(go.Scatter(x=inline_pos[0:no_of_vibs], y=depth_pos[0:no_of_vibs], mode='markers',  marker_size=12, marker_symbol='star'))
            fig.update_layout(title='Source layout (inline-depth)',  xaxis_title='Inline (m)',yaxis_title='Depth (m)')
            st.plotly_chart(fig)
        with col3:
            fig = go.Figure()
            fig.add_trace(go.Scatter(x=crossline_pos[0:no_of_vibs], y=depth_pos[0:no_of_vibs], mode='markers',  marker_size=12, marker_symbol='star'))
            fig.update_layout(title='Source layout (crossline-depth)',  xaxis_title='Crossline (m)',yaxis_title='Depth (m)')
            st.plotly_chart(fig)

    my_expander4 = st.expander("Plot individual element signatures:", expanded=False)
    with my_expander4:
        col1, col2 = st.columns(2)
        with col1:
            #plot the t-x signatures of the individual sources - just to to get started
            fig = go.Figure()
            if(len(signature)>0 and len(sampling_interval)>0):
                t=np.linspace(0,len(signature[0])*sampling_interval[0], len(signature[0]))
                if(t[-1] < 20):
                    t=t*1000

                for i in range(0, len(signature)):
                    fig.add_trace(go.Scatter(x=t, y=signature[i], mode='lines' ))

                txt = ('Source time-amplitude plot')
                fig.update_layout(title=txt,  xaxis_title='Milliseconds',yaxis_title='Amplitude')
                st.plotly_chart(fig)

                #make a spectrogram
                for i in range(0, len(signature)):
                    if(sampling_interval[i]<0.02): #we assume this is a vib - and not a gun
                        [f, t, Sxx] = signal.spectrogram(x=signature[i], fs=1/sampling_interval[i], nfft=256*16)
                        maxFreq=250
                        my_len = round(maxFreq*Sxx.shape[0]/(1.0/(2*sampling_interval[0])))

                        f=f[0:my_len]
                        Sxx=Sxx[0:my_len,:]
                        Sxx=Sxx/ max(map(max, Sxx)) #normalize

                        fig = go.Figure(data=go.Heatmap(x=t, y=f, z=Sxx))
                        txt = 'Spectrogram: Normalized amplitude of source #'+str(i+1)+'.'
                        fig.update_layout(xaxis_title = 'Time (sec)', yaxis_title='Frequency (Hz)', title=txt)
                        st.plotly_chart(fig)

                        #and the autocorrelation of the sweep:
                        corr= np.correlate(signature[i], signature[i], mode="full")
                        corr=corr/max(corr)
                        fig = go.Figure()
                        fig.add_trace(go.Scatter(y=corr, mode='lines',name='auto-correlation' ))
                        txt = 'Autocorrelation of vibrator sweep #'+str(i+1)+'.'
                        fig.update_layout(xaxis_title = 'Sample', yaxis_title='Correlation coeff [-1,1]', title=txt)
                        st.plotly_chart(fig)


        with col2:
            fig = go.Figure()
            if(len(signature)>0 and len(sampling_interval)>0):
                t=np.linspace(0,1000/sampling_interval[0], len(signature[0]))
                samps = round(len(signature[0])*250/(1000/sampling_interval[0]))
                if(t[-1] < 20):
                    t=t*1000

                for i in range(0, len(signature)):

                    #multitaper spectral estimate
                    A, weights, eigenvalues = pmtm(signature[i], NW=2.5,k=4)
                    A = 20*np.log10(np.mean(abs(A) * np.transpose(weights), axis=0))
                    #cut out the 0-250Hz range
                    A=A[0: round(len(A)*250/4000)]

                    #normal fft for comparing
                    #B= 20*np.log10(abs(np.fft.rfft(signature[i]*np.hamming(len(signature[i])))))

                    if(samps<100):
                        t= np.linspace(0, 0.5/sampling_interval[i], len(signature[i]))
                        samps = round(len(signature[i])*250/2000)

                    ##plot the fft results
                    #fig.add_trace(go.Scatter(x=t[0:samps], y=B[0:samps], mode='lines', name='fft' ))

                    #plot the multitaper results - which is pow2 long....
                    fig.add_trace(go.Scatter(x=np.linspace(0,250, len(A)),y=A, mode='lines',name='MultiTaper' ))

                txt = ('Multitaper spectral amplitude estimation')
                fig.update_layout(title=txt,  xaxis_title='Frequency (Hz)',yaxis_title='Amplitude (dB)')
                st.plotly_chart(fig)

                #make a spectrogram as well
                for i in range(0, len(signature)):
                    if(sampling_interval[i]<0.02): #we assume this is a vib - and not a gun
                        [f, t, Sxx] = signal.spectrogram(x=signature[i], fs=1/sampling_interval[i], nfft=256*16)
                        maxFreq=250
                        my_len = round(maxFreq*Sxx.shape[0]/(1.0/(2*sampling_interval[0])))
                        f=f[0:my_len]
                        Sxx=Sxx[0:my_len,:]
                        Sxx=Sxx/ max(map(max, Sxx)) #normalize

                        fig = go.Figure(data=go.Heatmap(x=t, y=f, z=np.log10(Sxx)))
                        txt = 'Spectrogram: Normalized amplitude of source #'+str(i+1)+' in dB.'
                        fig.update_layout(xaxis_title = 'Time (sec)', yaxis_title='Frequency (Hz)', title=txt)
                        st.plotly_chart(fig)

    my_expander5 = st.expander("Directivity plots:", expanded=True)

    delay=[]
    if len(sampling_interval)==no_of_vibs:
        col1, col2, col3 = st.columns(3)
        with col1:
            plot_2d = st.button("Plot source directivity")
            if (plot_2d):
                [fig1, fig3, fig5]=plot3d_directivity_and_phase(signature, sampling_interval, inline_pos, crossline_pos, depth_pos, no_of_vibs, max_freq, ff_pos, include_ghost, frequency_birdseye)
                st.pyplot(fig1)
                #st.pyplot(fig2)
        with col2:
            plot_2d_crossline = st.button("To be added in the future")
            if (plot_2d):
                st.pyplot(fig3)
                #st.pyplot(fig4)
        with col3:
            if (plot_2d):
                st.pyplot(fig5)

    else:
        st.write('Need signatures from all vibes to compute directivity plots')
示例#15
0
for i in range(1,10):
    mes_columns_dict['Mes '+str(i)+'     '] = 'Mes '+str(i)
for i in range(10,25):
    mes_columns_dict['Mes '+str(i)+'    '] = 'Mes '+str(i)

mes_columns = []
acum_mes_columns = []
for i in range(1,25):
    mes_columns.append('Mes '+str(i))
    acum_mes_columns.append('Acum_Mes '+str(i+1))
acum_mes_columns = acum_mes_columns[:-1]

st.set_page_config(layout="wide", initial_sidebar_state='auto')


st.title("SIMULACIÓN PREDICCIÓN DE PEDIDOS DE LIBROS")
key = st.secrets["key"]



df, datos = load_data(key)
#st.text(df.head())

num_prediccions = st.sidebar.number_input("Número de predicciones (selección aleatoria de estos elementos de la base de datos)", min_value=10, max_value=len(df)-1, value=20)
manual_entry = st.sidebar.checkbox("Pincha para entrar manualmente los datos de la predicción a realizar", value=False)


st.sidebar.title(("Selecciona los parámetros del libro:"))

libro = st.sidebar.selectbox('Libro', datos['libros'])
autor = st.sidebar.selectbox('Autor', datos['autores'])
示例#16
0
def industry_donations_analysis():
    # Setting the title -
    st.title("Industry Donation Analysis")

    # Desription -
    st.markdown("""
                <p style='text-align: justify;'>  
                An analysis of the corporate funding spanning across all the states in the United States of America has been analyzed for the last six presidential elections. A pattern emerging from how the corporate donations from the different sectors of the industry have been studied and inferences have been made accordingly.   
               
             </p>""",
                unsafe_allow_html=True)

    st.write("""
             ## Party-wise Donations 
             """)
    # Desription -
    st.markdown("""
                <p style='text-align: justify;'> 
             For each of the states, the donations made to both the political parties: Republicans and Democrats have 
             been analyzed and the impact of these corporate funding have been analyzed on how they determine the final
              outcome. For this purpose, all these companies have been divided into different sectors depending on their
               area of operation and the donation patterns for each of these companies have been analyzed over the past 
               presidential elections and the factors promoting such behavior have been scrutinized for future analysis.
             
             
             For a detailed analysis of these party wise donations, an interactive plot has been shown for both the 
            parties with the help of bubble plots.
            </p>""",
                unsafe_allow_html=True)

    st.write(" ")

    col1, col2, col3 = st.beta_columns((1, 1.5, 1))
    party_selected_don = col2.selectbox("Select Party - ",
                                        ["Democrats", "Republicans"])

    # Getting the state wise graph -
    get_state_wise_graph(party_selected_don)

    # Getting inference -
    st.write("")
    st.write("""
             ### **Plot Overview: **
            """)
    st.markdown("""
                <p style='text-align: justify;'>          
            The headquarters for each of the corporations have been stated. For each of the Presidential campaigns from 2000 to 2020, the bubble plot clearly shows how the donations shift from one party to the other depending on the field of operation of each company. The headquarters have been appended on the left so as to give an idea of how the donation pattern of the companies depend on the state where it operates its major businesses in. 
            </p>""",
                unsafe_allow_html=True)
    st.markdown("""
                <p style='text-align: justify;'>         
            In the bubble plot above, the Transportation companies (FedEx, 
            UPS etc.) have stayed loyal to the Republican party which can be estimated by the massive amount of 
            donations that have been made to the party irrespective of the outcome of the elections. Similarly, 80% of 
            the Tech companies and the Labor Unions have remained loyal to the Democratic Party in the subsequent 
            elections. The Finance and Real Estate companies, baring a few, are the only sector of companies which have 
            shifted their allegiance in each Presidential campaign and have been successful in gauging the winning party
             in most of the cases. Another important observation that can be made in this case is that the major donors 
             of the Republican party in all of these Presidential campaigns have their headquarters located in smaller 
             states, mostly in Michigan and Wisconsin, where as most of the major donors of the Democratic party have 
             their headquarters centered in New York and California.
             </p>""",
                unsafe_allow_html=True)

    # Year-wise Donations -
    st.write("""
             ## Year-wise Donations 
             """)
    st.markdown("""
                <p style='text-align: justify;'>
                We further explore the Donation data 
             over the years to get some insights. We analyzed the Corporate Donation data for the last three 
             Presidential elections. All the money that has been donated by the companies during the non-election years 
             have been taken into account for the next Presidential year. For example, if we have the company wise 
             donation data for 2014 and 2016, we added the donation received by the Political parties in 2014 to the
             donation data received in 2016 so that we have a cumulative donation received by the Political parties 
             during the Political campaign years. 
              
             </p>""",
                unsafe_allow_html=True)

    # Getting the year wise graph -
    get_year_wise_graph()

    # Inference/Result/Analysis (Insights)
    st.write("""
             ### Inference/Result/Analysis 
             """)
    st.markdown("""
                <p style='text-align: justify;'>
                The above visualization shows a relation between the money donated 
              to the Republications vs. the money donated to the Democrats over the years by the Corporate Industries.  
              The size of the circle gives a relative understanding of the amount of money donated to the Political 
              parties. The x-axis gives the estimate of the money donated to the Democrats while the y-axis gives the 
              estimate of the money donated to the Republicans. Thus, more the circle is leaning towards the x-axis, more
              the money is invested onto Democrats and vice versa. The color of the circle denotes the category or the sector
               of industry into which the company belongs to. Let's look into the year-wise analysis:
               </p>""",
                unsafe_allow_html=True)
    st.markdown("""
                <p style='text-align: justify;'>           
                
                * **2012:** Most of the donations came from Miscellaneous Business, Financial and Real Estate institutions 
             and Labor based industries. Las Vegas Sands is the biggest contributor from Miscellaneous Business and most
             of the money has been donated to the Republicans. The majority of the companies belonging to the labor 
             industry donated to the Democrats. The money donated by Financial institutions is scattered between both
             Democrats and Republicans.
             * **2016:** The major donors were still the Miscellaneous Business, Financial institutions, Labor and 
             Healthcare institutions. Las Vegas Sands is still the biggest contributor from Miscellaneous Business and 
             most of the money has been donated to the Republicans. Majority of Financial Institutions supported the 
             Democrats this time. Labor industry continued their support for Democrats. 
             * **2020:** The money donations have significantly increased as denoted by the size of the circles. The 
             biggest contributors to the Democrats were the Financial institutions. Miscellaneous Business still 
             supported the Republicans irrespective of the election year. Similarly, the money donated by the labor 
             industries have increased but they stayed loyal to the Democrats and continued their support. 
                     
             </p>""",
                unsafe_allow_html=True)

    # Financial Organization -
    st.write("""
             ## Donations by Financial Organizations 
             """)
    st.markdown("""
                <p style='text-align: justify;'>           
                
             The Financial institutions, Insurance 
             companies and the Real Estate companies made significant donations to the Political parties and their 
             contributions have swung a lot over the years. These institutions were not loyal in particular to any party
             and they mostly invested in the Political parties that they thought would likely win during that
              Presidential year. 
             </p>""",
                unsafe_allow_html=True)

    # Get financial graph
    get_financial_organization_graph()

    # Getting inference -
    st.write("")
    st.markdown("""
                <p style='text-align: justify;'> 
            During the 2012 Presidential elections, the donations received were mostly 
            scattered between the Democrats and the Republicans. Although some of the companies like Perry Homes and 
            Hugo Enterprises donated mostly to the Republicans, majority of the donations were made to the Democrats.
            
            In 2016, the donations were spaced out almost equally between the Democrats and the Republicans. Companies 
            like Bloomberg LP is one of those few companies who have not donated significantly in the past elections 
            campaigns except for 2016 and 2020. 
            
            In 2020, most of the companies shifted their major chunks to the Democratic Party barring Citadel LLC, Ryan 
            Speciality group and Stephens Group which stayed loyal to the Republicans. Companies like Renaissance
             Technologies continued their support to the Democrats irrespective of the election year.
            </p>""",
                unsafe_allow_html=True)

    # Educational Organization -

    # Get financial graph
    get_educational_graph()

    # Getting inference -
    st.write("")
    st.markdown("""
                <p style='text-align: justify;'> 
            Educational institutions also lent their support in the US Presidential Campaigns. In all the campaigns until
            now, the educational institutions, due to the diversity in their student population have donated unanimously
             to the Democratic party.
            </p>""",
                unsafe_allow_html=True)
示例#17
0
image1 = Image.open('clay-banks-_Jb1TF3kvsA-unsplash.jpg')

#make the user to enter the password to show the analysis
password = st.sidebar.text_input("Enter the password please", type="password")

if password == '123456':

    #add a radio buttons options on the sidebar for the user to select what he wants to see
    button = st.sidebar.radio(
        'Select which Analysis Date you want to See:',
        ('Info Page', 'Dates Between 2002 and 2008 Pages',
         'Dates Between 2011 and 2018 Pages'))

    if button == 'Info Page':

        st.title('Health Care Analysis in the United Arab Emirates:')
        col1, col2 = st.beta_columns(2)

        col1.image(image, use_column_width=True)

        col2.image(image1, use_column_width=True)

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

    elif button == 'Dates Between 2002 and 2008 Pages':

        #add a second radio button to filter based on the different analysis in this date
        button1 = st.sidebar.radio(
            'Select which Analysis you want to see:',
            ('Analysis of Death Cases based on the Cause, Gender Location',
             'Analysis of New Born Babies', 'Analysis of Blood Units usage'))
示例#18
0
def network_analysis():
    # Setting the title -
    st.title("Network Analysis")

    # Dividing into 2 parts -
    col1, col2, col3 = st.beta_columns((1, 0.1, 1))

    # Setting the image -
    image = Image.open('Images/network_photo.png')

    # Setting the image width -
    col1.image(image, use_column_width=True)

    # Writing description -
    col3.markdown("""
                <p style='text-align: justify;'>
                Topological Data Analysis is a clustering algorithm that relies on topology and 
               creates a Cech complex of a point-cloud. Using persistent diagrams, the number of 
               clusters is calculated. From there, using t-distributed stochastic neighbor embedding, 
               the data is projected in a manner such that some properties are preserved. After the 
               projection, a clustering algorithm along with covering balls is applied to the dataset 
               to obtain a 3-dimensional graph. The hyperparameters are autotuned based on the variance 
               and mean valency of the graph. Lastly, the graph is colored according to different 
               attributes associated with the original dataset to provide better visualization.
                
                <p> 
                """,
                  unsafe_allow_html=True)

    st.write("""
             ## Inference 
             
             """)
    st.markdown("""
               <p style='text-align: justify;'> 
               There are some great insights from this model, specifically on the clustering part. 
             There is one cluster with states where DEMOCRATS won and their expense is around the 
             same as republicans. Similarly, there is another one where REPUBLICANS won, which gives 
             us some information on the states where parties spend a similar amount of money and the 
             people tend to vote for the same party. Another cluster has states where democrats did not 
             spend more than the Republicans, but still, they won, which says that the state is blue. 
             These insights were helpful in understanding the relationship between expenditure and 
             voting in different states. 
             <p> 
             """,
                unsafe_allow_html=True)

    st.write(" ")
    st.write("""
             You can go to the network analysis by clicking on the link. Below is a snapshot of the network analysis.
             """)

    # To access the network analysis, press the button below -
    st.write("")
    col1, col2, col3 = st.beta_columns((1, 1, 1))
    link = '[Go to Network Analysis](https://lucky301910.github.io./)'
    col2.markdown(link, unsafe_allow_html=True)
    # url = 'https://ritesh-suhag.github.io./'
    # if col2.button("Go to the Network Analysis"):
    #     webbrowser.open_new_tab(url)

    st.write(" ")
    # Setting the image -
    image = Image.open('Images/Network_Analysis.png')

    # Setting the image width -
    st.image(image, use_column_width=True)
示例#19
0
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 25 13:41:11 2020

@author: harsh
"""
from nudity import Nudity
import streamlit as st
from PIL import Image
import os
st.title("obsenity filter")


def nudity_filter(file):
    nudity = Nudity()
    if nudity.has(file) == True:
        statement = 'image is above obsenity threshold'
        return (nudity.score(file), statement)


uploaded_file = st.file_uploader("Choose an image...", type="jpg")


#uploaded_file = st.file_uploader("Choose a file", type=['txt', 'jpg'])
def file_selector(folder_path='.'):
    filenames = os.listdir(folder_path)
    selected_filename = st.selectbox('Select a file', filenames)
    return os.path.join(folder_path, selected_filename)


filename = file_selector()
示例#20
0
def authors():
    # Setting the title -
    st.title("About the Authors")
    st.write(" ")

    # Dividing screen into 2 parts -
    col1, col2, col3 = st.beta_columns((0.75, 0.1, 2))

    # Setting the image -
    image = Image.open('Images/ritesh.png')

    # Setting the image width -
    col1.image(image, use_column_width=True)

    # Ritesh Singh Suhag -
    col3.write("## Ritesh Singh Suhag")

    # About section -
    col3.write("""
               Aspiring data scientist focused on executing data-driven solutions. Experienced at creating predictive models and analyzing raw data 
               to deliver insights and implement action-oriented solutions to complex business problems.  
               
               * **University:** Texas A&M University (Mays Business School)
               * **Degree:** MS in Management Information Systems (May 2021)
               * **Email:** [email protected]
               * **LinkedIn:** [linkedin.com/in/ritesh-singh-suhag/](https://www.linkedin.com/in/ritesh-singh-suhag/)
               * **Github:** [github.com/ritesh-suhag](https://www.github.com/ritesh-suhag)
               """)
    st.write(" ")

    # Dividing screen into 2 parts -
    col1, col2, col3 = st.beta_columns((0.75, 0.1, 2))

    # Setting the image -
    image = Image.open('Images/tushar.png')

    # Setting the image width -
    col1.write("")
    col1.image(image, use_column_width=True)

    # Ritesh Singh Suhag -
    col3.write("## Tushar Pandey")

    # About section -
    col3.write("""
               Research Area: Quantum Topology and Compressed Sensing     
               
               * **University:** Texas A&M University (Department of Mathematics)
               * **Degree:** PhD Student (2024) 
               * **Email:** [email protected]
               * **LinkedIn:** [linkedin.com/in/tushar-pandey1612/](https://www.linkedin.com/in/tushar-pandey1612/)
               * **Github:** [github.com/pandey-tushar](https://github.com/pandey-tushar)
               """)
    st.write("")

    # Dividing screen into 2 parts -
    col1, col2, col3 = st.beta_columns((0.75, 0.1, 2))

    # Setting the image -
    image = Image.open('Images/sambandh.png')

    # Setting the image width -
    col1.write("")
    col1.write("")
    col1.image(image, use_column_width=True)

    # Ritesh Singh Suhag -
    col3.write("## Sambandh Dhal")

    # About section -
    col3.write("""
               Research Area: Error Estimation and Machine Learning.
               
               * **University:** Texas A&M University (Department of Electrical and Computer Engineering)
               * **Degree:** PhD Student (Computer Engineering) 
               * **Email:** [email protected]
               * **LinkedIn:** [linkedin.com/in/sambandh-dhal9163/](https://www.linkedin.com/in/sambandh-dhal9163/)
               * **Github:** [github.com/Sambandh](https://github.com/Sambandh)
               """)
    st.write("")

    # Dividing screen into 2 parts -
    col1, col2, col3 = st.beta_columns((0.75, 0.1, 2))

    # Setting the image -
    image = Image.open('Images/swarnabha.png')

    # Setting the image width -
    col1.write("")
    col1.write("")
    col1.image(image, use_column_width=True)

    # Ritesh Singh Suhag -
    col3.write("## Swarnabha Roy")

    # About section -
    col3.write("""
               Research Area: Modular Robotics and Virtual Reality.
               
               * **University:** Texas A&M University (Department of Electrical and Computer Engineering)
               * **Degree:** PhD Student (Computer Engineering) 
               * **Email:** [email protected]
               * **LinkedIn:** [linkedin.com/in/swarnabha-roy-53a588a4/](https://www.linkedin.com/in/swarnabha-roy-53a588a4/)
               * **Github:** [github.com/swarnabha13](https://github.com/swarnabha13)
               """)
    st.write("")
示例#21
0
    "JPM",
    "WOL Subject",
    "Ownership",
    "Rejected Percentage",
    "Contributing?",
    "Desk Rejected?",
]]
final_merge.rename(
    columns={
        "Rejected Percentage": "%age Chinese Articles Rejected",
        "Contributing?": "%age of rejects with 2YrC > JIF",
        "Desk Rejected?": "%age Desk Rejections ",
    })

# %%
st.title("EBF Team Chinese Article Analysis")
st.write(
    "*All analysis is based on direct exports from Qlik: Submissions by Title (JEVA) and Cascade by Title (Submissions Dashboard). Data correct as of 14th May 2021*"
)
st.write(
    "Please bear in mind that what follows represents a proof of concept and is still rough around the edges. Any and all feedback is greatly appreciated."
)
st.write("---")
st.write(
    "As a reminder, the below list was pulled together by analysing all titles within the EBF portfolio, and selecting those that were in the 75th percentile or above for both submissions and rejections for content from Chinese First Authors."
)
st.write(
    "You can expand the list using the arrows to the top right of the dataframe."
)
st.write(ebf_target_list)
st.write("---")
示例#22
0
    'brown': '#a52a2a',
    'cyan': '#00ffff',
    'grey': '#808080',
    'green': '#008000',
    'magenta': '#ff00ff',
    'maroon': '#800000',
    'orange': '#ffa500',
    'pink': '#ffc0cb',
    'red': '#ff0000',
    'white': '#ffffff',
    'yellow': '#ffff00'
}

st.set_option('deprecation.showfileUploaderEncoding', False)
st.beta_set_page_config(page_title='BirdsPyView', layout='wide')
st.title('Upload Image or Video')
uploaded_file = st.file_uploader("Select Image file to open:",
                                 type=["png", "jpg", "mp4"])
pitch = FootballPitch()

if uploaded_file:
    if uploaded_file.type == 'video/mp4':
        play = Play(uploaded_file)
        t = st.slider(
            'You have uploaded a video. Choose the frame you want to process:',
            0.0, 60.0)
        image = PitchImage(pitch, image=play.get_frame(t))
    else:
        image = PitchImage(pitch, image_bytes=uploaded_file)

    st.title('Pitch lines')
示例#23
0
import streamlit as st
import pandas as pd

mobileData_df = pd.read_csv('Pricing_model.csv')
Dep_prediction_df = pd.read_csv('Price_depriciation_value.csv')

st.title("Save Nature, recycle Electronics")
st.write("""
Get the best value for your Used Mobile's \n

""")

model_name = st.selectbox(
    "Select your model",
    ("Iphone 12", "Oneplus 8", "Samsung S21", "Xiaomi Mi 10"))
st.write("Thanks for opting to recycle ", model_name)
is_working = st.radio('Is it in working condition ?', ['Yes', 'No'])
#st.write(is_working)
#months_used = st.slider("Number of months used ", min_value=1, max_value=60)

st.sidebar.image('./Ways-In-Which-Recycling-Helps-Our-Environment.png')
st.sidebar.title('Team Declutter')
st.sidebar.image('./Team.jpg')

index = 0
for ind in mobileData_df['Mobile']:
    #print(ind)
    if ind == model_name:
        mob_ind = index
    index = index + 1
示例#24
0
import streamlit as st
import numpy as np
import pandas as pd
from PIL import Image
import time

st.title('Streamlit')
"""
## プログレスバー
"""
# latest_iteration = st.empty()
# bar = st.progress(0)

# for i in range(100):
#     latest_iteration.text(f'Iteration {i+1}')
#     bar.progress(i+1)
#     time.sleep(0.1)
"""
## expander
"""
expander1 = st.beta_expander('問い合わせ1')
expander1.write('問い合わせ1の回答')

expander2 = st.beta_expander('問い合わせ2')
expander2.write('問い合わせ2の回答')

expander3 = st.beta_expander('問い合わせ3')
expander3.write('問い合わせ3の回答')
"""
## レイアウト変更(2カラムの例)
"""
示例#25
0
from sklearn.metrics import precision_recall_fscore_support as score


@st.cache
def load_data(nrows):
    df = pd.read_csv("df.csv", nrows=nrows)
    return df


df = load_data(99794)

page = st.sidebar.selectbox("Choose a page",
                            ['Homepage', 'Exploration', 'Prediction'])

if page == 'Homepage':
    st.title('Bank Loan Payment Classifier')

    data_load_state = st.text('Loading data...')
    data_load_state.text('Loading data...done!')

    if st.checkbox('Show the dataframe'):
        st.write(df.head(5))

elif page == 'Exploration':
    st.markdown('### Analysing column relations')
    st.write('Correlations:')
    rel = df.drop(columns=['Loan Status']).corrwith(df['Loan Status'])
    rel = rel.sort_values(ascending=False)
    rel = rel[:10]
    if st.checkbox('Show the Analysing column relations'):
        st.write(rel)
示例#26
0
def app():
    st.title('Orientation')

    st.write(
        '**This page will show the graphs and tables based on the Faculty Particpation in Orientation**'
    )

    data = st.file_uploader("Upload your relevant excel file")
    df = pd.read_csv(data)

    page_names = ["Department", "Faculty"]
    page = st.radio("", page_names, index=0)

    if page == "Department":
        col1, col2, col3, col4 = st.beta_columns(4)
        with col1:
            temp1 = st.button("Semester wise")
        with col2:
            temp2 = st.button("Year wise")
        with col3:
            temp3 = st.button("Venue")
        with col4:
            temp7 = st.button("University wise")

    if page == "Department":
        if temp1 == True:
            df['Date'] = df['Date'].astype('datetime64[ns]')

            df_1 = df['Date'].dt.year
            col = []
            for i in df_1:
                col.append(i)
            col = list(set(col))

            df1 = pd.DataFrame(data=None, columns=['Count'])
            for i in col:
                mask = (df['Date'] > str(i) + '0615') & (df['Date'] <=
                                                         str(i) + '1215')
                mask1 = (df['Date'] > str(i) + '1215') & (df['Date'] <=
                                                          str(i + 1) + '0615')
                test5 = df.loc[mask]
                test6 = df.loc[mask1]
                c1 = test5['Date']
                c2 = test6['Date']
                t1 = c1.shape[0]
                t2 = c2.shape[0]
                t1 = pd.DataFrame([t1],
                                  columns=['Count'],
                                  index=['ODD sem ' + str(i)])
                df1 = df1.append(pd.DataFrame(t1))
                t2 = pd.DataFrame([t2],
                                  columns=['Count'],
                                  index=['EVEN sem ' + str(i)])
                df1 = df1.append(pd.DataFrame(t2))

            st.write('**Table based on Sem-Wise Count for whole Department**')

            st.table(df1)
            st.write('**Graph based on Sem-Wise Count for whole Department **')

            st.bar_chart(df1)

    if page == "Department":
        if temp2 == True:

            df['Date'] = df['Date'].astype('datetime64[ns]')
            df_1 = df['Date'].dt.year
            col = []
            for i in df_1:
                col.append(i)
            col = list(set(col))
            df2 = pd.DataFrame(data=None, columns=['Count'])
            for i in col:
                mask = (df['Date'] > str(i) + '0615') & (df['Date'] <=
                                                         str(i + 1) + '0615')
                test5 = df.loc[mask]
                c1 = test5['Date']
                t1 = c1.shape[0]
                t1 = pd.DataFrame([t1],
                                  columns=['Count'],
                                  index=[str(i) + '-' + str(i + 1)])
                df2 = df2.append(pd.DataFrame(t1))

            st.write('**Table based on Year-Wise Count for whole Department**')

            st.table(df2)
            st.write(
                '**Graph based on Year-Wise Count for whole Department **')

            st.bar_chart(df2)

    if page == "Department":
        if temp3 == True:
            df2 = pd.DataFrame(data=None, columns=['Count'])

            totalr = len(df[df['Venue'] == 'RAIT'])
            totalr = totalr

            totall = len(df['Venue'])

            totald = totall - totalr

            t1 = pd.DataFrame([totalr], columns=['Count'], index=['RAIT'])
            df2 = df2.append(pd.DataFrame(t1))

            t1 = pd.DataFrame([totald],
                              columns=['Count'],
                              index=['Other Universities'])
            df2 = df2.append(pd.DataFrame(t1))

            st.write(
                '**Table based on Venue-Wise Count for whole Department**')

            st.table(df2)
            st.write(
                '**Graph based on Venue-Wise Count for whole Department **')

            st.bar_chart(df2)

    if page == "Department":
        if temp7 == True:

            df2 = pd.DataFrame(data=None, columns=['Count'])

            totalm = len(df[df['NameofUniversity'] == 'University of Mumbai'])
            totalr = len(df[df['NameofUniversity'] == 'RAIT'])
            totall = len(df['NameofUniversity'])

            totald = totall - totalm - totalr

            t1 = pd.DataFrame([totalm],
                              columns=['Count'],
                              index=['Mumbai University'])
            df2 = df2.append(pd.DataFrame(t1))

            t1 = pd.DataFrame([totalr], columns=['Count'], index=['RAIT'])
            df2 = df2.append(pd.DataFrame(t1))

            t1 = pd.DataFrame([totald],
                              columns=['Count'],
                              index=['Other Universities'])
            df2 = df2.append(pd.DataFrame(t1))

            st.write(
                '**Table based on University-Wise Count for whole Department**'
            )

            st.table(df2)
            st.write(
                '**Graph based on University-Wise Count for whole Department **'
            )

            st.bar_chart(df2)

    if page == "Faculty":

        col_one_list = df['NameOfFaculty'].tolist()

        col_one_list = list(set(col_one_list))

        df2 = pd.DataFrame(data=None, columns=['Count'])
        df1 = df
        faculties = df1["NameOfFaculty"].unique()
        faculty = st.selectbox('Select the name of the faculty:', faculties)
        j = col_one_list.index(faculty)

        df['Date'] = df['Date'].astype('datetime64[ns]')

        df_1 = df['Date'].dt.year

        col = []
        for i in df_1:
            col.append(i)
        col = list(set(col))

        for i in col:
            mask = (df['Date'] > str(i) + '0615') & (
                df['Date'] <= str(i + 1) + '0615') & (df['NameOfFaculty']
                                                      == str(col_one_list[j]))

            test5 = df.loc[mask]
            c1 = test5['Date']
            t1 = c1.shape[0]
            t1 = pd.DataFrame([t1],
                              columns=['Count'],
                              index=[str(i) + '-' + str(i + 1)])
            df2 = df2.append(pd.DataFrame(t1))
        st.write('**Table based on Year-Wise Count for Faculty**')

        st.table(df2)
        st.write('**Graph based on Year-Wise Count for Faculty **')

        st.bar_chart(df2)

        df4 = pd.DataFrame(data=None, columns=['Count'])

        for i in col:
            mask = (df['Date'] > str(i) + '0615') & (
                df['Date'] <= str(i) + '1215') & (df['NameOfFaculty'] == str(
                    col_one_list[j]))
            mask1 = (df['Date'] > str(i) + '1215') & (
                df['Date'] <= str(i + 1) + '0615') & (df['NameOfFaculty']
                                                      == str(col_one_list[j]))
            test5 = df.loc[mask]
            test6 = df.loc[mask1]
            c1 = test5['Date']
            c2 = test6['Date']
            t1 = c1.shape[0]
            t2 = c2.shape[0]
            t1 = pd.DataFrame([t1],
                              columns=['Count'],
                              index=['ODD sem ' + str(i)])
            df4 = df4.append(pd.DataFrame(t1))
            t2 = pd.DataFrame([t2],
                              columns=['Count'],
                              index=['EVEN sem ' + str(i)])
            df4 = df4.append(pd.DataFrame(t2))
        st.write('**Table based on Sem-Wise Count for Faculty**')

        st.table(df4)
        st.write('**Graph based on Sem-Wise Count for Faculty **')

        st.bar_chart(df4)

        data1 = df.loc[df['NameOfFaculty'] == str(col_one_list[j])]

        df5 = pd.DataFrame(data=None, columns=['Count'])

        totalm = len(
            data1[data1['NameofUniversity'] == 'University of Mumbai'])
        totalr = len(data1[data1['NameofUniversity'] == 'DYPU'])
        totall = len(data1['NameofUniversity'])

        totald = totall - totalm - totalr

        t1 = pd.DataFrame([totalm],
                          columns=['Count'],
                          index=['Mumbai University'])
        df5 = df5.append(pd.DataFrame(t1))

        t1 = pd.DataFrame([totalr], columns=['Count'], index=['RAIT'])
        df5 = df5.append(pd.DataFrame(t1))

        t1 = pd.DataFrame([totald],
                          columns=['Count'],
                          index=['Other Universities'])
        df5 = df5.append(pd.DataFrame(t1))

        st.write('**Table based on University-Wise Count for Faculty**')

        st.table(df5)
        st.write('**Graph based on University-Wise Count for Faculty **')

        st.bar_chart(df5)

        df6 = pd.DataFrame(data=None, columns=['Count'])

        data1 = df.loc[df['NameOfFaculty'] == str(col_one_list[j])]

        totalr = len(data1[data1['Venue'] == 'RAIT'])
        totalo = len(data1[data1['Venue'] == 'Online'])
        totalr = totalr + totalo

        totall = len(data1['Venue'])

        totald = totall - totalr

        t1 = pd.DataFrame([totalr], columns=['Count'], index=['RAIT'])
        df6 = df6.append(pd.DataFrame(t1))

        t1 = pd.DataFrame([totald],
                          columns=['Count'],
                          index=['Other Universities'])
        df6 = df6.append(pd.DataFrame(t1))

        st.write('**Table based on Venue-Wise Count for Faculty**')

        st.table(df6)
        st.write('**Graph based on Venue-Wise Count for Faculty **')

        st.bar_chart(df6)
import seaborn as sns
from scipy import stats
import mpl_toolkits
from datetime import datetime
import os, time, sys
from pandas import DataFrame

from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score, mean_squared_error
from sklearn.metrics import accuracy_score
from sklearn import tree

st.title('Waka Waka Seattle Home Prices')
st.write("""
Our app predicts the **Seattle House Price**!
""")
st.write('---')

from PIL import Image
img = Image.open("seattle.jpg")
st.image(img)
st.write('---')
st.subheader("""
Home Prices Predicted Using Machine Learning
""")

df = pd.read_csv('clean1.csv')
示例#28
0
def main():
    menu = ["Home", "About"]
    choice = st.sidebar.selectbox("Menu", menu)

    st.title("DevDeeds -Search Jobs")

    if choice == "Home":
        st.subheader("Home")

        # Nav  Search Form
        with st.form(key='searchform'):
            nav1, nav2, nav3 = st.beta_columns([3, 2, 1])

            with nav1:
                search_term = st.text_input("Search Job")
            with nav2:
                location = st.text_input("Location")

            with nav3:
                st.text("Search ")
                submit_search = st.form_submit_button(label='Search')

        st.success("You searched for {} in {}".format(search_term, location))

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

        with col1:
            if submit_search:
                # Create Search Query
                search_url = base_url.format(search_term, location)
                # st.write(search_url)
                data = get_data(search_url)

                # Number of Results
                num_of_results = len(data)
                st.subheader("Showing {} jobs".format(num_of_results))
                # st.write(data)

                for i in data:
                    job_title = i['title']
                    job_location = i['location']
                    company = i['company']
                    company_url = i['company_url']
                    job_post_date = i['created_at']
                    job_desc = i['description']
                    job_howtoapply = i['how_to_apply']
                    st.markdown(JOB_HTML_TEMPLATE.format(
                        job_title, company, job_location, job_post_date),
                                unsafe_allow_html=True)

                    # Description
                    with st.beta_expander("Description"):
                        stc.html(JOB_DES_HTML_TEMPLATE.format(job_desc),
                                 scrolling=True)

                    # How to Apply
                    with st.beta_expander("How To Apply"):
                        # stc.html(job_howtoapply) # For White Theme
                        stc.html(JOB_DES_HTML_TEMPLATE.format(job_howtoapply),
                                 scrolling=True)  # For Dark Theme

        with col2:
            with st.form(key='email_form'):
                st.write("Be the first to get new jobs info")
                email = st.text_input("Email")

                submit_email = st.form_submit_button(label='Subscribe')

                if submit_email:
                    st.success("A message was sent to {}".format(email))

    else:
        st.subheader("About")
示例#29
0
            s2s_tokenizer,
            num_answers=1,
            num_beams=n_beams,
            min_len=min_len,
            max_len=max_len,
            do_sample=sampling,
            temp=temp,
            top_p=top_p,
            top_k=None,
            max_input_length=1024,
            device="cuda:0",
        )[0]
    return (answer, support_list)


st.title("Long Form Question Answering with ELI5")

# Start sidebar
header_html = "<img src='https://huggingface.co/front/assets/huggingface_logo.svg'>"
header_full = """
<html>
  <head>
    <style>
      .img-container {
        padding-left: 90px;
        padding-right: 90px;
        padding-top: 50px;
        padding-bottom: 50px;
        background-color: #f0f3f9;
      }
    </style>
示例#30
0
def app():

    # Title
    st.title('K-means Clustering')

    # Introduction
    st.markdown(r'''
    Firstly, we need to explain unsupervised learning before we move onto K-means clustering. Unsupervised learning involves using input features (x) to predict an output (y). We try to find an underlying pattern or structure given unlabeled data.

    K-means Clustering is an iterative algorithm that loops until it converges to a solution. There are two methods in applying K-means clustering:

    (1) Standard

    (2) K-means +++

    #### Standard

    ##### Pseudocode

        Input: X array, K (number of clusters) integer, u = 0 (cluster center)
        for n ~ 1 to N:
            r_n = [0, 0, ..., 0]
            k = RandomInteger (1, K) 
            r_nk = 1 
        end for
        repeat
            for k ~ 1 to K:
                N_k = \sum_{n = 1}^N r_{nk} 
                 \mu_k = \frac{1}{N_k} \sum_{n = 1}^{N} r_{nk} x_n
            end for
            for n ~ 1 to N:
                r_n = [0, 0, ..., 0]       
                k =  arg min_k||x_n - \mu_k||^2 
                r_{nk} = 1 
            end for
        Return labels from r (responsibility vector) and u cluster means

    #### K-means +++
    K-means +++ is very similar to the standard algorithm.
    However, there is one modification in how the cluster centers are initialized.
    We set the first cluster centers as a random sample from the data. Then, we loop over the rest of the cluster centers.

    ##### Pseudocode
        Input: X array, K (number of clusters) integer, u = 0
        n = RandomInteger(1, N) 
        u_1 = x[n]
        for k ~ 2 to K:
            for n ~ 1 to N:
                d_n = min ||x_n - \mu_k ||^2 
            end for
            for n ~ 1 to N:
                 p_n = \frac{d_n^2}{\sum_n * d_n^2} 
            end for
         n = Discrete(p_1, p2, ..., p_N) 
         u_k = x_n 
        end for 
        Return cluster means

        Begin the rest of the K-means Algorithm

    ''')

    # Split into two columns for PROS and CONS
    col1, col2 = st.beta_columns(2)

    # Pros
    with col1:
        st.markdown(''' 
            #### Pros

            * Relatively simple to implement.

            * Scales to large data sets.

            * Guarantees convergence.

            ''')

    # Cons
    with col2:
        st.markdown(''' 
            #### Cons

        * Computationally intense
            * t - number of iterations

            * k - Number of cluster centers
            
            * n - number of points
            
            * d - number of dimensions
            
            * Algorithmic complexity of O(t  k  n  d)

        * Choosing k manually.

        * Clustering outliers.

        * Scaling with number of dimensions.
            ''')

    # Implementation code
    st.markdown('''
            ### Implementation
            [K-means Clustering](https://github.com/SulmanK/MLalgos/blob/main/Algos/model/kmeans.py)



            ''')

    # Insert parameters
    st.markdown('''

        #### Scatterplot of K-means Clustering


        ''')

    col1, col2 = st.sidebar.beta_columns(2)

    # Data parameters
    with col1:
        st.markdown(''' 
            #### Data parameters

            ''')
        classes_widget = st.radio('Classes', [2, 3, 4])
        number_of_samples_widget = st.slider('Number of samples',
                                             min_value=20,
                                             max_value=300,
                                             value=50)

    # Algorithm parameters
    with col2:
        st.markdown(''' 
            #### Algorithm parameters
            ''')

        method_widget = st.radio('Method', ['K-means', 'K-means +++'])
        num_cluster_widget = st.slider('K', min_value=1, value=2, max_value=4)
        iterations_widget = st.slider('Iterations',
                                      min_value=3,
                                      value=100,
                                      max_value=1000)

    # Get data
    X_train, X_test, y_train, y_test = get_sample_data(
        num_classes=classes_widget, num_samples=number_of_samples_widget)

    # Callback function used for populating comparison plots

    @st.cache(allow_output_mutation=True)
    def plots(X_train, X_test, y_train, y_test):

        fig = ScatterPlot_Kmeans(
            X_train=X_train,
            X_test=X_test,
            method=method_widget,
            k=num_cluster_widget,
            iterations=iterations_widget,
        )

        return fig

    # Display the plot
    sl_plot = plots(X_train=X_train,
                    X_test=X_test,
                    y_train=y_train,
                    y_test=y_test)

    st.pyplot(sl_plot)