Spaces:
Sleeping
Sleeping
Piyushmryaa
commited on
Commit
•
b3e8a56
1
Parent(s):
aa15917
revert app.py
Browse files
app.py
CHANGED
@@ -1,99 +1,51 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/1c8Qtf9TWr3apElEv2uDgCD_MQwHnmw0B
|
8 |
-
"""
|
9 |
-
|
10 |
import pickle
|
11 |
-
from mygrad import Neuron, Value
|
12 |
-
import streamlit as st
|
13 |
-
def convertToOneHotEncode(tags):
|
14 |
-
tag1 = tags[0]
|
15 |
-
tag2 = tags[1]
|
16 |
-
vec1 = [0]*5
|
17 |
-
vec2 = [0]*4
|
18 |
-
vec1[tag1] = 1
|
19 |
-
vec2[tag2-1] = 1
|
20 |
-
vec1.extend(vec2)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
return vec1
|
25 |
def loadModel():
|
26 |
-
neuron1weightsbias = []
|
27 |
-
with open(f'
|
28 |
neuron1weightsbias = pickle.load(file)
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
53 |
else:
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
for ix2, wordpair in enumerate(xnew):
|
63 |
-
xinput = [w] + wordpair
|
64 |
-
w = n(xinput)
|
65 |
-
if w.data > 0.5:
|
66 |
-
chunks.append(1)
|
67 |
-
else:
|
68 |
-
chunks.append(0)
|
69 |
-
return chunks
|
70 |
-
def input_(input):
|
71 |
-
if not input:
|
72 |
-
return
|
73 |
-
result = word_tokenize(input)
|
74 |
-
word_pos= nltk.pos_tag(result)
|
75 |
-
pos = [ i[1] for i in word_pos]
|
76 |
-
for i in range(len(pos)):
|
77 |
-
if pos[i] =='NN':
|
78 |
-
pos[i] = 1
|
79 |
-
elif pos[i] =='DT':
|
80 |
-
pos[i] = 2
|
81 |
-
elif pos[i] =='JJ':
|
82 |
-
pos[i] = 3
|
83 |
-
else:
|
84 |
-
pos[i]= 4
|
85 |
-
return pos
|
86 |
-
st.title('Chunk tagging')
|
87 |
-
input = st.text_input('Input the pos tags')
|
88 |
-
|
89 |
-
import nltk
|
90 |
-
from nltk.tokenize import word_tokenize
|
91 |
-
|
92 |
-
inputs = input_(input)
|
93 |
-
output = predictsentence(inputs)
|
94 |
-
st.write(output)
|
95 |
-
|
96 |
-
# import pandas as pd
|
97 |
-
# data = output
|
98 |
-
# df = pd.DataFrame.from_dict(data)
|
99 |
-
# st.dataframe(df)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from mygrad import Layer, Value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Define the predict function
|
6 |
+
def predict(x):
|
7 |
+
x1 = hiddenLayer1(x)
|
8 |
+
final = outputLayer([x1] + x)
|
9 |
+
return final.data
|
10 |
|
11 |
+
# Load model
|
|
|
12 |
def 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 |
+
|
28 |
+
hiddenLayer1, outputLayer = loadModel()
|
29 |
+
|
30 |
+
st.title("Neural Network Prediction")
|
31 |
+
|
32 |
+
st.header("Input")
|
33 |
+
inputs = st.text_input("Input 10 digits Binary no")
|
34 |
+
input = []
|
35 |
+
flag = 0
|
36 |
+
if len(inputs)!=10:
|
37 |
+
st.write("Error: Input not equal to 10 bits")
|
38 |
+
flag =1
|
39 |
+
for i in inputs:
|
40 |
+
if i!='0' and i!='1':
|
41 |
+
st.write("Please input Binary number only")
|
42 |
+
flag = 1
|
43 |
else:
|
44 |
+
input.append(int(i))
|
45 |
+
|
46 |
+
# Prediction
|
47 |
+
if st.button("Predict"):
|
48 |
+
if flag:
|
49 |
+
st.stop()
|
50 |
+
result = predict(input)
|
51 |
+
st.success(f"The prediction is: {result}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|