OmarEllethy commited on
Commit
c49ee94
1 Parent(s): fe2c201

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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', # This installs OpenCV without GUI support
10
+ ]
11
+
12
+ # Install each library using pip
13
+ for library in libraries:
14
+ try:
15
+ subprocess.check_call(['pip', 'install', library])
16
+ except subprocess.CalledProcessError as e:
17
+ print(f"Error installing {library}: {e}")
18
+
19
+ import gradio as gr
20
+ import tensorflow as tf
21
+ import numpy as np
22
+ from PIL import Image
23
+ import io
24
+
25
+ # Load the pre-trained TensorFlow model
26
+ model = tf.keras.models.load_model("imageclassifier.h5")
27
+
28
+ # Define the function to predict the teeth health
29
+ def predict_teeth_health(image):
30
+ # Convert the PIL image object to a file-like object
31
+ image_bytes = io.BytesIO()
32
+ image.save(image_bytes, format="JPEG")
33
+
34
+ # Load the image from the file-like object
35
+ image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
36
+ image = tf.keras.preprocessing.image.img_to_array(image)
37
+ image = np.expand_dims(image, axis=0)
38
+
39
+ # Make a prediction
40
+ prediction = model.predict(image)
41
+
42
+ # Get the probability of being 'Good'
43
+ probability_good = prediction[0][0] # Assuming it's a binary classification
44
+
45
+ # Return the predicted class name
46
+ if probability_good > 0.5:
47
+ return f"Predicted: Your Teeth are Good And You Don't Need To Visit Doctor"
48
+ else:
49
+ return f"Predicted: Your Teeth are Bad And You Need To Visit Doctor"
50
+
51
+ # Define the Gradio interface
52
+ iface = gr.Interface(
53
+ fn=predict_teeth_health,
54
+ inputs=gr.Image(type="pil"),
55
+ outputs="text",
56
+ title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1>",
57
+ )
58
+
59
+ # Deploy the Gradio interface using Gradio's hosting service
60
+ iface.launch(share=True)
61
+
62
+