Spaces:
Sleeping
Sleeping
File size: 1,591 Bytes
9cecb44 5bda5fb 9cecb44 5bda5fb 9cecb44 |
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 53 54 55 56 57 58 |
import streamlit as st
import json
from nn import train, predict, save_model, sigmoid
# INPUTS = [[0,0],[0,1],[1,0],[1,1]]
# OUTPUTS = [[0],[1],[1],[0]]
# EPOCHS = 1000000
# ALPHAS = 20
INPUTS = [[0,0],[0,1],[1,0],[1,1]]
OUTPUTS = [[0],[1],[1],[0]]
def runNN(epoch, alpha):
# Train model
modelo = train(epochs=epoch, alpha=alpha)
print(modelo)
# Save model to file
# save_model(modelo, "modelo.json")
st.download_button(
label="Download model",
data=json.dumps(modelo),
file_name="modelo.json",
mime="application/json",
)
for i in range(4):
result = predict(INPUTS[i][0],INPUTS[i][1], activation=sigmoid)
st.write("for input", INPUTS[i], "expected", OUTPUTS[i][0], "predicted", f"{result:4.4}", "which is", "correct" if round(result)==OUTPUTS[i][0] else "incorrect")
def sidebar():
# Neural network controls
st.sidebar.header('Neural Network Controls')
st.sidebar.text('Number of epochs')
epochs = st.sidebar.slider('Epochs', 1000, 1000000, 100000)
st.sidebar.text('Learning rate')
alphas = st.sidebar.slider('Alphas', 1, 100, 20)
if st.sidebar.button('Run Neural Network'):
runNN(epochs, alphas)
def app():
st.title('Simple Neural Network App')
st.write('This is the Neural Network image we are trying to implement!')
st.image('nn.png', width=500)
sidebar()
st.markdown('''
### References
* https://www.codingame.com/playgrounds/59631/neural-network-xor-example-from-scratch-no-libs
''')
if __name__ == '__main__':
app()
|