import tkinter as tk
from tkinter import filedialog
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import mean_squared_error, r2_score

class DataLoader:
    def __init__(self, root):
        self.root = root
        self.root.title("Load Data and Train Model")
        self.root.geometry("500x300")
        self.window = self.root

    def load_data(self, root):
        filetypes = [("CSV files", "*.csv"), ("All files", "*.*")]
        file_path = filedialog.askopenfilename(
            title="Select a file",
            filetypes=filetypes,
            defaultextension=".csv, .txt",
            confirmfiles=False
        )
        if not file_path:
            return None

        if file_path.endswith(".txt"):
            with open(file_path, "r") as file:
                data = pd.read_csv(pd.io.txt(file.read(), header=None, delimiter=" "))
        else:
            data = pd.read_csv(file_path)
        return data
