Papizee commited on
Commit
a7b9d60
·
verified ·
1 Parent(s): 82cb722

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -3,9 +3,8 @@ import numpy as np
3
  from PIL import Image
4
  from tensorflow.keras.models import load_model
5
  from tensorflow.keras.preprocessing import image
6
- import os
7
 
8
- # Load model
9
  print("Loading MobileNetV2 model...")
10
  try:
11
  model = load_model("model.keras")
@@ -22,10 +21,10 @@ class_names = [
22
 
23
  def predict_image(img):
24
  if model is None:
25
- return "Model failed to load. Please check logs.", {}
26
 
27
  try:
28
- # Preprocess
29
  img = img.resize((224, 224))
30
  img_array = image.img_to_array(img)
31
  img_array = np.expand_dims(img_array, axis=0)
@@ -42,10 +41,10 @@ def predict_image(img):
42
  return result, confidences
43
 
44
  except Exception as e:
45
- return f"Error during prediction: {str(e)}", {}
46
 
47
- # Gradio Interface
48
- interface = gr.Interface(
49
  fn=predict_image,
50
  inputs=gr.Image(type="pil", label="Upload Oral Image"),
51
  outputs=[
@@ -53,9 +52,10 @@ interface = gr.Interface(
53
  gr.JSON(label="Confidence Scores")
54
  ],
55
  title="🦷 OralScan AI - Oral Lesion Classifier",
56
- description="MobileNetV2 model for detecting oral white lesions",
57
- allow_flagging="never"
 
58
  )
59
 
60
  if __name__ == "__main__":
61
- interface.launch(server_name="0.0.0.0", server_port=7860)
 
3
  from PIL import Image
4
  from tensorflow.keras.models import load_model
5
  from tensorflow.keras.preprocessing import image
 
6
 
7
+ # Load the model
8
  print("Loading MobileNetV2 model...")
9
  try:
10
  model = load_model("model.keras")
 
21
 
22
  def predict_image(img):
23
  if model is None:
24
+ return "Error: Model failed to load. Please check if model.keras is uploaded.", {}
25
 
26
  try:
27
+ # Preprocess image
28
  img = img.resize((224, 224))
29
  img_array = image.img_to_array(img)
30
  img_array = np.expand_dims(img_array, axis=0)
 
41
  return result, confidences
42
 
43
  except Exception as e:
44
+ return f"Prediction error: {str(e)}", {}
45
 
46
+ # Gradio Interface (updated for newer Gradio)
47
+ demo = gr.Interface(
48
  fn=predict_image,
49
  inputs=gr.Image(type="pil", label="Upload Oral Image"),
50
  outputs=[
 
52
  gr.JSON(label="Confidence Scores")
53
  ],
54
  title="🦷 OralScan AI - Oral Lesion Classifier",
55
+ description="Upload an image to detect oral white lesions using MobileNetV2",
56
+ examples=None,
57
+ flagging_mode="never" # Updated parameter name
58
  )
59
 
60
  if __name__ == "__main__":
61
+ demo.launch(server_name="0.0.0.0", server_port=7860)