Spaces:
Sleeping
Sleeping
| 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 | |
| def root(): | |
| return f"Test" | |
| 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) |