Spaces:
Sleeping
Sleeping
File size: 991 Bytes
14841f9 29cce3f 14841f9 29cce3f 14841f9 29cce3f 14841f9 29cce3f |
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 |
from flask import Flask, request, jsonify, Response
from nn.nn import NN
from nn import train as train_nn
from nn import activation
import pandas as pd
import io
app = Flask(__name__)
@app.route("/neural-network", methods=["POST"])
def neural_net():
args = request.json
try:
net = NN.from_dict(args)
except Exception as e:
return Response(
response=f"issue with request args: {e}",
status=400,
)
try:
df = pd.read_csv(io.StringIO(net.data))
net.set_df(df=df)
except Exception as e:
return Response(
response=f"error reading csv data: {e}",
status=400,
)
try:
activation.get_activation(nn=net)
except Exception as e:
return Response(
response="invalid activation function",
status=400,
)
result = train_nn.train(nn=net)
return jsonify(result)
if __name__ == "__main__":
app.run(debug=True)
|