isshagle commited on
Commit
e60e045
1 Parent(s): 35fd5e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sklearn.datasets import load_breast_cancer
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.linear_model import LogisticRegression
6
+ from sklearn.preprocessing import StandardScaler
7
+ from sklearn.metrics import accuracy_score
8
+
9
+ # Load the breast cancer dataset
10
+ data = load_breast_cancer()
11
+ X = pd.DataFrame(data.data, columns=data.feature_names)
12
+ y = pd.Series(data.target)
13
+
14
+ # Split the dataset into training and testing sets
15
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
16
+
17
+ # Standardize the features
18
+ scaler = StandardScaler()
19
+ X_train = scaler.fit_transform(X_train)
20
+ X_test = scaler.transform(X_test)
21
+
22
+ # Create and train a logistic regression model
23
+ model = LogisticRegression()
24
+ model.fit(X_train, y_train)
25
+
26
+ # Define a function for prediction
27
+ def predict_cancer(*input_data):
28
+ # Preprocess the input data
29
+ input_data = [float(val) for val in input_data]
30
+ input_data = scaler.transform([input_data]) # Standardize input data
31
+ prediction = model.predict(input_data)
32
+ if prediction[0] == 0:
33
+ result = "Malignant"
34
+ else:
35
+ result = "Benign"
36
+
37
+ y_pred = model.predict(X_test)
38
+ accuracy = accuracy_score(y_test, y_pred)
39
+ #return (result, accuracy_score)
40
+ return f"Prediction: {result}, Accuracy: {accuracy:.2f}"
41
+
42
+ # Create a Gradio interface
43
+ input_component = gr.Interface(
44
+ fn=predict_cancer,
45
+ inputs=[gr.inputs.Number(label=feature) for feature in data.feature_names],
46
+ outputs="text",
47
+ examples = [
48
+ [13.21, 25.25, 84.1, 537.9, 0.08791, 0.05205, 0.02772, 0.02068, 0.1619, 0.05584, 0.2084, 1.35, 1.314, 17.58, 0.003047, 0.00781, 0.00511, 0.003749, 0.006471, 0.001095, 14.87, 38.97, 99.59, 698.8, 0.1162, 0.1711, 0.2282, 0.1282, 0.2871, 0.06917],
49
+ [9.029, 17.33, 58.79, 250.5, 0.1066, 0.1413, 0.313, 0.04375, 0.2111, 0.08046, 0.3274, 1.194, 2.157, 20.96, 0.01284, 0.03088, 0.05025, 0.01055, 0.02461, 0.004711, 10.31, 22.65, 65.5, 324.7, 0.1482, 0.4365, 1.252, 0.175, 0.4228, 0.1175],
50
+ [20.29, 14.34, 135.1, 1297, 0.1003, 0.1328, 0.198, 0.1043, 0.1809, 0.05883, 0.7572, 0.7813, 5.438, 94.44, 0.01149, 0.02461, 0.05688, 0.01885, 0.01756, 0.005115, 22.65, 18.1, 146.7, 1600, 0.1412, 0.2772, 0.8216, 0.1571, 0.3108, 0.1259],
51
+ [12.34, 12.27, 78.94, 468.5, 0.09003, 0.06307, 0.02958, 0.02647, 0.1689, 0.05808, 0.1166, 0.4957, 1.344, 8.966, 0.006808, 0.0187, 0.0198, 0.01185, 0.02037, 0.0027, 13.61, 19.27, 87.22, 564.9, 0.1292, 0.2074, 0.1791, 0.107, 0.311, 0.07592]
52
+ ],
53
+ description = " Press flag if any erroneous output comes ",
54
+ theme=gr.themes.Soft(),
55
+ title = "Breast Cancer Predictor Model",
56
+ live = True
57
+
58
+ )
59
+
60
+
61
+ # Launch the Gradio interface
62
+ input_component.launch(share=True, inline = False, debug=True)