import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Load your pre-trained model (e.g., TensorFlow Keras model) # Replace "currency_model.h5" with the actual path to your model model = tf.keras.models.load_model("counterfeitmodel.h5") # Define the prediction function def detect_currency(image): """ Function to detect if the input image is of a real or fake currency note. :param image: Uploaded image (.jpg) :return: String indicating 'Real' or 'Fake' """ # Resize the image to match the input size expected by the model input_size = (200, 200) # Replace with your model's expected input size image = image.resize(input_size) # Convert the image to a NumPy array image_array = np.array(image) / 255.0 # Normalize pixel values to [0, 1] # Add batch dimension image_array = np.expand_dims(image_array, axis=0) # Perform prediction prediction = model.predict(image_array) # Assume the model outputs a probability for 'Real' (1) and 'Fake' (0) is_real = prediction[0][0] > 0.5 return "Real Currency Note" if is_real else "Fake Currency Note" css =""" #currency-image { border: 2px solid #00BFFF; border-radius: 10px; padding: 10px; } #prediction-output { font-size: 20px; font-weight: bold; color: #2c3e50; margin-top: 20px; text-align: center; background-color: #ecf0f1; border: 2px solid #00BFFF; border-radius: 10px; padding: 10px; } """ # Create the Gradio interface interface = gr.Interface( fn=detect_currency, # The function to run inputs=gr.Image(type="pil", label="Upload Currency Image (.jpg)"), # Input type outputs="text", # Output type title="Currency Note Detector", description="Upload a .jpg image of a currency note to check if it's real or fake.", theme=gr.themes.Base(), # Hugging Face theme for a professional look live=True, css=css, ) # Add the custom CSS to the interface # Launch the app interface.launch(share=True)