File size: 5,435 Bytes
d909077
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import {
  Box,
  LinearProgress,
  Modal,
  Typography
} from "@mui/material";
import { useCallback, useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import MainContainer from "../../components/Container/MainContainer";
import AudioUploader from "../../requests/upload";

const Inference = () => {
  
  
  useEffect(() => {
    // Retrieve values from localStorage
    const storedFilePath = localStorage.getItem('file_path');
    const storedCsvFilePath = localStorage.getItem('csv_file_path');
    const storedOutputFilePath = localStorage.getItem('output_file_path');

    // Check if values are stored and delete them
    if (storedFilePath || storedCsvFilePath || storedOutputFilePath) {
      localStorage.removeItem('file_path');
      localStorage.removeItem('csv_file_path');
      localStorage.removeItem('output_file_path');
    }
  }, []);

  
  const location = useLocation();
  const [selectedIndex, setSelectedIndex] = useState(
    location.pathname.replace("/", "")
  );

  const [isVisible, setIsVisible] = useState(false);
  const [files, setFile] = useState<File | null>(null);
  const [filename, setFileName] = useState<string>("null");
  const [NextCard, setNextCard] = useState(false);

  const handleListItemClick = (index: string) => {
    setSelectedIndex(index);
  };
  
  useEffect(() => {
    setSelectedIndex(location.pathname.replace("/", ""));
  }, [location.pathname]);


  const uploadNow = () => {
    //start upload function and pass the file selected as argument
  };


  const onDragEnter = useCallback(
    (e: { stopPropagation: () => void; preventDefault: () => void }) => {
      setIsVisible(true);
      e.stopPropagation();
      e.preventDefault();
      return false;
    },
    []
  );
  const onDragOver = useCallback(
    (e: { preventDefault: () => void; stopPropagation: () => void }) => {
      e.preventDefault();
      e.stopPropagation();
      return false;
    },
    []
  );
  const onDragLeave = useCallback(
    (e: { stopPropagation: () => void; preventDefault: () => void }) => {
      setIsVisible(false);
      e.stopPropagation();
      e.preventDefault();
      return false;
    },
    []
  );
  const onDrop = useCallback(
    (e: { preventDefault: () => void; dataTransfer: any }) => {
      e.preventDefault();
      const files = e.dataTransfer.files;
      setFile(e.dataTransfer.files[0]);
      setFileName(e.dataTransfer.files[0].name);
      console.log("Files dropped: ", filename);
      // Upload files
      //check file type
      setNextCard(true);
      setIsVisible(false);
      return false;
    },
    []
  );

  useEffect(() => {
    window.addEventListener("mouseup", onDragLeave);
    window.addEventListener("dragenter", onDragEnter);
    window.addEventListener("dragover", onDragOver);
    window.addEventListener("drop", onDrop);
    return () => {
      window.removeEventListener("mouseup", onDragLeave);
      window.removeEventListener("dragenter", onDragEnter);
      window.removeEventListener("dragover", onDragOver);
      window.removeEventListener("drop", onDrop);
    };
  }, [onDragEnter, onDragLeave, onDragOver, onDrop]);


  //Modal OpenClose
  const [openModal, setOpenModal] = useState(false);
  const handleOpen = () => setOpenModal(true);
  const handleClose = () => setOpenModal(false);

  return (
    <>
      <MainContainer>
        <Box
          onDragEnter={onDragEnter}
          onDragOver={onDragEnter}
          onDragLeave={onDragLeave}
          sx={{
            justifyContent: "center",
            display: "flex",
            height: "99%",
            alignItems: "center",
          }}
        >
          <AudioUploader handleClose={handleClose} handleOpen={handleOpen}/>
          </Box>
        <GenerationModal GenerationStatus="It's working for sure" handleClose={handleClose} handleOpen={openModal}/>
      </MainContainer>
    </>
  );
};

export default Inference;

interface GenerationModalProps {
  GenerationStatus: string; // Replace "string" with the actual type of GenerationStatus
  handleOpen : boolean;
  handleClose: React.Dispatch<React.SetStateAction<boolean>>;
}

export function GenerationModal({
  GenerationStatus,
  handleOpen,
  handleClose
}: GenerationModalProps): any {


  const [statusText, setStatusText] = useState(GenerationStatus);

  useEffect(() => {
    // Update the displayText whenever the prop 'text' changes
    setStatusText(GenerationStatus);
  }, [GenerationStatus]);

  return (
    <div
      style={{
        display: "flex",
        justifyContent: "center",
        marginBottom: "10px",
      }}
    >
      <Modal
        open={handleOpen}
        onClose={handleClose}
        aria-labelledby="modal-modal-title"
        aria-describedby="modal-modal-description"
      >
        <Box sx={style_modal}>
          <Typography variant="h4">Model Running</Typography>
          <div style={{ paddingTop: "10px" }}>
            <Typography fontSize={"20px"}>{GenerationStatus}</Typography>
            <Box sx={{ pt: 2 }}>
              <LinearProgress color={"primary"} sx={{ borderRadius: "50px" }} />
            </Box>
          </div>
        </Box>
      </Modal>
    </div>
  );
}

const style_modal = {
  position: "absolute" as "absolute",
  top: "50%",
  left: "50%",
  transform: "translate(-50%, -50%)",
  width: 500,
  color: "inherit",
  bgcolor: "background.paper",
  p: 4,
  borderRadius: "10px"
};