File size: 1,888 Bytes
4757fa5
 
 
 
 
 
 
 
92883dd
 
4757fa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d55adb
 
 
 
 
 
4757fa5
 
 
 
 
9d55adb
 
4757fa5
 
 
92883dd
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',
    'Flask'  # Add Flask here
]

# 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

    # Define the prediction result
    result = {
        "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"
    }

    return result

# Define the Gradio interface
iface = gr.Interface(
    fn=predict_teeth_health,
    inputs=gr.Image(type="pil"),
    outputs="json",
    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>",
)

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