CoolFace
Apppublic

Piyushmryaa/CS772_ASSIGNMENT1

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py52 linesDownload Raw Back to root
1import streamlit as st2from mygrad import Layer, Value3import pickle4 5# Define the predict function6def predict(x):7    x1 = hiddenLayer1(x)    8    final = outputLayer([x1] + x)9    return final.data10 11# Load model12def loadModel():13    neuron1weightsbias, outputneuronweightsbias = [], []14    with open(f'parameters/neuron1weightsbias_fn_reLu.pckl', 'rb') as file:15        neuron1weightsbias = pickle.load(file)16    with open('parameters/outputneuronweightsbias2.pckl', 'rb') as file:17        outputneuronweightsbias = pickle.load(file)18    hiddenLayer1_ = Layer(10, 1, 'reLu')19    outputLayer_ = Layer(11, 1, 'sigmoid')20 21    hiddenLayer1_.neurons[0].w = [Value(i) for i in neuron1weightsbias[:-1]]22    hiddenLayer1_.neurons[0].b = Value(neuron1weightsbias[-1])23 24    outputLayer_.neurons[0].w = [Value(i) for i in outputneuronweightsbias[:-1]]25    outputLayer_.neurons[0].b = Value(outputneuronweightsbias[-1])26    return hiddenLayer1_, outputLayer_27 28hiddenLayer1, outputLayer = loadModel()29 30st.title("Neural Network Prediction")31 32st.header("Input")33inputs = st.text_input("Input 10 digits Binary no")34input = []35flag = 036if len(inputs)!=10:37    st.write("Error: Input not equal to 10 bits")38    flag =139for i in inputs:40    if i!='0' and i!='1':41        st.write("Please input Binary number only")42        flag = 143    else:44        input.append(int(i))45 46# Prediction47if st.button("Predict"):48    if flag:49        st.stop()50    result = predict(input)51    st.success(f"The prediction is: {result}")52