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