File size: 2,597 Bytes
2791cb8
9722cdb
0eb59cf
 
4a983a7
0f47eda
9722cdb
e30f101
4a983a7
 
 
 
0eb59cf
 
e30f101
0eb59cf
 
 
 
 
 
 
 
 
516407d
65ed2db
6337357
 
 
feff429
 
 
3afe5a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feff429
 
 
6337357
 
feff429
185960e
 
3ae7d4a
6337357
185960e
3ae7d4a
feff429
6337357
feff429
1d1ebdf
e0d39d2
1d1ebdf
0eb59cf
860a259
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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()