Spaces:
Sleeping
Sleeping
File size: 1,500 Bytes
b3e8a56 c0efbb4 b3e8a56 c0efbb4 b3e8a56 c0efbb4 b3e8a56 c0efbb4 b3e8a56 c0efbb4 b3e8a56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import streamlit as st
from mygrad import Layer, Value
import pickle
# Define the predict function
def predict(x):
x1 = hiddenLayer1(x)
final = outputLayer([x1] + x)
return final.data
# Load model
def loadModel():
neuron1weightsbias, outputneuronweightsbias = [], []
with open(f'parameters/neuron1weightsbias_fn_reLu.pckl', 'rb') as file:
neuron1weightsbias = pickle.load(file)
with open('parameters/outputneuronweightsbias2.pckl', 'rb') as file:
outputneuronweightsbias = pickle.load(file)
hiddenLayer1_ = Layer(10, 1, 'reLu')
outputLayer_ = Layer(11, 1, 'sigmoid')
hiddenLayer1_.neurons[0].w = [Value(i) for i in neuron1weightsbias[:-1]]
hiddenLayer1_.neurons[0].b = Value(neuron1weightsbias[-1])
outputLayer_.neurons[0].w = [Value(i) for i in outputneuronweightsbias[:-1]]
outputLayer_.neurons[0].b = Value(outputneuronweightsbias[-1])
return hiddenLayer1_, outputLayer_
hiddenLayer1, outputLayer = loadModel()
st.title("Neural Network Prediction")
st.header("Input")
inputs = st.text_input("Input 10 digits Binary no")
input = []
flag = 0
if len(inputs)!=10:
st.write("Error: Input not equal to 10 bits")
flag =1
for i in inputs:
if i!='0' and i!='1':
st.write("Please input Binary number only")
flag = 1
else:
input.append(int(i))
# Prediction
if st.button("Predict"):
if flag:
st.stop()
result = predict(input)
st.success(f"The prediction is: {result}")
|