K-A-Uthman commited on
Commit
e4a27d7
·
verified ·
1 Parent(s): 7bbdb34

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tensorflow.keras.applications import ResNet50
2
+ from tensorflow.keras.preprocessing import image
3
+ from tensorflow.keras.applications.resnet50 import preprocess_input
4
+ import numpy as np
5
+
6
+ from sklearn.ensemble import RandomForestClassifier
7
+ import gradio as gr
8
+ from joblib import load
9
+
10
+
11
+ # Load pre-trained ResNet50 model without top layers
12
+ base_model = ResNet50(weights='imagenet', include_top=False)
13
+
14
+ # Function to extract features using ResNet50
15
+ def extract_resnet_features(img_path):
16
+ img = image.load_img(img_path, target_size=(224, 224))
17
+ x = image.img_to_array(img)
18
+ x = np.expand_dims(x, axis=0)
19
+ x = preprocess_input(x)
20
+ features = base_model.predict(x)
21
+ features_flattened = features.flatten()
22
+ return features_flattened
23
+
24
+
25
+ # Load the trained Random Forest classifier
26
+ rf_classifier = load('random_forest_model2.joblib')
27
+
28
+ # Function to make predictions
29
+ def predict(image):
30
+ # Convert image to feature vector using ResNet50 (you can replace this with your feature extraction method)
31
+ features = extract_resnet_features(image)
32
+
33
+ # Make prediction using Random Forest classifier
34
+ prediction = rf_classifier.predict([features])[0]
35
+
36
+ return prediction
37
+
38
+ # Define Gradio interface
39
+ iface = gr.Interface(fn=predict, inputs="image", outputs="text", title="Brain Tumor Classification")
40
+ iface.launch()