Spaces:
Sleeping
Sleeping
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) | |