Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +65 -0
- feature_names.json +1 -0
- scaler.joblib +3 -0
- xgboost_breast_cancer_model.joblib +3 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[8]:
|
5 |
+
|
6 |
+
|
7 |
+
#!/usr/bin/env python
|
8 |
+
# coding: utf-8
|
9 |
+
|
10 |
+
# In[6]:
|
11 |
+
|
12 |
+
|
13 |
+
# app.py
|
14 |
+
import gradio as gr
|
15 |
+
import joblib
|
16 |
+
import json
|
17 |
+
import numpy as np
|
18 |
+
|
19 |
+
# Load the model and scaler
|
20 |
+
model = joblib.load('xgboost_breast_cancer_model.joblib')
|
21 |
+
scaler = joblib.load('scaler.joblib')
|
22 |
+
|
23 |
+
# Load feature names
|
24 |
+
with open('feature_names.json', 'r') as f:
|
25 |
+
feature_names = json.load(f)
|
26 |
+
|
27 |
+
def predict_cancer(*features):
|
28 |
+
# Convert inputs to numpy array
|
29 |
+
input_data = np.array(features).reshape(1, -1)
|
30 |
+
|
31 |
+
# Scale the input data
|
32 |
+
scaled_input = scaler.transform(input_data)
|
33 |
+
|
34 |
+
# Make prediction
|
35 |
+
prediction_proba = model.predict_proba(scaled_input)[0, 1]
|
36 |
+
|
37 |
+
# Apply threshold
|
38 |
+
prediction = "Malignant" if prediction_proba >= 0.4 else "Benign"
|
39 |
+
|
40 |
+
return f"Prediction: {prediction}\nProbability of being malignant: {prediction_proba:.2f}"
|
41 |
+
|
42 |
+
# Create Gradio interface
|
43 |
+
iface = gr.Interface(
|
44 |
+
fn=predict_cancer,
|
45 |
+
inputs=[gr.Number(label=name) for name in feature_names],
|
46 |
+
outputs="text",
|
47 |
+
title="Breast Cancer Prediction",
|
48 |
+
description="Enter the feature values to predict whether a breast mass is benign or malignant."
|
49 |
+
)
|
50 |
+
|
51 |
+
iface.launch()
|
52 |
+
|
53 |
+
|
54 |
+
# In[ ]:
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
# In[ ]:
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
feature_names.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
["concave points_worst", "perimeter_worst", "concave points_mean", "radius_worst", "perimeter_mean", "area_worst"]
|
scaler.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:18cb378aa97b540ef898aee2b95462b03553acb9d675c6afd1b36f1a1ad74fa5
|
3 |
+
size 1181
|
xgboost_breast_cancer_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ae834ee3f7ad316082560834a1ab63fb545af1cbc9c133dd6ab6abaa5c4802b8
|
3 |
+
size 114459
|