SmitaMahajan's picture
Upload 3 files
8cf4de0 verified
raw
history blame contribute delete
907 Bytes
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from PIL import Image
# Load model
model = load_model("trained_image_model.h5")
class_labels = ['original', 'screen_photo', 'screenshots']
# Prediction function
def predict_image(img: Image.Image):
img = img.resize((224, 224))
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
prediction = model.predict(img_array)
predicted_class = np.argmax(prediction, axis=1)[0]
return class_labels[predicted_class]
# Gradio UI
interface = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="pil"),
outputs="text",
title="📸 Image Type Classifier",
description="Upload an image to classify it as: Original Photo, Screen Photo, or Screenshot."
)
interface.launch()