Spaces:
Sleeping
Sleeping
File size: 1,708 Bytes
6fe5de2 a00e4ad 768671f 6fe5de2 a00e4ad 84972e4 6fe5de2 84972e4 6fe5de2 |
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 59 60 61 62 63 64 65 66 |
from flask import Flask, request, jsonify
import pandas as pd
from io import StringIO
from preprocess_test import Preprocess_Test
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, input_shape, num_classes):
super(Model, self).__init__()
self.fc1 = nn.Linear(input_shape, 1024)
self.bn1 = nn.BatchNorm1d(1024)
self.fc2 = nn.Linear(1024, 512)
self.bn2 = nn.BatchNorm1d(512)
self.fc3 = nn.Linear(512, 256)
self.bn3 = nn.BatchNorm1d(256)
self.fc4 = nn.Linear(256, num_classes)
def forward(self, x):
x = F.relu(self.bn1(self.fc1(x)))
x = F.relu(self.bn2(self.fc2(x)))
x = F.relu(self.bn3(self.fc3(x)))
x = self.fc4(x)
return x
app=Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
@app.route("/",methods=["GET"])
def root():
return f"Test"
@app.route("/test", methods=["POST"])
def test():
# Check if file is in request
if 'file' not in request.files:
return jsonify({"error": "No file part"}), 400
file = request.files['file']
# Check if file is selected
if file.filename == '':
return jsonify({"error": "No selected file"}), 400
# Read CSV into DataFrame
csv_data = file.read().decode('utf-8')
df = pd.read_csv(StringIO(csv_data))
obj=Preprocess_Test(df)
obj.preprocess()
results = obj.test() # Capture the returned results
print("Results : ", results)
return jsonify({
"message": "CSV processed successfully",
"model_results": results
}), 200
if __name__ == "__main__":
app.run(debug=True,port=7860) |