if st.button("Analyze"): st.info("Original Text:\n{}".format(news_text)) docx = nlp(news_text) if task_choice == 'Tokenization': result = [token.text for token in docx] if task_choice == 'NER': result = [(entity.text, entity.label) for entity in docx.ents] if task_choice == 'POS Tags': result = [ "'Token':{}, 'POS': {}, 'Dependency': {}".format( word.text, word.tag_, word.dep_) for word in docx ] st.json(result) if st.button("Tabulize"): docx = nlp(news_text) c_tokens = [token.text for token in docx] c_lemma = [(token.text, token.lemma_) for token in docx] c_pos = [(word.text, word.tag_, word.dep_) for word in docx] new_df = pd.DataFrame(zip(c_tokens, c_lemma, c_pos), columns=['Tokens', 'Lemma', 'POS']) st.dataframe(new_df) if st.checkbox("Wordcloud"): wordcloud = WordCloud().generate(news_text) plt.imshow(wordcloud, interpolation='bilinear') plt.axis("off")
.round(2).sort_values("price", ascending=False)\ .assign(avg_price=lambda x: x.pop("price").apply(lambda y: "%.2f" % y))) st.header("Which host has the most properties listed?") listingcounts = df.host_id.value_counts() top_host_1 = df.query('[email protected][0]') top_host_2 = df.query('[email protected][1]') st.write( f"""**{top_host_1.iloc[0].host_name}** is at the top with {listingcounts.iloc[0]} property listings. **{top_host_2.iloc[1].host_name}** is second with {listingcounts.iloc[1]} listings. Following are randomly chosen listings from the two displayed as JSON using [`st.json`](https://streamlit.io/docs/api.html#streamlit.json).""" ) st.json({top_host_1.iloc[0].host_name: top_host_1\ [["name", "neighbourhood", "room_type", "minimum_nights", "price"]]\ .sample(2, random_state=4).to_dict(orient="records"), top_host_2.iloc[0].host_name: top_host_2\ [["name", "neighbourhood", "room_type", "minimum_nights", "price"]]\ .sample(2, random_state=4).to_dict(orient="records")}) st.header("What is the distribution of property price?") st.write( """Select a custom price range from the side bar to update the histogram below displayed as a Plotly chart using [`st.plotly_chart`](https://streamlit.io/docs/api.html#streamlit.plotly_chart).""" ) values = st.sidebar.slider("Price range", float(df.price.min()), float(df.price.clip(upper=1000.).max()), (50., 300.)) f = px.histogram(df.query(f"price.between{values}"), x="price", nbins=15, title="Price distribution")
def write(): """News Classifier""" st.title("Sentiments with Emoji") # st.subheader("ML App with Streamlit") html_temp = """ <div style="background-color:blue;padding:10px"> <h1 style="color:white;text-align:center;">Streamlit ML App </h1> </div> """ st.markdown(html_temp,unsafe_allow_html=True) activity = ['Prediction','NLP'] choice = st.sidebar.selectbox("Select Activity",activity) if choice == 'Prediction': st.info("Prediction with ML") news_text = st.text_area("Enter News Here","Type Here") all_ml_models = ["LR","RFOREST","NB","DECISION_TREE"] model_choice = st.selectbox("Select Model",all_ml_models) prediction_labels = {'business': 0,'tech': 1,'sport': 2,'health': 3,'politics': 4,'entertainment': 5} if st.button("Classify"): st.text("Original Text::\n{}".format(news_text)) vect_text = news_cv.transform([news_text]).toarray() if model_choice == 'LR': predictor = load_prediction_models("models/newsclassifier_Logit_model.pkl") prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'RFOREST': predictor = load_prediction_models("models/newsclassifier_RFOREST_model.pkl") prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'NB': predictor = load_prediction_models("models/newsclassifier_NB_model.pkl") prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'DECISION_TREE': predictor = load_prediction_models("models/newsclassifier_CART_model.pkl") prediction = predictor.predict(vect_text) # st.write(prediction) final_result = get_key(prediction,prediction_labels) st.success("News Categorized as:: {}".format(final_result)) if choice == 'NLP': st.info("Natural Language Processing of Text") raw_text = st.text_area("Enter News Here","Type Here") nlp_task = ["Tokenization","Lemmatization","NER","POS Tags"] task_choice = st.selectbox("Choose NLP Task",nlp_task) if st.button("Analyze"): st.info("Original Text::\n{}".format(raw_text)) docx = nlp(raw_text) if task_choice == 'Tokenization': result = [token.text for token in docx ] elif task_choice == 'Lemmatization': result = ["'Token':{},'Lemma':{}".format(token.text,token.lemma_) for token in docx] elif task_choice == 'NER': result = [(entity.text,entity.label_)for entity in docx.ents] elif task_choice == 'POS Tags': result = ["'Token':{},'POS':{},'Dependency':{}".format(word.text,word.tag_,word.dep_) for word in docx] st.json(result) if st.button("Tabulize"): docx = nlp(raw_text) c_tokens = [token.text for token in docx ] c_lemma = [token.lemma_ for token in docx ] c_pos = [token.pos_ for token in docx ] new_df = pd.DataFrame(zip(c_tokens,c_lemma,c_pos),columns=['Tokens','Lemma','POS']) st.dataframe(new_df) if st.checkbox("WordCloud"): c_text = raw_text wordcloud = WordCloud().generate(c_text) plt.imshow(wordcloud,interpolation='bilinear') plt.axis("off") st.pyplot() st.sidebar.subheader("About")
# st.title("커피 스누퍼스 인공지능 모델링") # if st.checkbox('checkbox'): # st.image(banner_image) ## Chapter 3 Pandas Data a = [1, 2, 3, 4, 5, 6, 7, 8] n = np.array(a) nd = n.reshape((2, 4)) dic = {"name": ["harsh", "Gupta"], "age": [21, 32], "city": ["noida", "delhi"]} data = pd.read_csv("media/Salary_Data.csv") # st.dataframe(data, width="100%", height=500) st.dataframe(data.head(5), width=600, height=500) st.table(data.head(3)) st.table(dic) st.json(dic) st.write(dic) @st.cache def ret_time(a): time.sleep(3) return "모델 정확도 : 0.982142354" # return time.time() if st.checkbox("1"): st.write(ret_time(1)) if st.checkbox("2"): st.write(ret_time(2))
def main(): """Car Evaluation with ML Streamlit App""" st.title("Car Evaluation") st.subheader("Streamlit ML App") #st.image(load_image("car_images/car.jpg"),width=300, caption='Images') activities = ['EDA','Prediction','About'] choices = st.sidebar.selectbox("Select Activity",activities) if choices == 'EDA': st.subheader("EDA") data = load_data('car_dataset.csv') st.dataframe(data.head(5)) if st.checkbox("Show Summary of Dataset"): st.write(data.describe()) # Show Plots if st.checkbox("Simple Value Plots "): st.write(data['class'].value_counts().plot(kind='bar')) st.pyplot() if st.checkbox("Select Columns To Show"): all_columns = data.columns.tolist() selected_columns = st.multiselect('Select',all_columns) new_df = data[selected_columns] st.dataframe(new_df) if st.checkbox("Pie Plot"): st.write(data['class'].value_counts().plot.pie(autopct="%1.1f%%")) st.pyplot() if choices == 'Prediction': st.subheader("Prediction") buying = st.selectbox('Select Buying Level',tuple(buying_label.keys())) maint = st.selectbox('Select Maintenance Level',tuple(maint_label.keys())) doors = st.selectbox('Select Doors',tuple(doors_label.keys())) persons = st.number_input('Select Num of Persons',2,10) lug_boot = st.selectbox("Select Lug Boot",tuple(lug_boot_label.keys())) safety = st.selectbox('Select Safety',tuple(safety_label.keys())) k_buying = get_value(buying,buying_label) k_maint = get_value(maint,maint_label) k_doors = get_value(doors,doors_label) # k_persons = get_value(persons,persons_label) k_lug_boot = get_value(lug_boot,lug_boot_label) k_safety = get_value(safety,safety_label) pretty_data = { "buying":buying, "maint":maint, "doors":doors, "persons":persons, "lug_boot":lug_boot, "safety":safety, } st.subheader("Options Selected") st.json(pretty_data) st.subheader("Data Encoded As") # Data To Be Used sample_data = [k_buying,k_maint,k_doors,persons,k_lug_boot,k_safety] st.write(sample_data) prep_data = np.array(sample_data).reshape(1, -1) model_choice = st.selectbox("Model Type",['logit','naive bayes','MLP classifier']) if st.button('Evaluate'): if model_choice == 'logit': predictor = load_prediction_models("logit_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) if model_choice == 'naive bayes': predictor = load_prediction_models("nb_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) if model_choice == 'MLP classifier': predictor = load_prediction_models("nn_clf_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) final_result = get_key(prediction,class_label) st.write("your prediction on buying a car is") st.success(final_result) if final_result =='unacceptable': st.write("please try to avoid these model,choose better features for your car") if final_result =='acceptable': st.write("you have choose some good features for your car") if final_result =='good': st.write("you have choosen some fantastic features for your car") if final_result =='very good': st.write("you have choosen excellent and advanced features for your car") if choices == 'About': st.subheader("About") st.write("This web app gives the prediction on wether to buy a car or not or can say that car is safe to buy on basis of certain parameters")
st.success(result) # Text Area message = st.text_area("Enter your meassage", "Type here ...") # if st.button("Submit"): # result = message.title() # st.success(result) # Date Input today = st.date_input("Today is", datetime.datetime.now()) # Time time = st.time_input("The time is ", datetime.time()) # Dislaying JSON st.text("Displaying JSON") st.json({"name": 'Abhi', "age": 20, "gender": "male"}) # Displaying Raw Code st.text("Displaying Raw Code") st.code("import numpy as np") # or with st.echo(): import pandas as pd df = pd.DataFrame() # Progress Bar my_bar = st.progress(0) for p in range(10): my_bar.progress(p + 1)
import streamlit as st st.title("Lists!") lists = [ [], [10, 20, 30], [[10, 20, 30], [1, 2, 3]], [[10, 20, 30], [1]], [[10, "hi", 30], [1]], [[{ "foo": "bar" }, "hi", 30], [1]], [[{ "foo": "bar" }, "hi", 30], [1, [100, 200, 300, 400]]], ] for i, l in enumerate(lists): st.header("List %d" % i) st.write("With st.write") st.write(l) st.write("With st.json") st.json(l) st.write("With st.dataframe") st.dataframe(l)
def main(): st.title('Simple Bioinformatics App') menu = ["DNA Sequence", "Dot Plot"] choice = st.sidebar.selectbox("Select Activity", menu) if choice == "DNA Sequence": st.subheader("DNA Sequence Analysis") seq_file = st.file_uploader("Upload FASTA File", type=["fasta", "fa"]) #text_io = io.TextIOWrapper(seq_file) if seq_file is not None: dna_record = SeqIO.read(seq_file, "fasta") #st.write(dna_record) dna_seq = dna_record.seq desc = dna_record.description details = st.radio("Details", ("Description", "Sequence")) if details == "Description": st.write(desc) elif details == "Sequence": st.write(dna_seq) # Nucleotide Frequencies st.subheader("Nucleotide Frequencies") dna_freq = Counter(dna_seq) st.write(dna_freq) adenine_color = st.beta_color_picker("Adenine Color") guanine_color = st.beta_color_picker("Guanine Color") thymine_color = st.beta_color_picker("Thymine Color") cytosil_color = st.beta_color_picker("Cytosil Color") if st.button("Plot Freq"): barlist = plt.bar(dna_freq.keys(), dna_freq.values()) barlist[0].set_color(adenine_color) barlist[1].set_color(thymine_color) barlist[2].set_color(guanine_color) barlist[3].set_color(cytosil_color) st.pyplot() st.subheader("DNA Composition") gc_score = utils.gc_content(str(dna_seq)) at_score = utils.at_content(str(dna_seq)) st.json({"GC Content ": gc_score, "AT Content ": at_score}) # Nucleotide Count nt_count = st.text_input("Enter Nucleotide Here", "Type Nucleotide Alphabet") st.write("Number of {} nucleotide is : {} ".format( (nt_count), str(dna_seq).count(nt_count))) # Protein Synthesis p1 = dna_seq.translate() aa_freq = Counter(str(p1)) st.subheader("Protein Synthesis") if st.checkbox("Transcription"): st.write(dna_seq.transcribe()) elif st.checkbox("Translation"): st.write(dna_seq.translate()) elif st.checkbox("Complement"): st.write(dna_seq.complement()) elif st.checkbox("AA Frequency"): st.write(aa_freq) elif st.checkbox("AA Plot Frequency"): #aa_color = st.beta_color_picker("Amino Acid Color") #barlist = plt.bar(aa_freq.keys(), aa_freq.values(), color = aa_color) plt.bar(aa_freq.keys(), aa_freq.values()) #barlist[0].set_color(aa_color) st.pyplot() elif st.checkbox("Full Amino Acid Name"): aa_name = str(p1).replace("*", "") st.write(aa_name) st.write("--------------------------") st.write(utils.convert_1to3(aa_name)) elif choice == "Dot Plot": st.subheader("Generate Dot Plot For Two Sequences") seq_file = st.file_uploader("Upload 1st FASTA File", type=["fasta", "fa"]) seq_file2 = st.file_uploader("Upload 2nd FASTA File", type=["fasta", "fa"]) # text_io = io.TextIOWrapper(seq_file) if seq_file and seq_file2 is not None: dna_record1 = SeqIO.read(seq_file, "fasta") dna_record2 = SeqIO.read(seq_file2, "fasta") # st.write(dna_record) dna_seq1 = dna_record1.seq dna_seq2 = dna_record2.seq desc1 = dna_record1.description desc2 = dna_record2.description details = st.radio("Details", ("Description", "Sequence")) if details == "Description": st.write(desc1) st.write("----------") st.write(desc2) elif details == "Sequence": st.write(dna_seq1) st.write("----------") st.write(dna_seq2) custom_limit = st.number_input("Select max number of Nucleotide ", 10, 200, 25) if st.button("Dot Plot"): st.write("Comparing the first {} Nucleotide of Two Sequences ". format(custom_limit)) dotplotx(dna_seq1[0:custom_limit], dna_seq2[0:custom_limit]) st.pyplot()
st.write("Press the above button..") # Date Input import datetime, time today = st.date_input("Today is", datetime.datetime.now()) # Time Input t = st.time_input("The time now is", datetime.time()) # SIDE Bar st.sidebar.header("Side Bar Header") st.sidebar.text("Hello") # Display JSON st.text("Display JSON") st.json({'name': 'hello', 'age': 34}) # Display Raw Code st.text("Display Raw Code") st.code("import numpy as np") st.text("Display Raw Code Alternative Method") with st.echo(): # This will also be shown import pandas as pd df = pd.DataFrame() DEFAULT_TEXT = """Google was founded in September 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a California privately held company on September 4, 1998, in California. Google was then reincorporated in Delaware on October 22, 2002.""" spacy_model = "en_core_web_sm"
>>>>>>> 1906d1b29928dda1f159c3b148ab48488ab87b80 # st.write(prediction) if prediction == 1: st.warning('Necesitara hospitalización') else: st.success("No necesitara hospitalización") <<<<<<< HEAD pred_prob = model_load.predict_proba(user_input) ======= pred_prob = model_load.predict_proba(feature_model) >>>>>>> 1906d1b29928dda1f159c3b148ab48488ab87b80 st.write(pred_prob) prob_score = {'Ambulante':pred_prob[0][0]*100,'Hospitalizado':pred_prob[0][1]*100} st.json(prob_score) #### elif choice == 'Mortalidad antes de hopitalización': st.subheader("Se pretende predecir en base a los descriptores la mortalidad del paciente contagiado de CoV-2 antes de estar internado en el hospital") activity = st.selectbox("Activity", submenu) if activity == "Plot": st.subheader("Data plot") st.image(Image.open('plots/def_pos.png'), use_column_width=True) st.image(Image.open('plots/def_edad_histograma.png'), use_column_width=True) st.image(Image.open('plots/barplot_defuncion_edad.png'), use_column_width=True) st.image(Image.open('plots/Tasa de casos de COVID en Mexico por rangos de edad.png'), use_column_width=True) st.image(Image.open('plots/Tasa de letalidad de COVID en México.png'), use_column_width=True) elif activity=='Prediction': st.subheader("Análisis predictivo") st.write(pd.read_csv("models/def_data_grid_report.csv", index_col=0))
def main(): """News Classifier with Streamlit""" st.title('News Classifier using Machine Learning') st.subheader( 'Natural Language Processing and Machine Learning Application') st.markdown('**Created by Aly Boolani**') activities = [ 'Prediction using Machine Learning', 'Natural Language Processing', 'Topic Modelling' ] choice = st.sidebar.selectbox("Choose Activity", activities) # Letting the user pick the options if choice == 'Prediction using Machine Learning': st.info('Prediction using Machine Learning') # Creating an input for users news_text = st.text_area('Enter your text below', 'Start typing here') # Stating all our models all_ml_models = [ 'Random Forest Best Estimator CV = 5', 'Logistic Regression', 'Decision Tree', 'Random Forest', 'Naive Bayes', 'Neural Network', 'AdaBoost', 'Support Vector Machines' ] #'GridSearch Fitted'] # Stating the model choices in a drop down model_choice = st.selectbox('Choose your ML Model below', all_ml_models) # Setting our prediction_labels dictionary for output prediction_labels = {'Fake News': 0, 'Factual News': 1} # Giving a button to classify text or enter command to the machine if st.button("Classify text"): # The following will output the text entered in the box (text_area) above st.text('Original Text ::\n{}'.format(news_text)) # Converting the inputted text for transfomring into vectors vect_text = news_cv.transform([news_text]).toarray() # If user selects Logistic Regression if model_choice == 'Logistic Regression': # Importing the model to predict predictor = loading_prediction_models('models/LR_model.pkl') # Setting our prediction by calling .predict on the model selected prediction = predictor.predict(vect_text) # The following will be moved to the end in order to produce results at the end # Writing this prediction #st.write(prediction) # Prints out the final result #final_result = get_keys(prediction, prediction_labels) #st.success(final_result) # The same steps will be followed as above but will not have comments so it's clear to see # If user chooses Decision Tree Classifier elif model_choice == 'Random Forest Best Estimator CV = 5': predictor = loading_prediction_models( 'models/GridSearchCVTrained.pkl') prediction = predictor.predict(vect_text) elif model_choice == 'Decision Tree': predictor = loading_prediction_models('models/DT_model.pkl') prediction = predictor.predict(vect_text) # st.write(prediction) # If user chooses Random Forest Classifier elif model_choice == 'Random Forest': predictor = loading_prediction_models('models/RF_model.pkl') prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'Naive Bayes': predictor = loading_prediction_models('models/NB_model.pkl') prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'Neural Network': predictor = loading_prediction_models('models/NN_model.pkl') prediction = predictor.predict(vect_text) # st.write(prediction) elif model_choice == 'Support Vector Machines': predictor = loading_prediction_models('models/SVM_model.pkl') prediction = predictor.predict(vect_text) # st.write(prediction) final_result = get_keys(prediction, prediction_labels) st.success('News Categorized as:: {}'.format(final_result)) # If the user decides to choose NLP if choice == 'Natural Language Processing': st.info('Natural Language Processing') news_text = st.text_area('Enter your text below', 'Start typing here') nlp_task = ['Tokenization', 'Lemmatization'] task_choice = st.selectbox('Choose NLP task', nlp_task) if st.button('Analyze'): st.info('Original Text ::\n {}'.format(news_text)) docx = nlp(news_text) if task_choice == 'Tokenization': result = [token.text for token in docx] elif task_choice == 'Lemmatization': result = [ "'Tokens': {}, 'Lemmatized Words': {}".format( token.text, token.lemma_) for token in docx ] st.json(result) # Giving a button to put it in a tabular format if st.button("Tabulize"): docx = nlp(news_text) c_tokens = [token.text for token in docx] c_lemma = [token.lemma_ for token in docx] new_df = pd.DataFrame(zip(c_tokens, c_lemma), columns=['Tokens', 'Lemmatized Words']) st.dataframe(new_df) if st.checkbox('Wordcloud'): wordcloud = WordCloud().generate(news_text) plt.imshow(wordcloud, interpolation='bilinear') plt.axis('off') st.pyplot() if choice == 'Topic Modelling': st.info('Topic Modelling') news_text = st.text_area('Enter your text below', 'Start typing here') number_of_topics = ['1', '2', '3', '4', '5'] model_choice = st.selectbox( 'Choose the number of topics you want to identify', number_of_topics) if st.button("Identify topics"): st.text('Original Text ::\n{}'.format(news_text)) vect_text = news_cv.transform([news_text]).toarray()
def main(): # Wide mode st.set_page_config(layout="wide") # Designing the interface st.title("docTR: Document Text Recognition") # For newline st.write('\n') # Instructions st.markdown( "*Hint: click on the top-right corner of an image to enlarge it!*") # Set the columns cols = st.columns((1, 1, 1, 1)) cols[0].subheader("Input page") cols[1].subheader("Segmentation heatmap") cols[2].subheader("OCR output") cols[3].subheader("Page reconstitution") # Sidebar # File selection st.sidebar.title("Document selection") # Disabling warning st.set_option('deprecation.showfileUploaderEncoding', False) # Choose your own image uploaded_file = st.sidebar.file_uploader( "Upload files", type=['pdf', 'png', 'jpeg', 'jpg']) if uploaded_file is not None: if uploaded_file.name.endswith('.pdf'): doc = DocumentFile.from_pdf(uploaded_file.read()).as_images() else: doc = DocumentFile.from_images(uploaded_file.read()) page_idx = st.sidebar.selectbox( "Page selection", [idx + 1 for idx in range(len(doc))]) - 1 cols[0].image(doc[page_idx]) # Model selection st.sidebar.title("Model selection") det_arch = st.sidebar.selectbox("Text detection model", DET_ARCHS) reco_arch = st.sidebar.selectbox("Text recognition model", RECO_ARCHS) # For newline st.sidebar.write('\n') if st.sidebar.button("Analyze page"): if uploaded_file is None: st.sidebar.write("Please upload a document") else: with st.spinner('Loading model...'): predictor = ocr_predictor(det_arch, reco_arch, pretrained=True) with st.spinner('Analyzing...'): # Forward the image to the model processed_batches = predictor.det_predictor.pre_processor( [doc[page_idx]]) out = predictor.det_predictor.model(processed_batches[0], return_model_output=True) seg_map = out["out_map"] seg_map = tf.squeeze(seg_map[0, ...], axis=[2]) seg_map = cv2.resize( seg_map.numpy(), (doc[page_idx].shape[1], doc[page_idx].shape[0]), interpolation=cv2.INTER_LINEAR) # Plot the raw heatmap fig, ax = plt.subplots() ax.imshow(seg_map) ax.axis('off') cols[1].pyplot(fig) # Plot OCR output out = predictor([doc[page_idx]]) fig = visualize_page(out.pages[0].export(), doc[page_idx], interactive=False) cols[2].pyplot(fig) # Page reconsitution under input page page_export = out.pages[0].export() img = out.pages[0].synthesize() cols[3].image(img, clamp=True) # Display JSON st.markdown("\nHere are your analysis results in JSON format:") st.json(page_export)
def main(): """AutoML Web App Tool with Streamlit""" st.title("AutoML WebApp") st.text("Version(Beta): 0.2") # activities = ["EDA", "Plot", "Model Building", "About"] # choice = st.sidebar.selectbox("Select Activity", activities) # dark_theme = st.sidebar.checkbox("Dark Theme", False) menu = [ "Home", "Pandas Profile", "Sweetviz", "EDA", "Plot", "Model Building", "About" ] choice = st.sidebar.selectbox("Menu", menu) # if dark_theme: # global COLOR # global BACKGROUND_COLOR # BACKGROUND_COLOR = "rgb(17,17,17)" # COLOR = "#fff" if choice == 'Home': # st.subheader("Home") # html_temp = """ # <div style = "background-color:royalblue;padding:10px;border-radius:10px"> # <h1 style = "color:white;text-align:center;">Simpe EDA App with Streamlit Components # </div> # """ # components.html("<p style='color:red'> Demo App </p>") # components.html(html_temp) st.markdown( '**Data Analysis, Visualization** and Machine Learning **Model Building** in an interactive **WebApp** for Data Scientist/Data Engineer/Business Analyst. \n\nThe purpose of this app is to create a **quick Business Insights**. \n\nAutoML WebApp built with **Streamlit framework** using **Pandas** and **Numpy** for Data Analysis, **Matplotlib** and **Seaborn** for Data Visualization, **SciKit-Learn** for Machine Learning Model.' ) # st.markdown('**Demo URL**: https://automlwebapp.herokuapp.com/') st.header("Silent Features") st.markdown( '* User can browse or upload file(Dataset) in .csv or .txt format. \n* User can get the details of dataset like No. of rows & Columns, Can View Column list, Select Columns with rows to show, Dataset Summary like count, mean, std, min and max values. \n* Several Data Visualizations like Correlation with HeatMap, PieChart and Plots like Area, Bar, Line, Box, KDE. \n* User can built Models like LogisticRegression, LinearDiscriminantAnalysis, KNeighborsClassifier, DecisionTreeClassifier, GaussianNB, SVC. \n* Model Evaluation with Accuracy, Mean and Standard Deviation.' ) if choice == 'Pandas Profile': st.subheader("Automated EDA with Pandas Profile") data = st.file_uploader("Upload Dataset", type=["csv", "txt"]) if data is not None: df = pd.read_csv(data) st.dataframe(df.head()) profile = ProfileReport(df) st_profile_report(profile) if choice == 'Sweetviz': st.subheader("Automated EDA with Sweetviz") data = st.file_uploader("Upload Dataset", type=["csv", "txt"]) if data is not None: df = pd.read_csv(data) st.dataframe(df.head()) if st.button("Generate Sweetviz Report"): ## WorkFlow report = sv.analyze(df) report.show_html() st_display_sweetviz("SWEETVIZ_REPORT.html") if choice == 'EDA': st.subheader("Exploratory Data Analysis") data = st.file_uploader("Upload Dataset", type=["csv", "txt"]) if data is not None: df = pd.read_csv(data) st.dataframe(df.head()) if st.checkbox("Show Shape"): st.write(df.shape) if st.checkbox("Show Columns"): all_columns = df.columns.to_list() st.write(all_columns) if st.checkbox("Select Columns To Show"): selected_columns = st.multiselect("Select Columns", all_columns) new_df = df[selected_columns] st.dataframe(new_df) if st.checkbox("Show Summary"): st.write(df.describe()) if st.checkbox("Show Value Counts"): st.write(df.iloc[:, -1].value_counts()) if st.checkbox("Correlation with Seaborn"): st.write(sns.heatmap(df.corr(), annot=True)) st.pyplot() if st.checkbox("Pie Chart"): all_columns = df.columns.to_list() columns_to_plot = st.selectbox("Select 1 Column", all_columns) pie_plot = df[columns_to_plot].value_counts().plot.pie( autopct="%1.1f%%") st.write(pie_plot) st.pyplot() elif choice == 'Plot': st.subheader("Data Visualization") data = st.file_uploader("Upload Dataset", type=["csv", "txt"]) if data is not None: df = pd.read_csv(data) st.dataframe(df.head()) if st.checkbox("Correlation with Seaborn"): st.write(sns.heatmap(df.corr(), annot=True)) st.pyplot() if st.checkbox("Pie Chart"): all_columns = df.columns.to_list() columns_to_plot = st.selectbox("Select 1 Column", all_columns) pie_plot = df[columns_to_plot].value_counts().plot.pie( autopct="%1.1f%%") st.write(pie_plot) st.pyplot() all_columns_names = df.columns.tolist() type_of_plot = st.selectbox( "Select Type of Plot", ["area", "bar", "line", "hist", "box", "kde"]) selected_columns_names = st.multiselect("Select Columns To Plot", all_columns_names) if st.button("Generate Plot"): st.success("Generating Customizable Plot of {} for {}".format( type_of_plot, selected_columns_names)) ## Plot By Streamlit if type_of_plot == 'area': cust_data = df[selected_columns_names] st.area_chart(cust_data) elif type_of_plot == 'bar': cust_data = df[selected_columns_names] st.bar_chart(cust_data) elif type_of_plot == 'line': cust_data = df[selected_columns_names] st.line_chart(cust_data) ## Custom Plot elif type_of_plot: cust_plot = df[selected_columns_names].plot(kind=type_of_plot) st.write(cust_plot) st.pyplot() elif choice == 'Model Building': st.subheader("Building Ml Model") data = st.file_uploader("Upload Dataset", type=["csv", "txt"]) if data is not None: df = pd.read_csv(data) st.dataframe(df.head()) ## Model Building X = df.iloc[:, 0:-1] Y = df.iloc[:, -1] seed = 7 ## Model models = [] models.append(("LR", LogisticRegression())) models.append(("LDA", LinearDiscriminantAnalysis())) models.append(("KNN", KNeighborsClassifier())) models.append(("CART", DecisionTreeClassifier())) models.append(("NB", GaussianNB())) models.append(("SVM", SVC())) ## Evaluate each model in turn ## List model_names = [] model_mean = [] model_std = [] all_models = [] scoring = 'accuracy' for name, model in models: kfold = model_selection.KFold(n_splits=10, random_state=seed) cv_results = model_selection.cross_val_score(model, X, Y, cv=kfold, scoring=scoring) model_names.append(name) model_mean.append(cv_results.mean()) model_std.append(cv_results.std()) accuracy_results = { "model_name": name, "model_accuracy": cv_results.mean(), "standard_deviation": cv_results.std() } all_models.append(accuracy_results) if st.checkbox("Metrics as Table"): st.dataframe( pd.DataFrame(zip(model_names, model_mean, model_std), columns=[ "Model Name", "Model Accuracy", "Standard Deviation" ])) if st.checkbox("Metrics as JSON"): st.json(all_models) elif choice == "About": st.header("About Author") # st.markdown('**Data Analysis, Visualization** and Machine Learning **Model Building** in an interactive **WebApp** for Data Scientist/Data Engineer/Business Analyst. \n\nThe purpose of this app is to create a **quick Business Insights**. \n\nAutoML WebApp built with **Streamlit framework** using **Pandas** and **Numpy** for Data Analysis, **Matplotlib** and **Seaborn** for Data Visualization, **SciKit-Learn** for Machine Learning Model.') # # st.markdown('**Demo URL**: https://automlwebapp.herokuapp.com/') # st.header("Silent Features") # st.markdown('* User can browse or upload file(Dataset) in .csv or .txt format. \n* User can get the details of dataset like No. of rows & Columns, Can View Column list, Select Columns with rows to show, Dataset Summary like count, mean, std, min and max values. \n* Several Data Visualizations like Correlation with HeatMap, PieChart and Plots like Area, Bar, Line, Box, KDE. \n* User can built Models like LogisticRegression, LinearDiscriminantAnalysis, KNeighborsClassifier, DecisionTreeClassifier, GaussianNB, SVC. \n* Model Evaluation with Accuracy, Mean and Standard Deviation.') # st.header("Author") st.markdown( "Hi, there! I'm **Ravi Varma**. I'm passionate about using data to extract decision making insight and help machines learn to make the world a better place. If you liked what you saw, want to have a chat with me about the **Data Science** or **Machine Learning Projects**, **Work Opportunities**, or collaboration, shoot an **email** at **[email protected]**" ) st.markdown( '**Portfolio**: https://ravivarmathotakura.github.io/portfolio/') # st.markdown('**GitHub**: https://github.com/ravivarmathotakura') # st.markdown('**LinkedIn**: https://www.linkedin.com/in/ravivarmathotakura/') st.markdown( '**Follow Me**: [@LinkedIn](https://www.linkedin.com/in/ravivarmathotakura/ "LinkedIn"), [@GitHub](https://github.com/ravivarmathotakura "GitHub")' ) st.subheader("Note") st.text( "The author is not responsible for any misuse the program. \nAny contribution or suggestions are most welcome." )
def main(): st.title("Automated Breast Cancer Prediction!") st.subheader("Predicting Breast Cancer with ML and Streamlit") df = pd.read_csv("Breast_Cancer.csv") x, y = preprocessing(df) le = LabelEncoder() y = le.fit_transform(y) # Splitting x,y into Training & Test set. x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=101) # Feature Scaling sc = StandardScaler() x_train = sc.fit_transform(x_train) x_test = sc.transform(x_test) choose_eda = st.sidebar.selectbox("Select EDA", ["NONE", "Exploratory Data Analysis"]) if (choose_eda == "Exploratory Data Analysis"): if st.checkbox("Show DataSet"): st.dataframe(df.head()) if st.button("Columns Names"): st.write(df.columns) if st.checkbox("Shape of Dataset"): st.write(df.shape) data_dim = st.radio("Show Dimension by", ("Rows", "Columns")) if data_dim == 'Rows': st.text("Number of Rows") st.write(df.shape[0]) elif data_dim == 'Columns': st.text("Number of Columns") st.write(df.shape[1]) if st.checkbox("Select Columns To Show"): all_columns = df.columns.tolist() selected_columns = st.multiselect('Select', all_columns) new_df = df[selected_columns] st.dataframe(new_df) if st.button("Data Types"): st.write(df.dtypes) if st.button("Value Counts"): st.text("Value Counts By Target/Class") st.write(df.iloc[:, 1].value_counts()) st.subheader("Data Visualization") # Show Correlation Plots # Seaborn Plot if st.checkbox("Correlation Plot with Annotation[Seaborn]"): corr = df.corr().round(2) msk = np.zeros_like(corr, dtype=np.bool) msk[np.triu_indices_from(msk)] = True f, ax = plt.subplots(figsize=(20, 20)) cmap = sns.diverging_palette(220, 10, as_cmap=True) st.write( sns.heatmap(corr, mask=msk, cmap=cmap, vmin=-1, vmax=1, center=0, square=True, linewidths=.5, cbar_kws={"shrink": .5}, annot=True)) plt.tight_layout() st.pyplot() # Count Plot for Diagnosis if st.checkbox("Count Plot for Diagnosis column"): st.write(sns.countplot(df['diagnosis'], palette='RdBu')) st.pyplot() choose_pred = st.sidebar.selectbox("Make a Prediction", ["NONE", "User Inputted Prediction"]) if (choose_pred == "User Inputted Prediction"): sample_data, prettified_result, results = accept_user_data() if st.checkbox("Your Inputs Summary"): st.json(prettified_result) st.text("Vectorized as ::{}".format(results)) st.subheader("Prediction") if st.checkbox("Make Prediction"): choose_mdl = st.selectbox("Choose a Model:", [ "Logistic Regression", "Neural Network", "K-Nearest Neighbours", "SVM" ]) if (choose_mdl == "Logistic Regression"): score, report, log = logisticRegression( x_train, x_test, y_train, y_test) pred = log.predict(sc.transform(sample_data)) st.write("The Predicted Class is: ", le.inverse_transform(pred)) elif (choose_mdl == "Neural Network"): score, report, model = neuralNet(x_train, x_test, y_train, y_test) pred = model.predict_classes(sc.transform(sample_data)) st.write("The Predicted Class is: ", le.inverse_transform(pred)) elif (choose_mdl == "K-Nearest Neighbours"): score, report, knn = Knn_Classifier(x_train, x_test, y_train, y_test) pred = knn.predict(sc.transform(sample_data)) st.write("The Predicted Class is: ", le.inverse_transform(pred)) elif (choose_mdl == "SVM"): score, report, svc_linear = svm(x_train, x_test, y_train, y_test) pred = svc_linear.predict(sc.transform(sample_data)) st.write("The Predicted Class is: ", le.inverse_transform(pred)) # ML Model Report choose_model = st.sidebar.selectbox("ML Model Analysis", [ "NONE", "Logistic Regression", "Neural Network", "K-Nearest Neighbours", "SVM" ]) if (choose_model == "Neural Network"): st.write(""" # Explore different classifiers Which one is the best? """) score, report, model = neuralNet(x_train, x_test, y_train, y_test) st.text("Accuracy of Neural Network model is: ") st.write(score, "%") print('\n') st.text("Report of Neural Network model is: ") st.write(report) print('\n') cm = confusion_matrix(y_test, model.predict_classes(x_test)) st.write(sns.heatmap(cm, annot=True, fmt="d", cmap="mako")) st.pyplot() elif (choose_model == "K-Nearest Neighbours"): st.write(""" # Explore different classifiers Which one is the best? """) score, report, knn = Knn_Classifier(x_train, x_test, y_train, y_test) st.text("Accuracy of K-Nearest Neighbour model is: ") st.write(score, "%") print('\n') st.text("Report of K-Nearest Neighbour model is: ") st.write(report) print('\n') cm = confusion_matrix(y_test, knn.predict(x_test)) st.write(sns.heatmap(cm, annot=True, fmt="d", cmap="mako")) st.pyplot() elif (choose_model == "SVM"): st.write(""" # Explore different classifiers Which one is the best? """) score, report, svc_linear = svm(x_train, x_test, y_train, y_test) st.text("Accuracy of SVM model is:") st.write(score, "%") print('\n') st.text("Report of SVM model is:") st.write(report) print('\n') cm = confusion_matrix(y_test, svc_linear.predict(x_test)) st.write(sns.heatmap(cm, annot=True, fmt="d", cmap="mako")) st.pyplot() elif (choose_model == "Logistic Regression"): st.write(""" # Explore different classifiers Which one is the best? """) score, report, log = logisticRegression(x_train, x_test, y_train, y_test) st.text("Accuracy of Logistic Regression model is: ") st.write(score, "%") print('\n') st.text("Report of Logistic Regression model is: ") st.write(report) print('\n') cm = confusion_matrix(y_test, log.predict(x_test)) st.write(sns.heatmap(cm, annot=True, fmt="d", cmap="mako")) st.pyplot()
# removing certain characters that lead to errors (e.g. replacing "%20" by "-") commands = unquote(commands) commands = commands.split("https")[:-1][0] + "https" + '-'.join( commands.split("https")[-1].split(" ")) commands = commands.replace("'", '"') commands = unidecode.unidecode(commands) joblib.dump(commands, cache_dir + '/commands.pickle') commands_to_file = commands + ' > ' + data_dir + '/out.json' os.system(commands_to_file) st.success( f'Pedido efectuado. \nFicheiro guardado na pasta: {data_dir}.') output_file = json.load(open(data_dir + "/out.json")) st.json(output_file) # st.table(pd.DataFrame(output_file['data'])) ### SITE if st.sidebar.checkbox("Exemplo 2: Dados de Utilização do Portal"): st.subheader("Dados de utilização do Portal") response_site = session.get("https://dados.gov.pt/api/1/site/") # response_site.json() # response_site.json().get("metrics") st.json(response_site.json().get("metrics")) st.table(
def main(): ''' NLP with NLTK, streamlit ''' try: st.title("NLP4U ") st.subheader('Your Guide to Natural Language Processing (NLP) !') st.markdown('Put in raw text, and get back linguistic knowledge and other useful information.') sample_text = 'London is the capital and most populous city of England. Bill Gates is looking at buying fintech startup for $1 billion.' text = st.text_area("Enter Your Text : ", sample_text, key='text_analyzer') nlp = NLP(text) st.markdown('Click on the checkboxes to view the results.') # Tokenization if st.checkbox("Tokenization"): st.text( "Tokenization is the process of segmenting running text into sentences and words.") if st.button('Run', key='Tokenization'): result = nlp.tokenizer() st.json(body=result) # Lemmatization if st.checkbox("Lemmatization"): st.text("Lemmatization reduce a word to its base form.") if st.button('Run', key='Lemmatization'): result = nlp.lemmatizer() st.json(body=result) # Stemming if st.checkbox("Stemming"): st.text("Stemming link all the words into their root word.") stemming_options = st.selectbox( "Choose Stemmer", ['PorterStemmer', 'LancasterStemmer']) if st.button('Run', key='Stemming'): if stemming_options == 'PorterStemmer': result = nlp.stemming('PorterStemmer') st.json(body=result) elif stemming_options == 'LancasterStemmer': result = nlp.stemming('LancasterStemmer') st.json(body=result) # N-Grams if st.checkbox("N-Grams"): st.markdown("N-grams are a set of co-occurring or continuous sequence of n items from a sequence of large text or sentence.") stemming_options = st.selectbox( "Choose N", ['2','3','4']) if st.button('Run', key='ngram'): if stemming_options == '2': result = nlp.extract_ngrams('2') st.json(body=result) elif stemming_options == '3': result = nlp.extract_ngrams('3') st.json(body=result) elif stemming_options == '4': result = nlp.extract_ngrams('4') st.json(body=result) # Tagging if st.checkbox("POS Tagging"): st.markdown("POS Tagging is the process of marking up a word in a text as corresponding to a particular part of speech.") if st.button('Run', key='pos'): result = nlp.pos_tagging() st.json(body=result) # NER if st.checkbox("NER Tagging"): st.markdown("NER seeks to locate and classify named entities in text into pre-defined categories such as the names of persons, organizations, locations, expressions of times, quantities, monetary values, percentages, etc.") if st.button('Run', key='ner'): result = nlp.ner_tagging() st.json(body=result) # About st.sidebar.header("About") st.sidebar.subheader("NLP4U") st.sidebar.markdown("App to demonstrate various Natural Language Processing (NLP) capabilities.") st.sidebar.text("Created with NLTK and Streamlit") st.sidebar.header("By :") st.sidebar.text("Sreejith C") st.sidebar.markdown("[Profile](https://sites.google.com/site/sreejithc321/)") except Exception as error: st.exception(error)
def write(): """Writes the page in gallery.py""" st.sidebar.title("Interactive spaCy visualizer") st.sidebar.markdown(""" Process text with [spaCy](https://spacy.io) models and visualize named entities, dependencies and more. Uses spaCy's built-in [displaCy](http://spacy.io/usage/visualizers) visualizer under the hood. """) st.write("Author: [Ines Montani](https://gist.github.com/ines)") st.write( "Source: [Github](https://gist.github.com/ines/b320cb8441b590eedf19137599ce6685)" ) spacy_model = st.sidebar.selectbox("Model name", SPACY_MODEL_NAMES) model_load_state = st.info(f"Loading model '{spacy_model}'...") nlp = load_model(spacy_model) model_load_state.empty() text = st.text_area("Text to analyze", DEFAULT_TEXT) doc = process_text(spacy_model, text) if "parser" in nlp.pipe_names: st.header("Dependency Parse & Part-of-speech tags") st.sidebar.header("Dependency Parse") split_sents = st.sidebar.checkbox("Split sentences", value=True) collapse_punct = st.sidebar.checkbox("Collapse punctuation", value=True) collapse_phrases = st.sidebar.checkbox("Collapse phrases") compact = st.sidebar.checkbox("Compact mode") options = { "collapse_punct": collapse_punct, "collapse_phrases": collapse_phrases, "compact": compact, } docs = [span.as_doc() for span in doc.sents] if split_sents else [doc] for sent in docs: html = displacy.render(sent, options=options) # Double newlines seem to mess with the rendering html = html.replace("\n\n", "\n") if split_sents and len(docs) > 1: st.markdown(f"> {sent.text}") st.write(HTML_WRAPPER.format(html), unsafe_allow_html=True) if "ner" in nlp.pipe_names: st.header("Named Entities") st.sidebar.header("Named Entities") default_labels = ["PERSON", "ORG", "GPE", "LOC"] labels = st.sidebar.multiselect("Entity labels", nlp.get_pipe("ner").labels, default_labels) html = displacy.render(doc, style="ent", options={"ents": labels}) # Newlines seem to mess with the rendering html = html.replace("\n", " ") st.write(HTML_WRAPPER.format(html), unsafe_allow_html=True) attrs = ["text", "label_", "start", "end", "start_char", "end_char"] if "entity_linker" in nlp.pipe_names: attrs.append("kb_id_") data = [[str(getattr(ent, attr)) for attr in attrs] for ent in doc.ents if ent.label_ in labels] df = pd.DataFrame(data, columns=attrs) st.dataframe(df) if "textcat" in nlp.pipe_names: st.header("Text Classification") st.markdown(f"> {text}") df = pd.DataFrame(doc.cats.items(), columns=("Label", "Score")) st.dataframe(df) vector_size = nlp.meta.get("vectors", {}).get("width", 0) if vector_size: st.header("Vectors & Similarity") st.code(nlp.meta["vectors"]) text1 = st.text_input("Text or word 1", "apple") text2 = st.text_input("Text or word 2", "orange") doc1 = process_text(spacy_model, text1) doc2 = process_text(spacy_model, text2) similarity = doc1.similarity(doc2) if similarity > 0.5: st.success(similarity) else: st.error(similarity) st.header("Token attributes") if st.button("Show token attributes"): attrs = [ "idx", "text", "lemma_", "pos_", "tag_", "dep_", "head", "ent_type_", "ent_iob_", "shape_", "is_alpha", "is_ascii", "is_digit", "is_punct", "like_num", ] data = [[str(getattr(token, attr)) for attr in attrs] for token in doc] df = pd.DataFrame(data, columns=attrs) st.dataframe(df) st.header("JSON Doc") if st.button("Show JSON Doc"): st.json(doc.to_json()) st.header("JSON model meta") if st.button("Show JSON model meta"): st.json(nlp.meta)
def draw_all( key, plot=False, ): st.write(""" # Example Widgets These widgets don't do anything. But look at all the new colors they got 👀 ```python # First some code. streamlit = "cool" theming = "fantastic" both = "💥" ``` """) st.checkbox("Is this cool or what?", key=key) st.radio( "How many balloons?", ["1 balloon 🎈", "2 balloons 🎈🎈", "3 balloons 🎈🎈🎈"], key=key, ) st.button("🤡 Click me", key=key) # if plot: # st.write("Oh look, a plot:") # x1 = np.random.randn(200) - 2 # x2 = np.random.randn(200) # x3 = np.random.randn(200) + 2 # hist_data = [x1, x2, x3] # group_labels = ["Group 1", "Group 2", "Group 3"] # fig = ff.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5]) # st.plotly_chart(fig, use_container_width=True) st.file_uploader("You can now upload with style", key=key) st.slider("From 10 to 11, how cool are themes?", min_value=10, max_value=11, key=key) # st.select_slider("Pick a number", [1, 2, 3], key=key) st.number_input("So many numbers", key=key) st.text_area("A little writing space for you :)", key=key) st.selectbox( "My favorite thing in the world is...", ["Streamlit", "Theming", "Baloooons 🎈 "], key=key, ) # st.multiselect("Pick a number", [1, 2, 3], key=key) # st.color_picker("Colors, colors, colors", key=key) with st.beta_expander("Expand me!"): st.write("Hey there! Nothing to see here 👀 ") st.write("") # st.write("That's our progress on theming:") # st.progress(0.99) if plot: st.write("And here's some data and plots") st.json({"data": [1, 2, 3, 4]}) st.dataframe({"data": [1, 2, 3, 4]}) st.table({"data": [1, 2, 3, 4]}) st.line_chart({"data": [1, 2, 3, 4]}) # st.help(st.write) st.write("This is the end. Have fun building themes!")
base_configs = sorted(glob.glob(os.path.join(logdir, "configs/*-project.yaml"))) opt.base = base_configs+opt.base if opt.config: if type(opt.config) == str: opt.base = [opt.config] else: opt.base = [opt.base[-1]] configs = [OmegaConf.load(cfg) for cfg in opt.base] cli = OmegaConf.from_dotlist(unknown) config = OmegaConf.merge(*configs, cli) st.sidebar.text(ckpt) gs = st.sidebar.empty() gs.text(f"Global step: ?") st.sidebar.text("Options") #gpu = st.sidebar.checkbox("GPU", value=True) gpu = True #eval_mode = st.sidebar.checkbox("Eval Mode", value=True) eval_mode = True #show_config = st.sidebar.checkbox("Show Config", value=False) show_config = False if show_config: st.info("Checkpoint: {}".format(ckpt)) st.json(OmegaConf.to_container(config)) dsets, model, global_step = load_model_and_dset(config, ckpt, gpu, eval_mode) gs.text(f"Global step: {global_step}") run_conditional(model, dsets)
query_term = add_selectbox count, dict_by_terms, all = get_images_by_term(query_term) st.write("# PadChest Explorer") st.write("## Query term: " + query_term) st.write("### Total images: ", count) def get_table_download_link(df): """Generates a link allowing the data to be downloaded in: dataframe out: href string """ csv = df.to_csv(index=False) b64 = base64.b64encode(csv.encode()).decode( ) # some strings <-> bytes conversions necessary here href = f'<a href="data:file/csv;base64,{b64}">Download csv file</a>' df = pd.DataFrame(all['ImageID'], columns=['ImageID']) #st.sidebar.markdown(get_table_download_link(df), unsafe_allow_html=True) st.write("### Images by each node term ") st.json(dict_by_terms) st.write("### Images by any node term (OR operation): ", count) st.json(all)
platelets = st.sidebar.number_input("Platelets (kiloplatelets/mL)",0.0,100000.0) # Level of creatinine in the blood serum_creatinine = st.sidebar.number_input("Serum creatinine (mg/dL)",0.0,100.0) # Level of sodium in the blood serum_sodium = st.sidebar.number_input("Serum sodium (mEq/L)",1,1000) # If the patient smokes smoking = st.sidebar.radio("Smoking",tuple(feature_dict.keys())) # Follow-up period time = st.sidebar.number_input("Time (follow-up-period)", 1,1000) feature_list = [age,get_value(sex,gender_dict),get_fvalue(anaemia),creatinine_phosphokinase,get_fvalue(diabetes),ejection_fraction,get_fvalue(high_blood_pressure),platelets,serum_creatinine,serum_sodium,get_fvalue(smoking), time] pretty_result = {"Age":age,"Sex":sex,"Anaemia":anaemia,"Creatinine phosphokinase (mcg/L)":creatinine_phosphokinase,"Diabetes":diabetes,"Ejection fraction %":ejection_fraction,"High blood pressure":high_blood_pressure,"Platelets (kiloplatelets/mL)":platelets,"Serum creatinine (mg/dL)":serum_creatinine,"Serum sodium (mEq/L)":serum_sodium,"Smoking":smoking,"Time (follow-up-period)":time} ''' ## These are the values you entered 🧑⚕ ''' st.json(pretty_result) single_sample = np.array(feature_list).reshape(1,-1) if st.button("Predict"): ''' ## Results 👁🗨 ''' loaded_model = load_model('model.pkl') prediction = loaded_model.predict(single_sample) pred_prob = loaded_model.predict_proba(single_sample) if prediction == 1: st.error("The patient will die") else: st.success("The patient will live")
current = geocode_results[0] coords = (current["geometry"]["location"]["lat"], current["geometry"]["location"]["lng"]) id = current["place_id"] east_lng, west_lng = (current["geometry"]["bounds"]["northeast"]["lng"], current["geometry"]["bounds"]["southwest"]["lng"]) zoom = calc_zoom(west_lng, east_lng) st.deck_gl_chart(viewport={ 'latitude': coords[0], 'longitude': coords[1], 'zoom': zoom + 2, 'pitch': 50, }) places = gmaps.places_nearby(location=coords, language="EN", min_price=1, max_price=4, name='food', open_now=True, rank_by='distance', type=["cafe", "restaurant"]) st.text(len(places["results"])) st.json(places) # st.json(geocode_results)
def main(): """Car Evaluation with ML Streamlit App""" st.title("Car Evaluation") st.subheader("Streamlit ML App") # st.image(load_image("cars_images/car1.jpg"),width=300, caption='Images') activities = ['EDA', 'Prediction', 'Gallery', 'About'] choices = st.sidebar.selectbox("Select Activity", activities) if choices == 'EDA': st.subheader("EDA") data = load_data('data/car_eval_dataset.csv') st.dataframe(data.head(5)) if st.checkbox("Show Summary of Dataset"): st.write(data.describe()) # Show Plots if st.checkbox("Simple Value Plots "): st.write(sns.countplot(data['class'])) # Use Matplotlib to render seaborn st.pyplot() # Show Columns By Selection if st.checkbox("Select Columns To Show"): all_columns = data.columns.tolist() selected_columns = st.multiselect('Select', all_columns) new_df = data[selected_columns] st.dataframe(new_df) if st.checkbox("Pie Plot"): all_columns_names = data.columns.tolist() if st.button("Generate Pie Plot"): st.write( data.iloc[:, -1].value_counts().plot.pie(autopct="%1.1f%%")) st.pyplot() if choices == 'Prediction': st.subheader("Prediction") buying = st.selectbox('Select Buying Level', tuple(buying_label.keys())) maint = st.selectbox('Select Maintenance Level', tuple(maint_label.keys())) doors = st.selectbox('Select Doors', tuple(doors_label.keys())) persons = st.number_input('Select Num of Persons', 2, 10) lug_boot = st.selectbox("Select Lug Boot", tuple(lug_boot_label.keys())) safety = st.selectbox('Select Safety', tuple(safety_label.keys())) k_buying = get_value(buying, buying_label) k_maint = get_value(maint, maint_label) k_doors = get_value(doors, doors_label) # k_persons = get_value(persons,persons_label) k_lug_boot = get_value(lug_boot, lug_boot_label) k_safety = get_value(safety, safety_label) pretty_data = { "buying": buying, "maint": maint, "doors": doors, "persons": persons, "lug_boot": lug_boot, "safety": safety, } st.subheader("Options Selected") st.json(pretty_data) st.subheader("Data Encoded As") # Data To Be Used sample_data = [ k_buying, k_maint, k_doors, persons, k_lug_boot, k_safety ] st.write(sample_data) prep_data = np.array(sample_data).reshape(1, -1) model_choice = st.selectbox("Model Type", ['logit', 'naive bayes', 'MLP classifier']) if st.button('Evaluate'): if model_choice == 'logit': predictor = load_prediction_models( "models/logit_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) if model_choice == 'naive bayes': predictor = load_prediction_models("models/nb_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) if model_choice == 'MLP classifier': predictor = load_prediction_models( "models/nn_clf_car_model.pkl") prediction = predictor.predict(prep_data) st.write(prediction) final_result = get_key(prediction, class_label) st.success(final_result)
# Text Area message = st.text_area("Enter your message:", "Type here...") if st.button("Submit", key="unique"): result = message.title() st.success(result) # Date Input import datetime today = st.date_input("Today is", datetime.datetime.now()) # Time the_time = st.time_input("Time is", datetime.time()) # Display JSON st.text("Display JSON") st.json({'a':2, 'b':5}) # Display raw code st.text("Display raw code") st.code("import numpy as np") # Display raw code with st.echo(): # this will also show as a comment import pandas as pd df = pd.DataFrame() # Progress Bar import time my_bar = st.progress(0)
def main(): st.title("A webapp that explores different datasets and classifiers.") st.write(""" ### Explore the Breast Cancer, Iris, Wine and Digits datasets using Scikit Learn. """) st.sidebar.write("### Choose the best classifier and parameter") data_name = st.sidebar.selectbox( "Select Dataset:", ("Breast Cancer", "Iris", "Wine", "Digits")) classifier_name = st.sidebar.selectbox( "Select Classifier:", ("Logistic Regression", "K-Nearest Neighbors (KNN)", "Support Vector Machine (SVM)", "Random Forest")) @st.cache(persist=True) def load_data(): if data_name == "Breast Cancer": data = datasets.load_breast_cancer() elif data_name == "Iris": data = datasets.load_iris() elif data_name == "Wine": data = datasets.load_wine() else: data = datasets.load_digits() # split features and target X = data.data y = data.target class_names = data.target_names return X, y, class_names X, y, class_names = load_data() st.write("Current data: ", data_name) st.write("Shape of", data_name, "dataset ", X.shape) st.write("Class labels: ", class_names) st.sidebar.write("Adjust parameters: ") def add_parameter(classifier_name): params = dict() if classifier_name == "Logistic Regression": C = st.sidebar.slider("C", 0.01, 10.0) params["C"] = C elif classifier_name == "K-Nearest Neighbors (KNN)": K = st.sidebar.slider("K", 1, 15) params["K"] = K elif classifier_name == "Support Vector Machine (SVM)": C = st.sidebar.slider("C", 0.01, 10.0) params["C"] = C else: # load random forest max_depth = st.sidebar.slider("max_depth", 2, 15) n_estimators = st.sidebar.slider("n_estimators", 1, 100) params["max_depth"] = max_depth params["n_estimators"] = n_estimators return params params = add_parameter(classifier_name) def get_classifier(clf_name, params): if classifier_name == "Logistic Regression": clf = LogisticRegression(C=params["C"], solver='liblinear') elif classifier_name == "K-Nearest Neighbors (KNN)": clf = KNeighborsClassifier(n_neighbors=params["K"]) elif classifier_name == "Support Vector Machine (SVM)": clf = SVC(C=params["C"]) else: clf = RandomForestClassifier(n_estimators=params["n_estimators"], max_depth=params["max_depth"]) return clf clf = get_classifier(classifier_name, params) # split data for training and testing X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=23) # standardized features scaler = StandardScaler() scaler.fit_transform(X_train) # fit model clf.fit(X_train, y_train) # predict y_pred = clf.predict(X_test) # calculate metrics accuracy = accuracy_score(y_test, y_pred).round(3) precision = precision_score(y_test, y_pred, average='weighted', zero_division=0).round(3) recall = recall_score(y_test, y_pred, average='weighted').round(3) model_results = { "Model Name": classifier_name, "Accuracy": accuracy, "Precision": precision, "Recall Score": recall # "ROC AUC Score": area_under_curve } st.write("Model Results: ") st.json(model_results) st.set_option('deprecation.showPyplotGlobalUse', False) # confusiont matrix plot def confusion_matrix_plot(): st.subheader("Confusion Matrix") plt.figure(1, figsize=(9, 7)) plot_confusion_matrix(clf, X_test, y_test, display_labels=class_names) st.pyplot() # instantiate plot confusion_matrix_plot() # pca plot pca = PCA(n_components=2, svd_solver='full') X_projected = pca.fit_transform(X) x1 = X_projected[:, 0] x2 = X_projected[:, 1] # st.write(f"Principal Component Analysis for {data_name}") def pca_plot(): st.subheader("PCA Scatter Plot") fig = plt.figure(1, figsize=(9, 7)) plt.scatter(x1, x2, c=y, alpha=0.8, cmap='Paired') plt.xlabel("Principal Component 1") plt.ylabel("Principal Component 2") plt.colorbar() st.pyplot(fig) # instantiate plot pca_plot()
def main(): """ ML App with Streamlit for Contraceptive Choice Prediction""" st.title("Contraceptive Method Choice Prediction") st.subheader("Predicting Contraceptive Choice with ML and Streamlit") # Load Our Dataset df = pd.read_csv("cmc_dataset.csv") if st.checkbox("Show DataSet"): number = st.number_input("Number of Rows to View") st.dataframe(df.head(number)) if st.button("Columns Names"): st.write(df.columns) if st.checkbox("Shape of Dataset"): st.write(df.shape) data_dim = st.radio("Show Dimension by", ("Rows", "Columns")) if data_dim == 'Rows': st.text("Number of Rows") st.write(df.shape[0]) elif data_dim == 'Columns': st.text("Number of Columns") st.write(df.shape[1]) if st.checkbox("Select Columns To Show"): all_columns = df.columns.tolist() selected_columns = st.multiselect('Select', all_columns) new_df = df[selected_columns] st.dataframe(new_df) if st.button("Data Types"): st.write(df.dtypes) if st.button("Value Counts"): st.text("Value Counts By Target/Class") st.write(df.iloc[:, -1].value_counts()) st.subheader("Data Visualization") # Show Correlation Plots # Matplotlib Plot if st.checkbox("Correlation Plot [Matplotlib]"): plt.matshow(df.corr()) st.pyplot() # Seaborn Plot if st.checkbox("Correlation Plot with Annotation[Seaborn]"): st.write(sns.heatmap(df.corr(), annot=True)) st.pyplot() # Counts Plots if st.checkbox("Plot of Value Counts"): st.text("Value Counts By Target/Class") all_columns_names = df.columns.tolist() primary_col = st.selectbox('Select Primary Column To Group By', all_columns_names) selected_column_names = st.multiselect('Select Columns', all_columns_names) if st.button("Plot"): st.text("Generating Plot for: {} and {}".format( primary_col, selected_column_names)) if selected_column_names: vc_plot = df.groupby( primary_col)[selected_column_names].count() else: vc_plot = df.iloc[:, -1].value_counts() st.write(vc_plot.plot(kind='bar')) st.pyplot() if st.checkbox("Pie Plot"): all_columns_names = df.columns.tolist() # st.info("Please Choose Target Column") # int_column = st.selectbox('Select Int Columns For Pie Plot',all_columns_names) if st.button("Generate Pie Plot"): # cust_values = df[int_column].value_counts() # st.write(cust_values.plot.pie(autopct="%1.1f%%")) st.write(df.iloc[:, -1].value_counts().plot.pie(autopct="%1.1f%%")) st.pyplot() # Prediction st.subheader("Options For Prediction") st.subheader("Attributes To Select from") def get_value(val, my_dict): for key, value in my_dict.items(): if val == key: return value age = st.slider("Select Age", 16, 60) wife_education = st.number_input("Wife's Education Level(low2High) [1,4]", 1, 4) husband_education = st.number_input( "Husband's Education Level(low2High) [1,4]", 1, 4) num_of_children_ever_born = st.number_input("Number of Children") wife_reg = {"Non_Religious": 0, "Religious": 1} choice_wife_reg = st.radio("Wife's Religion", tuple(wife_reg.keys())) result_wife_reg = get_value(choice_wife_reg, wife_reg) # st.text(result_wife_reg) wife_working = {"Yes": 0, "No": 1} choice_wife_working = st.radio("Is the Wife Currently Working", tuple(wife_working.keys())) result_wife_working = get_value(choice_wife_working, wife_working) # st.text(result_wife_working) husband_occupation = st.number_input("Husband Occupation(low2High) [1,4]", 1, 4) standard_of_living = st.slider("Standard of Living (low2High) [1,4]", 1, 4) media_exposure = {"Good": 0, "Not Good": 1} choice_media_exposure = st.radio("Media Exposure", tuple(media_exposure.keys())) result_media_exposure = get_value(choice_media_exposure, media_exposure) # Result and in json format results = [ age, wife_education, husband_education, num_of_children_ever_born, result_wife_reg, result_wife_working, husband_occupation, standard_of_living, result_media_exposure ] displayed_results = [ age, wife_education, husband_education, num_of_children_ever_born, choice_wife_reg, choice_wife_working, husband_occupation, standard_of_living, choice_media_exposure ] prettified_result = { "age": age, "wife_education": wife_education, "husband_education": husband_education, "num_of_children_ever_born": num_of_children_ever_born, "result_wife_reg": choice_wife_reg, "result_wife_working": choice_wife_working, "husband_occupation": husband_occupation, "standard_of_living": standard_of_living, "media_exposure": choice_media_exposure } sample_data = np.array(results).reshape(1, -1) if st.checkbox("Your Inputs Summary"): st.json(prettified_result) st.text("Vectorized as ::{}".format(results)) st.subheader("Prediction") if st.checkbox("Make Prediction"): all_ml_dict = { 'LR': LogisticRegression(), 'CART': DecisionTreeClassifier(), 'RForest': RandomForestClassifier(), 'NB': GaussianNB(), 'MultNB': MultinomialNB() } # models = [] # model_choice = st.multiselect('Model Choices',list(all_ml_dict.keys())) # for key in all_ml_dict: # if 'RForest' in key: # st.write(key) # Find the Key From Dictionary def get_key(val, my_dict): for key, value in my_dict.items(): if val == value: return key # Load Models def load_model_n_predict(model_file): loaded_model = joblib.load(open(os.path.join(model_file), "rb")) return loaded_model # Model Selection model_choice = st.selectbox('Model Choice', list(all_ml_dict.keys())) prediction_label = {"No-use": 1, "Long-term": 2, "Short-term": 3} if st.button("Predict"): if model_choice == 'RForest': loaded_model = joblib.load( open("contraceptives_rf_model.pkl", "rb")) prediction = loaded_model.predict(sample_data) # final_result = get_key(prediction,prediction_label) # st.info(final_result) elif model_choice == 'LR': model_predictor = load_model_n_predict( "models/contraceptives_logit_model.pkl") prediction = model_predictor.predict(sample_data) # st.text(prediction) elif model_choice == 'CART': model_predictor = load_model_n_predict( "models/contraceptives_dcTree_model.pkl") prediction = model_predictor.predict(sample_data) # st.text(prediction) elif model_choice == 'NB': model_predictor = load_model_n_predict( "models/contraceptives_nv_model.pkl") prediction = model_predictor.predict(sample_data) # st.text(prediction) final_result = get_key(prediction, prediction_label) st.success(final_result) st.sidebar.subheader("About") st.sidebar.info("ML App with Streamlit") st.sidebar.text("Streamlit Is Awesome") if st.sidebar.button("About"): st.sidebar.text("Jesse E.Agbe(JCharis)") st.sidebar.text("Jesus Saves@JCharisTech")
location = geolocator.geocode(where) lat = location.latitude lon = location.longitude map_df = pd.DataFrame.from_dict({"lat": [lat], "lon": [lon]}) st.map(map_df) import datetime today = st.date_input("Today is", datetime.datetime.now()) st.text("Display JSON") st.json({ "Strive": { "Professor": { "name": "Jan", "subject": "being-great!" }, "TA": { "name": "Antonio", "subject": "being-awesome!" } } }) # Display Row Code st.text("Display Raw Code") st.code("import numpy as np") with st.echo(): import pandas as pd df = pd.DataFrame()
xy=(i, value), ha="center", va="center", xytext=(0, 10), textcoords="offset points", fontsize=12, ) sns.despine(ax=ax, bottom=False, left=False) plt.xlabel("Metric", fontsize=16) ax.set_xticklabels(key_metrics, rotation=30, fontsize=10) plt.ylabel("Diff (%)", fontsize=16) plt.show() st.pyplot(plt) with st.beta_expander("Hyperparameters"): st.json(params_diff) with st.beta_expander("Improvements"): st.json({ metric: value for metric, value in performance_diff.items() if value["diff"] >= 0 }) with st.beta_expander("Regressions"): st.json({ metric: value for metric, value in performance_diff.items() if value["diff"] < 0 }) elif selected_page == "Inference": st.header("Inference") text = st.text_input( "Enter text:",
st.write( 'To insert titles and headers like the ones on this page, use the `title`, ' '`header`, and `subheader` functions.') st.header('Preformatted text') with st.echo(): st.text("Here's preformatted text instead of _Markdown_!\n" ' ^^^^^^^^^^^^\n' 'Rock on! \m/(^_^)\m/ ') st.header('JSON') with st.echo(): st.json({'hello': 'world'}) with st.echo(): st.json('{"object":{"array":[1,true,"3"]}}') st.header('Inline Code Blocks') with st.echo(): with st.echo(): st.write('Use `st.echo()` to display inline code blocks.') st.header('Alert boxes') with st.echo(): st.error('This is an error message') st.warning('This is a warning message')
try: st.sidebar.title('Step 3: News Sentiment') buzz, sentiment_df, news = get_sentiment(ticker) st.sidebar.table(buzz.T) st.sidebar.table(sentiment_df.T) st.sidebar.table(news.T) st.subheader("Recommendation") r = requests.get('https://finnhub.io/api/v1/stock/recommendation?symbol={}&token={}'.format(ticker, config.TOKEN)) st.json(r.json()[0]) st.subheader("Price Target") r = requests.get('https://finnhub.io/api/v1/stock/price-target?symbol={}&token={}'.format(ticker, config.TOKEN)) st.json(r.json()) except: st.sidebar.write("Not available at the moment") else: "No ticker"