SocialAI commited on
Commit
7afb0b9
·
verified ·
1 Parent(s): adf31a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -1,12 +1,22 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  import tensorflow
 
 
 
4
  import os
5
 
 
 
 
6
  # returning classifiers output
7
- def image_classifier(inp):
 
 
 
8
 
9
- return None
 
10
 
11
  with gr.Blocks() as demo:
12
  gr.Markdown("# Lung Cancer Classifier")
@@ -16,5 +26,11 @@ with gr.Blocks() as demo:
16
  submit_btn = gr.Button("Detect Cancer")
17
  with gr.Column():
18
  output_text = gr.Textbox(label="Model Results")
 
 
 
 
 
 
19
 
20
  demo.launch()
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  import tensorflow
4
+ import tensorflow as tf
5
+ from tensorflow.keras.preprocessing import image
6
+ import numpy as np
7
  import os
8
 
9
+ model = tf.keras.models.load_model("fine_tuned_resnet50.h5")
10
+ img_dim = (224, 224)
11
+
12
  # returning classifiers output
13
+ def predict(img):
14
+ img = img.resize(img_dim)
15
+ img_array = image.img_to_array(img) / 255.0
16
+ img_array = np.expand_dims(img_array, axis=0)
17
 
18
+ prediction = model.predict(img_array)
19
+ return prediction
20
 
21
  with gr.Blocks() as demo:
22
  gr.Markdown("# Lung Cancer Classifier")
 
26
  submit_btn = gr.Button("Detect Cancer")
27
  with gr.Column():
28
  output_text = gr.Textbox(label="Model Results")
29
+
30
+ submit_btn.click(
31
+ fn=predict,
32
+ inputs=[input_image],
33
+ outputs=[output_text]
34
+ )
35
 
36
  demo.launch()