#+--------------------------------------------------------------------------------------------+ # Breast Cancer Prediction # Using Neural Networks and Tensorflow # Prediction using Gradio on Hugging Face # Written by: Prakash R. Kota # Written on: 12 Feb 2025 # Last update: 12 Feb 2025 # Data Set from # Original: # https://archive.ics.uci.edu/dataset/17/breast+cancer+wisconsin+diagnostic # With Header: # https://www.kaggle.com/code/nancyalaswad90/analysis-breast-cancer-prediction-dataset # # Input Data Format for Gradio must be in the above header format with 30 features # The header has 32 features listed, but ignore the first 2 header columns #+--------------------------------------------------------------------------------------------+ import tensorflow as tf import numpy as np import gradio as gr import joblib # Load the trained model model = tf.keras.models.load_model("PRK_BC_NN_Model.keras") # Load the saved Scaler scaler = joblib.load("PRK_BC_NN_Scaler.pkl") # Function to process input and make predictions def predict(input_text): # Convert input string into a NumPy array of shape (1, 30) input_data = np.array([list(map(float, input_text.split(",")))]) # Ensure the input shape is correct if input_data.shape != (1, 30): return "Error: Please enter exactly 30 numerical values separated by commas." # Transform the input data using the loded scaler input_data_scaled = scaler.transform(input_data) # Make a prediction prediction = model.predict(input_data_scaled) # Convert prediction to a binary outcome (assuming classification) result = "Malignant" if prediction[0][0] > 0.5 else "Benign" return f"Prediction: {result} (Confidence: {prediction[0][0]:.2f})" import gradio as gr # Create the Gradio interface interface = gr.Interface( fn=predict, inputs=gr.Textbox(label="Enter 30 feature values, comma-separated"), outputs="text", title="Breast Cancer Prediction", description="Enter 30 numerical feature values separated by commas to predict whether the biopsy is Malignant or Benign." ) # Launch the Gradio app interface.launch()