Suhani-2407's picture
Update app.py
c35e9aa verified
raw
history blame
870 Bytes
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Disable GPU warnings
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load model
model = tf.keras.models.load_model("MobileNet_model.h5")
class_names = ["Fake", "Low", "Medium", "High"]
def predict_image(img):
img = img.resize((128, 128))
img_array = np.array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
predictions = model.predict(img_array)
class_index = np.argmax(predictions, axis=1)[0]
confidence_scores = {class_names[i]: float(predictions[0][i]) for i in range(len(class_names))}
return {"Predicted Class": class_names[class_index], "Confidence Scores": confidence_scores}
iface = gr.Interface(fn=predict_image, inputs="image", outputs="json")
iface.launch(server_name="0.0.0.0", server_port=7860) # Fix for Hugging Face