Nahiyan14 commited on
Commit
23dfbf5
·
verified ·
1 Parent(s): 06a776d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -60
app.py CHANGED
@@ -1,60 +1,60 @@
1
- import gradio as gr
2
- import pandas as pd
3
- from pycaret.classification import load_model
4
-
5
- # Load the saved model
6
- model = load_model('best_automl_model')
7
-
8
- # Prediction function
9
- def predict_anemia(sex, red_pixel, green_pixel, blue_pixel):
10
- # Map input values to a DataFrame
11
- input_data = pd.DataFrame({
12
- 'Red Pixel': [red_pixel],
13
- 'Green Pixel': [green_pixel],
14
- 'Blue Pixel': [blue_pixel],
15
- 'Sex': [1 if sex == "Male" else 0] # Encode 'Male' as 1, 'Female' as 0
16
- })
17
-
18
- # Make predictions
19
- prediction = model.predict(input_data)[0]
20
- probability = model.predict_proba(input_data)[0][1]
21
-
22
- # Convert results
23
- prediction_label = "Yes" if prediction == 1 else "No"
24
- return prediction_label, f"{probability:.2%}" # Probability as a percentage
25
-
26
- # Define input components with better labels and layout
27
- inputs = [
28
- gr.Radio(["Male", "Female"], label="Sex", interactive=True),
29
- gr.Slider(0, 100, step=0.1, label="Red Pixel Percentage (%)"),
30
- gr.Slider(0, 100, step=0.1, label="Green Pixel Percentage (%)"),
31
- gr.Slider(0, 100, step=0.1, label="Blue Pixel Percentage (%)"),
32
- ]
33
-
34
- # Define output components
35
- outputs = [
36
- gr.Textbox(label="Prediction", interactive=False),
37
- gr.Textbox(label="Probability of Anemia (%)", interactive=False),
38
- ]
39
-
40
- # Create the Gradio Interface
41
- interface = gr.Interface(
42
- fn=predict_anemia,
43
- inputs=inputs,
44
- outputs=outputs,
45
- title="Anemia Prediction App",
46
- description=(
47
- "This app predicts whether a person is anemic based on the percentages of red, "
48
- "green, and blue pixels in their image and their sex. "
49
- "Simply adjust the sliders and select the person's sex to get a prediction."
50
- ),
51
- theme="huggingface", # Optional theme
52
- live=False, # Turn off live predictions for better performance
53
- examples=[
54
- ["Male", 45.0, 30.0, 25.0],
55
- ["Female", 50.0, 28.0, 22.0],
56
- ],
57
- )
58
-
59
- # Launch the app
60
- interface.launch()
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from pycaret.classification import load_model
4
+
5
+ # Load the saved model
6
+ model = load_model('best_automl_model')
7
+
8
+ # Prediction function
9
+ def predict_anemia(sex, red_pixel, green_pixel, blue_pixel):
10
+ # Map input values to a DataFrame
11
+ input_data = pd.DataFrame({
12
+ 'Red Pixel': [red_pixel],
13
+ 'Green Pixel': [green_pixel],
14
+ 'Blue Pixel': [blue_pixel],
15
+ 'Sex': [1 if sex == "Male" else 0] # Encode 'Male' as 1, 'Female' as 0
16
+ })
17
+
18
+ # Make predictions
19
+ prediction = model.predict(input_data)[0]
20
+ probability = model.predict_proba(input_data)[0][1]
21
+
22
+ # Convert results
23
+ prediction_label = "Yes" if prediction == 1 else "No"
24
+ return prediction_label, f"{probability:.2%}" # Probability as a percentage
25
+
26
+ # Define input components with better labels and layout
27
+ inputs = [
28
+ gr.Radio(["Male", "Female"], label="Sex", interactive=True),
29
+ gr.Slider(0, 100, step=0.1, label="Red Pixel Percentage (%)"),
30
+ gr.Slider(0, 100, step=0.1, label="Green Pixel Percentage (%)"),
31
+ gr.Slider(0, 100, step=0.1, label="Blue Pixel Percentage (%)"),
32
+ ]
33
+
34
+ # Define output components
35
+ outputs = [
36
+ gr.Textbox(label="Prediction", interactive=False),
37
+ gr.Textbox(label="Probability of Anemia (%)", interactive=False),
38
+ ]
39
+
40
+ # Create the Gradio Interface
41
+ interface = gr.Interface(
42
+ fn=predict_anemia,
43
+ inputs=inputs,
44
+ outputs=outputs,
45
+ title="Anemia Prediction App",
46
+ description=(
47
+ "This app predicts whether a person is anemic based on the percentages of red, "
48
+ "green, and blue pixels in their image and their sex. "
49
+ "Simply adjust the sliders and select the person's sex to get a prediction."
50
+ ),
51
+ theme="huggingface", # Optional theme
52
+ live=False, # Turn off live predictions for better performance
53
+ examples=[
54
+ ["Male", 45.0, 30.0, 25.0],
55
+ ["Female", 50.0, 28.0, 22.0],
56
+ ],
57
+ )
58
+
59
+ # Launch the app
60
+ interface.launch()