Spaces:
Runtime error
Runtime error
| from logging import PlaceHolder | |
| import gradio as gr | |
| import numpy as np | |
| import pandas as pd | |
| import pickle | |
| def infer(cylinder, bore, stroke, cooling): | |
| with open('df_model.bin', 'rb') as f: | |
| (encoder_engine, encoder_transmission, encoder_cooling, model) = pickle.load(f) | |
| X = [[cylinder, bore, stroke, cooling]] | |
| X = pd.DataFrame(X, columns=['Engine cylinder', 'Bore (mm)', 'Stroke (mm)', 'Cooling system']) | |
| moto1_pred = np.absolute(model.predict(X)) | |
| moto1_pred = np.round(moto1_pred, 2) | |
| return f"The power output of the engine will be around {moto1_pred}hp" | |
| with gr.Blocks() as demo: | |
| gr.Markdown(""" | |
| <p style="text-align:center"> | |
| <h2>Welcome to the Motorcycle Engine Power Calculator!!!</h2> | |
| It uses a Ridge Regression Model to predict the possible power output of an engine with such given specifications. | |
| If you are here and don't now any engine specs you can use the cool Yamaha XT660R engine just for fun, here you go: | |
| Bore = 100mm | |
| Stroke = 84mm | |
| Engine configuration= Single Cylinder | |
| Cooling system = Liquid | |
| With this you should get something around 48hp of output... | |
| Buuuut the mean absolute error of the model it's still a little high, so don't worry if you got something around 51hp. | |
| The idea it's give to the designer a raw insight about that crazy engine he's been thinking about without the need of any calculations... | |
| I hope you enjoy. | |
| Any feedbacks are welcome, dm me in @ckmoraiz (twitter or IG)! | |
| """ | |
| ) | |
| bore = gr.Number(label="Bore size in mm:") | |
| stroke = gr.Number(label="Stroke size in mm:") | |
| cylinders = ['Diesel', 'Four cylinder boxer', 'In-line four', 'In-line six', 'In-line three', 'Single cylinder', | |
| 'Six cylinder boxer', 'Square four cylinder', 'Twin', 'Two cylinder boxer', 'V2', 'V3', 'V4', 'V6', 'V8'] | |
| cylinder = gr.Radio(choices=cylinders, type="index", label="Choose the engine configuration:") | |
| coolers = ['Air', 'Liquid', 'Oil & Air'] | |
| cooling = gr.Radio(choices=coolers, type="index", label="Choose the cooling system type:") | |
| specs = [cylinder, bore, stroke, cooling] | |
| b1 = gr.Button("Calculate engine power!") | |
| out = gr.Textbox(label="Output") | |
| b1.click(fn=infer, inputs=specs, outputs=out) | |
| demo.launch() |