JanardhanM/no-reference-iqa
0
1import gradio as gr2import cv23import numpy as np4import tensorflow as tf5 6# Load the trained model (Fixed path issue)7model = tf.keras.models.load_model("model/modelnriqa_model.keras")8 9# Function to classify image quality10def predict_quality(image):11 img = cv2.resize(image, (224, 224)) # Resize to model input size12 img = img / 255.0 # Normalize13 img = np.expand_dims(img, axis=0) # Add batch dimension14 mos_score = model.predict(img)[0][0] # Get predicted score15 print(mos_score)16 # Convert MOS Score to Category17 if mos_score >= 4.5:18 category = "๐ Excellent"19 elif mos_score > 4.2:20 category = "Average"21 elif mos_score > 3:22 category = "Poor"23 else:24 category = "๐จ Very Poor"25 26 return f"Predicted Quality: {category}"27 28# Create Gradio UI29iface = gr.Interface(30 fn=predict_quality,31 inputs=gr.Image(type="numpy"),32 outputs="text",33 title="๐ธ No-Reference Image Quality Classifier",34 description="Upload an image and get its quality category."35)36 37# Launch the app (Fix if localhost issue occurs)38iface.launch(share=True) # Use share=True to get a public link39 