File size: 870 Bytes
c35e9aa
 
 
d41eab8
 
 
 
 
c35e9aa
 
 
d41eab8
c35e9aa
 
 
 
 
 
 
 
d41eab8
c35e9aa
 
d41eab8
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
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