File size: 4,910 Bytes
a34aae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import gradio as gr
from SVM.SVM_C import SVM_Classifier
from SVM.SVM_R import SVM_Regressor

class SVM_UI():
    def __init__(self):
        #self.svm = SVM_Classifier()
        self.svm = SVM_Regressor()

    def predict(self, weight, height, gender, fat, freq, experience, duration, workout):
        # Update the SVM model with current values
        self.svm.weight = weight
        self.svm.height = height
        self.svm.gender = gender
        self.svm.fat = fat
        self.svm.freq = freq
        self.svm.experience = experience
        self.svm.duration = duration
        self.svm.workout = workout
        
        # Get prediction and debug info
        prediction = self.svm.make_prediction()
        debug_info = self.svm.get_debug_info()
        
        return prediction, debug_info

    def get_interface(self) -> gr.Blocks:

        result_text = gr.Textbox(label="Modify the settings to check how much water should you take:",interactive=False)

        debug_text = gr.Textbox(label="Debug Information", interactive=False, lines=20, info="This is for the one who made this site... do not worry about this ;)")  # Make it bigger for debug info

        with gr.Blocks() as interface:
            gr.Markdown("hello world!")
            gr.Markdown("In this model we are using a Support Vector Machine tuned for a regression target.")
            gr.Markdown("Based on the information you provide, the model will recommend the amount of water (in litres) you need to consume for your intended workout session.")

            inputs = []

            with gr.Column():
                gr.HTML("<hr style='border: 1px solid #ccc; width: 100%;'>")

            with gr.Column():
                gr.Markdown("# Water consumption for workout session")
                gr.Markdown("How much water should you take with you for your next workout session:")
                result_text.render()

            with gr.Row():
                with gr.Column():# as network_parameters_ui:
                    gr.Markdown("# About you")

                    slider1 = gr.Slider(40, 140, value=self.svm.weight, step=1.0, label="Weight (kg)", interactive=True)
                    inputs.append(slider1)

                    slider2 = gr.Slider(1.5, 2.2, value=self.svm.height, step=0.01, label="Height (m)", interactive=True)
                    inputs.append(slider2)

                    radio1 = gr.Radio(["Male", "Female"], value=self.svm.gender, label="Gender", interactive=True)
                    inputs.append(radio1)

                with gr.Column():# as network_parameters_ui:
                    gr.Markdown("# Your fitness level")

                    slider4 = gr.Slider(20, 70, value=self.svm.fat, step=1.0, label="Fat percentage (%)", info="What is the percentage fat in your body?",interactive=True)
                    inputs.append(slider4)
                    
                    slider5 = gr.Slider(1, 5, value=self.svm.freq, step=1.0, label="Workouts a week", info="How many times a week do you go to the gym?",interactive=True)
                    inputs.append(slider5)
                   
                    slider6 = gr.Slider(1, 3, value=self.svm.experience, step=1.0, label="Experience level", info="1 = Beginner; 3 = Very experienced?",interactive=True)
                    inputs.append(slider6)

            with gr.Column():
                gr.Markdown("# Your session today")

                slider3 = gr.Slider(0.1, 2.0, value=self.svm.duration, step=0.1, label="Session duration (hours)", info="How long are you planning to exercise today?",interactive=True)
                inputs.append(slider3)

                radio2 = gr.Radio(["Cardio", "HIIT", "Strength","Yoga"], value=self.svm.workout, label="Workout type", info="What are you planning to do today?", interactive=True)
                inputs.append(radio2)

            with gr.Column():
                gr.HTML("<hr style='border: 1px solid #ccc; width: 100%;'>")
            
            with gr.Column():
                debug_text.render()
            
            #predict_btn = gr.Button("Get Water recommendation", variant="primary")
            
            #result_text = gr.Textbox(label="Recommendation",interactive=False)

            #debug_text = gr.Textbox(label="Debug Information", interactive=False, lines=20)  # Make it bigger for debug info
            
            #predict_btn.click(fn=self.predict, inputs=inputs, outputs=[result_text, debug_text])

            # Add debounced change event handlers to all inputs
            for input_component in inputs:
                input_component.change(
                    fn=self.predict,
                    inputs=inputs,
                    outputs=[result_text, debug_text]
                )
        
        return interface