Spaces:
Sleeping
Sleeping
OmarEllethy
commited on
Commit
•
736a546
1
Parent(s):
2c625ad
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,61 @@
|
|
1 |
-
import subprocess
|
2 |
-
|
3 |
-
# Define the list of libraries to install with specific versions
|
4 |
-
libraries = [
|
5 |
-
'gradio==2.3.0',
|
6 |
-
'tensorflow==2.
|
7 |
-
'numpy==1.
|
8 |
-
'Pillow==8.4.0',
|
9 |
-
'opencv-python-headless==4.5.3.56', # 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 from the specified path
|
26 |
-
model_path = r"C:\Users\Administrator\Desktop\proj\imageclassifier.keras"
|
27 |
-
model = tf.keras.models.load_model(model_path)
|
28 |
-
|
29 |
-
# Define the function to predict the teeth health
|
30 |
-
def predict_teeth_health(image):
|
31 |
-
# Convert the PIL image object to a file-like object
|
32 |
-
image_bytes = io.BytesIO()
|
33 |
-
image.save(image_bytes, format="JPEG")
|
34 |
-
|
35 |
-
# Load the image from the file-like object
|
36 |
-
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
|
37 |
-
image = tf.keras.preprocessing.image.img_to_array(image)
|
38 |
-
image = np.expand_dims(image, axis=0)
|
39 |
-
|
40 |
-
# Make a prediction
|
41 |
-
prediction = model.predict(image)
|
42 |
-
|
43 |
-
# Get the probability of being 'Good'
|
44 |
-
probability_good = prediction[0][0] # Assuming it's a binary classification
|
45 |
-
|
46 |
-
# Return the predicted class name
|
47 |
-
if probability_good > 0.5:
|
48 |
-
return f"Predicted: Your Teeth are Good And You Don't Need To Visit Doctor"
|
49 |
-
else:
|
50 |
-
return f"Predicted: Your Teeth are Bad And You Need To Visit Doctor"
|
51 |
-
|
52 |
-
# Define the Gradio interface
|
53 |
-
iface = gr.Interface(
|
54 |
-
fn=predict_teeth_health,
|
55 |
-
inputs=gr.inputs.Image(type="pil"),
|
56 |
-
outputs="text",
|
57 |
-
title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1>",
|
58 |
-
)
|
59 |
-
|
60 |
-
# Deploy the Gradio interface using Gradio's hosting service
|
61 |
-
iface.launch(share=True)
|
|
|
1 |
+
import subprocess
|
2 |
+
|
3 |
+
# Define the list of libraries to install with specific versions
|
4 |
+
libraries = [
|
5 |
+
'gradio==2.3.0', # You can update to a more recent version if needed
|
6 |
+
'tensorflow==2.12.0', # Use a more recent version available on your platform
|
7 |
+
'numpy==1.21.0', # Compatible with TensorFlow 2.12.0
|
8 |
+
'Pillow==8.4.0',
|
9 |
+
'opencv-python-headless==4.5.3.56', # 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 from the specified path
|
26 |
+
model_path = r"C:\Users\Administrator\Desktop\proj\imageclassifier.keras"
|
27 |
+
model = tf.keras.models.load_model(model_path)
|
28 |
+
|
29 |
+
# Define the function to predict the teeth health
|
30 |
+
def predict_teeth_health(image):
|
31 |
+
# Convert the PIL image object to a file-like object
|
32 |
+
image_bytes = io.BytesIO()
|
33 |
+
image.save(image_bytes, format="JPEG")
|
34 |
+
|
35 |
+
# Load the image from the file-like object
|
36 |
+
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
|
37 |
+
image = tf.keras.preprocessing.image.img_to_array(image)
|
38 |
+
image = np.expand_dims(image, axis=0)
|
39 |
+
|
40 |
+
# Make a prediction
|
41 |
+
prediction = model.predict(image)
|
42 |
+
|
43 |
+
# Get the probability of being 'Good'
|
44 |
+
probability_good = prediction[0][0] # Assuming it's a binary classification
|
45 |
+
|
46 |
+
# Return the predicted class name
|
47 |
+
if probability_good > 0.5:
|
48 |
+
return f"Predicted: Your Teeth are Good And You Don't Need To Visit Doctor"
|
49 |
+
else:
|
50 |
+
return f"Predicted: Your Teeth are Bad And You Need To Visit Doctor"
|
51 |
+
|
52 |
+
# Define the Gradio interface
|
53 |
+
iface = gr.Interface(
|
54 |
+
fn=predict_teeth_health,
|
55 |
+
inputs=gr.inputs.Image(type="pil"),
|
56 |
+
outputs="text",
|
57 |
+
title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1>",
|
58 |
+
)
|
59 |
+
|
60 |
+
# Deploy the Gradio interface using Gradio's hosting service
|
61 |
+
iface.launch(share=True)
|