Spaces:
Build error
Build error
Upload 3 files
Browse files- app.py +60 -0
- best_automl_model.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +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()
|
best_automl_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b2380025f163eeb045e823c58b5ce95106d54622ee3b460c6f7bfd89657c4d70
|
| 3 |
+
size 4375
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
pycaret
|
| 4 |
+
scikit-learn
|