import streamlit as st import numpy as np import sys import time import math import pandas as pd from utils import * def main(): st.markdown( """ """, unsafe_allow_html=True, ) germanShepherdHeaderColumns = st.columns((1)) germanShepherdHeaderColumns[0].title("Introducing the German Shepherd's Database Collection!") germanShepherdHeaderColumns[0].markdown( """ Created by [Abhinit Sundar](https://github.com/asundar0128) """) germanShepherdEvaluationMethod = germanShepherdHeaderColumns[-1].button('Intrigued with German Shepherds?') if germanShepherdEvaluationMethod: germanShepherdExplainMethod() else: germanShepherdEvaluation() def germanShepherdExplainMethod(): st.button('Traverse Back to German Shepherd Dog Photos') st.markdown( """ Dataset: - We used German Shepherd Dog images from random online sources and fed them into the neural network using ResNet-50 to train the model accuractely. Afterwards, this model is representative of every German Shepherd and is an accurate classifier and predictor for the entire dataset, or paramter of interest, which is the German Shepherd breed of dogs. Created by [Abhinit Sundar](https://github.com/asundar0128) """ ) st.button('Traverse Back to German Shepherd Dog Photos', key='German Shepherd') def germanShepherdEvaluation(): germanShepherdSimilarityMeasureIndex = ['maximum correlation and maximum similarity', 'least correlation and least similarity'] germanShepherdNearestValues = [w**2 for w in range(4, 11)] germanShepherdMaximumProximity = 1000 germanShepherdPixel = [96, 152, 256] germanShepherdModelVersions = ['v1', 'v2'] germanShepherdMinimalIndex = 2500 germanShepherdModelStartTime = time.time() with st.sidebar.expander('Germam Shepherd Similarity Search Instructions'): st.markdown( """ **Select a photo of a particular German Shepherd of interest!** Click the 'Find German Shepherd' button. """ ) germanshepherdNumNearest = st.sidebar.select_slider('Total Quantity of Similar German Shepherds to Show', germanShepherdNearestValues) germanShepherdEvaluatePixel = st.sidebar.select_slider('Picture Size (In Pixels)', germanShepherdPixel, value=germanShepherdPixel[1]) germanShepherdModelVersion = st.sidebar.select_slider('German Shepherd Current Model Version', germanShepherdModelVersions, value=germanShepherdModelVersions[-1]) germanShepherdQuantitySimilarElements = 1000 germanShepherdSimilarityMetric = False germanShepherdBeginSearch = st.sidebar.button('Enter your search parameter of interest for German Shepherd') germanShepherdBeginRandomSearch = st.sidebar.button('Evaluate Random German Shepherd Images') germanShepherdNumberTotal = germanShepherdCategory['Total Number of German Shepherds'] if germanShepherdBeginSearch or germanShepherdRandomSearch: if germanShepherdRandomSearch: germanShepherdMaximumIndex = germanShepherdNumberTotal-1 germanShepherdRandomIndex = 0 while (germanShepherdRandomIndex < germanShepherdMinimalIndex) or (germanShepherdRandomIndex > germanShepherdMaximumIndex): germanShepherdRandomIndex = int(np.random.lognormal(12., 3.)) germanShepherdLinks = urls_from_coordinates(germanShepherdSimilarityValue, germanShepherdPixelValue=germanShepherdEvaluatePixel) germanShepherdSimilarityValue['Link to German Shepherd'] = np.array(germanShepherdLink) germanShepherdNumberColumns = min(11, int(math.ceil(np.sqrt(germanshepherdNumNearest)))) germanShepherdNumberRows = int(math.ceil(germanshepherdNumNearest/germanShepherdNumberColumns)) germanShepherdLabel = 'Traverse Through German Shepherd' germanShepherdLabelRawDecimal = 'RA, Dec = ({:.4f}, {:.4f})'.format(germanShepherdSimilarityValue['Raw German Shepherd Image'][0], germanShepherdSimilarityValue['Decimal German Shepherd Image'][0]) germanShepherdColumns = st.columns([2]+[1*germanShepherdNumberColumns]) germanShepherdColumns[0].subheader(lab) germanShepherdColumns[1].subheader('Closest German Shepherd Photos') germanShepherdColumns = st.columns([2]+[1]*germanShepherdNumberColumns) germanShepherdColumns[0].image(germanShepherdLink[0], use_column_width='always', caption=lab_radec)#use_column_width='auto') germanShepherdIndexImage = 1 for germanShepherdIndexRow in range(germanShepherdNumberRows): for germanShepherdIndexColumn in range(germanShepherdNumberColumns): germanShepherdLink = germanShepherdLinks[germanShepherdIndexImage] germanShepherdLabelValue = 'German Shepherd Similarity Value={:.2f}\n'.format(germanShepherdSimilarityValue['German Shepherd Similarity'][germanShepherdIndexImage]) if germanShepherdNumberColumns > 5: germanShepherdLabelValue = None germanShepherdColumns[germanShepherdIndexColumn+1].image(germanShepherdLink, caption=lab, use_column_width='always') germanShepherdIndexImage += 1 germanShepherdValueatIndex = ['g', 'r', 'z'] germanShepherdSimilarityValueOutput = {} for q, x in germanShepherdSimilarityValue.items(): if x.ndim == 2: for germanShepherdIndexValues in range(v.shape[1]): germanShepherdSimilarityValueOutput['{:s}_{:s}'.format(q, germanShepherdValueatIndex[germanShepherdIndexValues])] = x[:, germanShepherdIndexValues] else: germanShepherdSimilarityValueOutput[q] = x germanShepherdSimilarityValueOutput['German Shepherd Source Value'] = germanShepherdSimilarityValueOutput['German Shepherd Source Value'].astype('str') germanShepherdDataFrame = pd.DataFrame.from_dict(germanShepherdSimilarityValueOutput) cols_leading = ['German Shepherd Raw Pixel Value', 'German Shepherd Decimal Pixel Value', 'German Shepherd Similarity Index'] cols = cols_leading + [germanShepherdColumn for germanShepherdColumn in df if germanShepherdColumn not in germanShepherdLeadingColumn] germanShepherdDatFrame = germanShepherdDataFrame[germanShepherdColumns] # display table st.write(df.head(germanShepherdMaximumProximity)) # show a downloadable link st.markdown(get_table_download_link(germanShepherdDataFrame), unsafe_allow_html=True) germanShepherdTendency = time.time() st.set_page_config( page_title='GermanShepherdDogFinder', layout="wide", initial_sidebar_state="expanded", ) if __name__ == '__main__': main()