OmarEllethy commited on
Commit
0f3534a
1 Parent(s): 2e0e034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -27
app.py CHANGED
@@ -1,14 +1,13 @@
1
  import subprocess
2
- import os
3
 
4
- # Define the list of libraries to install with specific versions
5
  libraries = [
6
- 'gradio==2.3.0', # You can update to a more recent version if needed
7
- 'tensorflow==2.12.0', # Use a more recent version available on your platform
8
- 'numpy==1.23.5', # Compatible with TensorFlow 2.12.0 and newer versions of matplotlib
9
- 'Pillow==8.4.0',
10
- 'opencv-python-headless==4.5.5.62', # This installs OpenCV without GUI support
11
- 'pandas==1.4.2', # Ensure compatibility with numpy
12
  ]
13
 
14
  # Install each library using pip
@@ -24,17 +23,8 @@ import numpy as np
24
  from PIL import Image
25
  import io
26
 
27
- # Load the pre-trained TensorFlow model from the specified path
28
- model_path = "imageclassifier.h5"
29
-
30
- # Check if the model file exists
31
- if not os.path.exists(model_path):
32
- raise FileNotFoundError(f"Model file not found at path: {model_path}")
33
-
34
- try:
35
- model = tf.keras.models.load_model(model_path, custom_objects=None, compile=True)
36
- except Exception as e:
37
- raise IOError(f"Error loading model from {model_path}: {e}")
38
 
39
  # Define the function to predict the teeth health
40
  def predict_teeth_health(image):
@@ -53,18 +43,19 @@ def predict_teeth_health(image):
53
  # Get the probability of being 'Good'
54
  probability_good = prediction[0][0] # Assuming it's a binary classification
55
 
56
- # Return the predicted class name
57
- if probability_good > 0.5:
58
- return f"Predicted: Your Teeth are Good And You Don't Need To Visit Doctor"
59
- else:
60
- return f"Predicted: Your Teeth are Bad And You Need To Visit Doctor"
 
61
 
62
  # Define the Gradio interface
63
  iface = gr.Interface(
64
  fn=predict_teeth_health,
65
- inputs=gr.inputs.Image(type="pil"),
66
- outputs="text",
67
- title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1>",
68
  )
69
 
70
  # Deploy the Gradio interface using Gradio's hosting service
 
1
  import subprocess
 
2
 
3
+ # Define the list of libraries to install
4
  libraries = [
5
+ 'gradio',
6
+ 'tensorflow',
7
+ 'numpy',
8
+ 'Pillow',
9
+ 'opencv-python-headless',
10
+ 'Flask' # Add Flask here
11
  ]
12
 
13
  # Install each library using pip
 
23
  from PIL import Image
24
  import io
25
 
26
+ # Load the pre-trained TensorFlow model
27
+ model = tf.keras.models.load_model("imageclassifier.h5")
 
 
 
 
 
 
 
 
 
28
 
29
  # Define the function to predict the teeth health
30
  def predict_teeth_health(image):
 
43
  # Get the probability of being 'Good'
44
  probability_good = prediction[0][0] # Assuming it's a binary classification
45
 
46
+ # Define the prediction result
47
+ result = {
48
+ "prediction": "Your Teeth are Good & You Don't Need To Visit Doctor" if probability_good > 0.5 else "Your Teeth are Bad & You Need To Visit Doctor"
49
+ }
50
+
51
+ return result
52
 
53
  # Define the Gradio interface
54
  iface = gr.Interface(
55
  fn=predict_teeth_health,
56
+ inputs=gr.Image(type="pil"),
57
+ outputs="json",
58
+ title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1><p style='text-align: center; color: skyblue; font-size: 30px;'>Please Enter Your Teeth Here...</p>",
59
  )
60
 
61
  # Deploy the Gradio interface using Gradio's hosting service