File size: 1,814 Bytes
c49ee94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import subprocess

# Define the list of libraries to install
libraries = [
    'gradio',
    'tensorflow',
    'numpy',
    'Pillow',
    'opencv-python-headless',  # This installs OpenCV without GUI support
]

# Install each library using pip
for library in libraries:
    try:
        subprocess.check_call(['pip', 'install', library])
    except subprocess.CalledProcessError as e:
        print(f"Error installing {library}: {e}")

import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
import io

# Load the pre-trained TensorFlow model
model = tf.keras.models.load_model("imageclassifier.h5")

# Define the function to predict the teeth health
def predict_teeth_health(image):
    # Convert the PIL image object to a file-like object
    image_bytes = io.BytesIO()
    image.save(image_bytes, format="JPEG")

    # Load the image from the file-like object
    image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
    image = tf.keras.preprocessing.image.img_to_array(image)
    image = np.expand_dims(image, axis=0)

    # Make a prediction
    prediction = model.predict(image)

    # Get the probability of being 'Good'
    probability_good = prediction[0][0]  # Assuming it's a binary classification

    # Return the predicted class name
    if probability_good > 0.5:
        return f"Predicted: Your Teeth are Good And You Don't Need To Visit Doctor"
    else:
        return f"Predicted: Your Teeth are Bad And You Need To Visit Doctor"

# Define the Gradio interface
iface = gr.Interface(
    fn=predict_teeth_health,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="<h1 style='color: lightgreen; text-align: center;'>Dentella</h1>",
)

# Deploy the Gradio interface using Gradio's hosting service
iface.launch(share=True)