# setting dimensions of image for inputting into model N_ROWS = 150 N_COLS = 150 # loading model and label encoder model = models.load_model("./models/keras_model_1") encoder_file = open('./models/encoder.pkl', 'rb') encoder = pickle.load(encoder_file) # initiating dash app app = dash.Dash(__name__, external_stylesheets=[dbc.themes.FLATLY]) app.layout = html.Div(className='container', children=[ dbc.Row(dbc.Col(html.H1("Metropolitan Museum of Art Paintings Classifier"), style={'textAlign': 'center'})), dbc.Row(html.H1(" ")), dbc.Row(dbc.Col(html.Font( "Click the button below to generate a random photo from the Metroploitan Museum of Art's collection, and to predict its culture."), style={'textAlign': 'center', 'backgroundColor': 'lightgrey'}, width=4), justify='center'), dbc.Row(html.H1(" ")), dbc.Row(dbc.Col(dbc.Button("Generate Random Image", id='button', n_clicks=0, color='danger', size='lg'), style={'textAlign': 'center'})), dbc.Row(id='random-image', style={'display': 'none'}), dbc.Row(id='image-culture', style={'display': 'none'}), dbc.Row(html.H1(" ")), dbc.Row(html.H1(" ")), dbc.Row(dbc.Col(id="label-explanation", style={'textAlign': 'center'})), dbc.Row(html.H1(" ")), dbc.Row(dbc.Col(html.Img(id='image', src='image'), width=6), justify='center'), dbc.Row(html.H1(" ")), dbc.Row(html.H1(" ")), dbc.Row(dbc.Col(id="prediction", style={'textAlign': 'center'})), dbc.Row(html.H1(" ")),
html.Button(id='submit_stock', n_clicks=0, children='Show', style={'color': 'black'}) ]), html.Label(dcc.Dropdown(id='year_dropdown', options=[{ 'label': year, 'value': year } for year in years], value="1y", multi=False), style={"width": '60%'}), html.Br(), html.Label(children=[ html.Font("Percentage up", style={'color': 'black'}), dcc.Slider(id='percent_slider', min=min(percentages), max=(max(percentages)), step=None, marks={ percent: { 'label': str(percent) + '%', 'style': { 'fontSize': 14 } } for percent in percentages }, dots=True, value=5,
print("Loading " + prefix.capitalize() + " ...") layout = dbc.Col([ dbc.Col([ html.Br(), dbc.Col([ html.Center([ dbc.Jumbotron([ html.H1("404 Page Not Found"), html.H3("Sorry, we can't find that page ..."), html.H5("Please check the URL and try again ..."), html.Br(), html.Hr(), html.Br(), html.P([ html.Font("Try to go back to our "), html.A("homepage", href="/covidrugnet/home") ]), html.P([ html.Font("If the problem persists, please "), html.A("let us know", href="mailto:[email protected]") ]) ], style={"width": "50vw"}) ]) ], style={ "padding": "2%", "width": "100%" })
], value='ET灰面鵟鷹隊', id='team-option', className= 'form-inputs d-flex align-items-center'), className='align-items-center'), dbc.Row(html.Div('', id='hint-text'), className='align-items-center'), dbc.Row( html.Button('提交並開始比賽!', type='submit', id='join-submit'), className='align-items-center'), dbc.Row([ dcc.Link('忘記公開顯示帳號', href='/help', style={'color': '#37760E'}), html.Font( '|', className='px-3', style={'color': '#37760E'}), html. A('創建新帳號', href= 'https://secure.birds.cornell.edu/cassso/account/create', style={'color': '#37760E'}) ], className='mt-3 mx-auto help-lnks'), dcc.Input( id='team-output', name='team', style={'display': 'none'}), ], action='/post', method='post'), ], lg=4, md=12,
df = GetN_Record([2019,7,1], [2019,12,31]) fig_Record_species = draw_bar(df.紀錄筆數.tolist(), df.觀察者.tolist()) nP = GetN_Participants([2019,7,1], [2019,12,31]) accP = f'累積參與人數: {nP}' ##################################################################################### ######################## LAYOUTs SECTION ################################################## ################################################################### master_layout = app.layout = html.Div([ visdcc.Run_js(id='javascript'), dcc.Location(id='url', refresh=False), html.Nav([ html.A([html.Font('e', style={'color':'#4ca800'},className='EB'),html.Font('Bird',className='EB',style={'color':'#000000'}),html.Br(className="EB_sep"), html.Font(' Taiwan', style={'color':'#4ca800'})],style={'font-weight':'600'},className='logo_title navbar-brand',href="/"), dbc.NavbarToggler(id="navbar-toggler"), dbc.Collapse([ html.Ul([ html.Li(html.A('eBird Taiwan秋季大亂鬥', href='/Ebird%e7%a7%8b%e5%ad%a3%e6%8c%91%e6%88%b0%e8%b3%bd',className="NavLnks"),className="nav-item"), html.Li(html.A('關渡觀鳥大日', href='/%e9%97%9c%e6%b8%a1%e9%b3%a5%e5%8d%9a%e8%a7%80%e9%b3%a5%e5%a4%a7%e6%97%a5',className="NavLnks"),className="nav-item"), html.Li(html.A('全球觀鳥大日', href='https://ebird.org/taiwan/news/2019-ebird%E5%8D%81%E6%9C%88%E8%A7%80%E9%B3%A5%E5%A4%A7%E6%97%A5-10%E6%9C%8819%E6%97%A5',className="NavLnks"),className="nav-item"), ],className="navbar-nav mr-auto"), html.Img(src="assets/sponsor.png",height="71px",className="float-right"), ],id="navbar-collapse", navbar=True), ], className="navbar navbar-expand-md navbar-light bg-white justify-content-between"), html.Div(id='page-content'), html.Br(), html.Div(style={"height": "100px", "background": "#84BC60"}), html.Div(), html.Div(),
def update_graph(make_selected, model_selected, year_selected, trim_selected, mileage_selected, make_selected2, model_selected2, year_selected2, tab): show_first_car = {**styles.drop_down_group_style, "display": "block"} show_second_car = {**styles.drop_down_group_style, "display": "none"} show_graph = {"display": "none"} description = html.P() show_description = {"display": "none", **styles.description_box_style} mileage_box = {**styles.drop_down_style, "display": "none"} trim_box = {**styles.drop_down_style, "display": "none"} first_vehicle_title = "Select Vehicle" fig = go.Figure() show_arch_fig = {"display": "none", **styles.arch_fig_style} if tab == "tab-1": if make_selected and model_selected: car = " ".join( [str(year_selected or ""), make_selected, model_selected]) df = data.get_grouped_data(make_selected, model_selected, year_selected) marker = dict(color="#d64161") text = [f"Sample size: {cnt}" for cnt in df.Count.tolist()] hovertemplate = "<br><i>Mileage Range</i>: %{x} miles<br>" + \ "<i>Average Price</i>: $%{y}<br>" + "<i>%{text}</i>" fig = helper.create_plot("bar", df.Mileage_range, df.Average_Price, error_y=dict(array=df.STD_Price.tolist()), marker=marker, text=text, template=hovertemplate, title=f"{car} Listing Price", xaxis_title="Mileage (miles)", yaxis_title="Average Price ($)", opacity=0.7) desc = helper.generate_description( df, "#d64161", make_selected, model_selected, year_selected, style=styles.description_tablets_style) if desc: description = [ html.Br(), html.Br(), desc, html. P("Hover over the bars to check the sample size. " + "Larger sample size has a higher chance of yielding accurate statistics", style=styles.description_tablets_style) ] show_description["display"] = "inline-block" show_graph["display"] = "block" elif tab == "tab-2": if all( [make_selected, model_selected, make_selected2, model_selected2]): df = data.get_grouped_data(make_selected, model_selected, year_selected, make2=make_selected2, model2=model_selected2, year2=year_selected2) try: makemodel1, makemodel2 = df.MakeModel.unique().tolist() except ValueError: makemodel1 = df.MakeModel.unique().tolist()[0] makemodel2 = makemodel1 car1 = df[df["MakeModel"] == makemodel1] car2 = df[df["MakeModel"] == makemodel2] name = [makemodel1, makemodel2] x = [car1.Mileage_range, car2.Mileage_range] y = [car1.Average_Price, car2.Average_Price] error_y = [ dict(array=car1.STD_Price.tolist()), dict(array=car2.STD_Price.tolist()) ] marker = [dict(color="rgb(82,188,163)"), dict(color="#d64161")] text = [[f"Sample size: {cnt}" for cnt in car1.Count.tolist()], [f"Sample size: {cnt}" for cnt in car2.Count.tolist()]] hovertemplate = "<br><i>Mileage Range</i>: %{x} miles<br>" + \ "<i>Average Price</i>: $%{y}<br>" + "<i>%{text}</i>" fig = helper.create_plot("groupbar", x, y, error_y=error_y, marker=marker, text=text, template=hovertemplate, name=name, title=f"{makemodel1} vs {makemodel2}", xaxis_title="Mileage (miles)", yaxis_title="Average Price ($)", opacity=0.7) desc1 = helper.generate_description( car1, "rgb(82,188,163)", make_selected, model_selected, year_selected, style=styles.description_tablets_style) desc2 = helper.generate_description( car2, "#d64161", make_selected2, model_selected2, year_selected2, style=styles.description_tablets_style) if desc1 or desc2: description = [ html.Br(), html.Br(), desc1, desc2, html. P("Hover over the bars to check the sample size. " + "Larger sample size has a higher chance of yielding accurate statistics", style=styles.description_tablets_style) ] show_description["display"] = "inline-block" show_graph["display"] = "block" show_second_car = {**styles.drop_down_group_style, "display": "block"} first_vehicle_title = "Vehicle 1" elif tab == "tab-3": if all([ make_selected, model_selected, year_selected, trim_selected, mileage_selected ]): df = data.get_data(Make=make_selected, Model=model_selected) df.sort_values(by="Mileage", inplace=True) mileage_per_year = 12000 mileage_std = df.Mileage.std() mileage_std = round(mileage_std / 5000) * 5000 # Select only the dataframe columns relevant for estimating price df = df[["Mileage", "Year", "Price", "clean_trim"]] predicted, model, transform, score, trim_columns = estimate.main( df, mileage_per_year) # A scatter plot of mileage vs price marker = dict(color="rgb(82,188,163)") text = [ f"Year: {year}<br>Trim: {trim}" for year, trim in zip(df.Year.astype("int"), df.clean_trim) ] hovertemplate = "<br><i>Mileage</i>: %{x}<br>" + "<i>%{text}</i>" + \ "<br><i>Price</i>: $%{y}<br>" title = f"Regression Estimator: {year_selected} {make_selected} {model_selected}" fig = helper.create_plot("scatter", df.Mileage, df.Price, mode="markers", name="Data points", marker=marker, text=text, template=hovertemplate, title=title, xaxis_title="Mileage (miles)", yaxis_title="Price ($)", opacity=0.5) # Compute estimated average price using the reg. model mileage_selected = int(mileage_selected) if transform == "std": mileage = (mileage_selected - df.Mileage.mean()) / mileage_std elif transform == "log": mileage = np.log2(mileage_selected) trim_columns.remove("clean_trim_Other") trim_binary = [ 1 if column.strip("clean_trim_") == trim_selected else 0 for column in trim_columns ] estimated = int( model.predict( [[mileage, df.Year.max() - year_selected, *trim_binary]])[0]) print(f"Estimated Price {estimated}") print( f"R2 on Test {score}", f"Mileage coeff = {model.coef_[0]}, Year coff = {model.coef_[1]}", f"Other coefs: {model.coef_[2:]}") # Show estimate as a scatter plot marker = dict(color="#d64161", size=10) text = [f"Year: {year_selected}<br>Trim: {trim_selected}"] hovertemplate = "<br><i>Mileage</i>: %{x}<br>" + "<i>%{text}</i>" + \ "<br><i>Estimated Avg. Price</i>: $%{y}<br>" helper.create_plot("scatter", [mileage_selected], [estimated], mode="markers", name="Est. Average Price", marker=marker, text=text, template=hovertemplate, title=title, xaxis_title="Mileage (miles)", yaxis_title="Price ($)", base_fig=fig) # Generate and plot a 'trend line' using the reg model generated_mileage = list(range(0, 150000, mileage_per_year)) generated_year = [ int(df.Year.max() - (mileage // mileage_per_year)) for mileage in generated_mileage ] text = [f"Year: {year}" for year in generated_year] line = dict(color="#d64161", width=3) hovertemplate = "<br><i>Mileage</i>: %{x}<br>" + "<i>%{text}</i>" + \ "<br><i>Estimated Avg. Price</i>: $%{y}<br>" helper.create_plot("scatter", generated_mileage, predicted, mode="lines", name="Regression line", text=text, template=hovertemplate, line=line, base_fig=fig) description = helper.generate_description( df, "#d64161", make_selected, model_selected, year_selected, model, mileage_selected, estimated, score, mileage_std, style=styles.description_tablets_style) show_description["display"] = "inline-block" show_graph["display"] = "block" mileage_box = { **styles.drop_down_style, "margin-top": "10px", "width": "100%", "display": "block" } trim_box = { **styles.drop_down_style, "margin-top": "10px", "display": "block" } elif tab == "tab-4": description = html.P([ html.Font("This dashboard provides used car listing price "), html.Font("statistics and estimates. Listing prices are scrapped"), html.Font( " from major car listing websites on a weekly basis. The processed" ), html.Font( "data is stored in S3 and used to build estimation models. "), html.Font( "The figure on the side shows how the project is setup in AWS. Checkout the " ), html.A("Github page", href="https://github.com/mEyob/used-car-analytics", target="_blank") ], style=styles.description_tablets_style) show_arch_fig["display"] = "inline-block" show_description["display"] = "inline-block" show_first_car["display"] = "none" show_second_car["display"] = "none" return show_graph, show_description, description, fig, show_first_car, show_second_car, first_vehicle_title, mileage_box, trim_box, show_arch_fig
html.Div([ dcc.Input(id="stock-input", value="SPY", type="text"), html.Button(id="submit-button", n_clicks=0, children="Submit") ]), # Main Layout Div html.Div( [ # Display Stock Plot html.Div([dcc.Graph(id="graph_close", )], className="six columns"), # Display Market news feed (to do) html.Div( [ html.H3(html.Font("News Feed"), ), # Display the news from API news_table() ], className="six columns"), ], className="row") ]) ### Callbacks ### def Add_Dash(server): dash_app = Dash(server=server, url_base_pathname=url_base) apply_layout_with_auth(dash_app, layout)
import flask import datetime import time from apps import Home, AutumnChallenge, BigDayChallenge, NotYet, Admin, Prize from setting import app server = app.server app.layout = html.Div([ visdcc.Run_js(id='javascript'), dcc.Location(id='url', refresh=False), html.Nav([ html.A([ html.Font('e', style={'color': '#4ca800'}, className='EB'), html.Font('Bird', className='EB', style={'color': '#000000'}), html.Br(className="EB_sep"), html.Font(' Taiwan', style={'color': '#4ca800'}) ], style={'font-weight': '600'}, className='logo_title navbar-brand', href="/"), dbc.NavbarToggler(id="navbar-toggler"), dbc.Collapse([ html.Ul([ html.Li(html.A( '秋季大亂鬥', href='/big-month-challenge', className="NavLnks"), className="nav-item"), html.Li(html.A( '關渡觀鳥大日', href='/big-day-challenge', className="NavLnks"),