Spaces:
Runtime error
Runtime error
Lambang
commited on
Commit
·
4a677e7
1
Parent(s):
f50765e
sementara gini dulu
Browse files
main.py
CHANGED
@@ -179,111 +179,111 @@ def get_images():
|
|
179 |
# -------------------------------------------------------------------------
|
180 |
|
181 |
# Model pydantic untuk validasi body
|
182 |
-
class TrainingParams(BaseModel):
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
@app.post('/upload/dataset', tags=["Training"])
|
188 |
-
async def upload_data(dataset: UploadFile):
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
@app.post('/set_params', tags=["Training"])
|
205 |
-
async def set_params(request: Request, params: TrainingParams):
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
@app.get('/get_info_data', tags=["Training"])
|
216 |
-
def get_info_prepro():
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
@app.get('/get_images_preprocess', tags=["Training"])
|
230 |
-
def get_random_images_crop():
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
@app.get('/do_preprocessing', tags=["Training"])
|
241 |
-
async def do_preprocessing():
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
@app.get('/do_training', tags=["Training"])
|
252 |
-
def do_training():
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
|
288 |
|
289 |
# -------------------------------------------------------------------------
|
@@ -291,37 +291,37 @@ def do_training():
|
|
291 |
# -------------------------------------------------------------------------
|
292 |
|
293 |
|
294 |
-
@app.post('/upload/model', tags=["Model"])
|
295 |
-
def upload_model():
|
296 |
-
|
297 |
-
|
298 |
|
299 |
-
|
300 |
|
301 |
-
|
302 |
-
|
303 |
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
|
309 |
-
|
310 |
|
311 |
-
|
312 |
|
313 |
-
@app.post('/selected_models')
|
314 |
-
def select_models(index: int):
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
|
321 |
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
|
326 |
if __name__ == '__main__':
|
327 |
import uvicorn
|
|
|
179 |
# -------------------------------------------------------------------------
|
180 |
|
181 |
# Model pydantic untuk validasi body
|
182 |
+
# class TrainingParams(BaseModel):
|
183 |
+
# optimizer: str
|
184 |
+
# epoch: int
|
185 |
+
# batchSize: int
|
186 |
+
|
187 |
+
# @app.post('/upload/dataset', tags=["Training"])
|
188 |
+
# async def upload_data(dataset: UploadFile):
|
189 |
+
# if dataset.filename == '':
|
190 |
+
# raise HTTPException(status_code=400, detail='No file selected for uploading')
|
191 |
+
|
192 |
+
# # Buat path lengkap untuk menyimpan file
|
193 |
+
# file_path = os.path.join(UPLOAD_FOLDER, dataset.filename)
|
194 |
+
|
195 |
+
# # Simpan file ke folder yang ditentukan
|
196 |
+
# with open(file_path, "wb") as file_object:
|
197 |
+
# file_object.write(dataset.file.read())
|
198 |
+
|
199 |
+
# # Panggil fungsi untuk mengekstrak file jika perlu
|
200 |
+
# FileProcess.extract_zip(file_path)
|
201 |
+
|
202 |
+
# return {'message': 'File successfully uploaded'}
|
203 |
+
|
204 |
+
# @app.post('/set_params', tags=["Training"])
|
205 |
+
# async def set_params(request: Request, params: TrainingParams):
|
206 |
+
# global optimizer, epoch, batch_size
|
207 |
+
|
208 |
+
# optimizer = params.optimizer
|
209 |
+
# epoch = params.epoch
|
210 |
+
# batch_size = params.batchSize
|
211 |
+
|
212 |
+
# response = {'message': 'Set parameter sukses'}
|
213 |
+
# return response
|
214 |
+
|
215 |
+
# @app.get('/get_info_data', tags=["Training"])
|
216 |
+
# def get_info_prepro():
|
217 |
+
# global optimizer, epoch, batch_size
|
218 |
+
# training_counts = GetLoadData.get_training_file_counts().json
|
219 |
+
# testing_counts = GetLoadData.get_testing_file_counts().json
|
220 |
+
# response = {
|
221 |
+
# "optimizer": optimizer,
|
222 |
+
# "epoch": epoch,
|
223 |
+
# "batch_size": batch_size,
|
224 |
+
# "training_counts": training_counts,
|
225 |
+
# "testing_counts": testing_counts
|
226 |
+
# }
|
227 |
+
# return response
|
228 |
+
|
229 |
+
# @app.get('/get_images_preprocess', tags=["Training"])
|
230 |
+
# def get_random_images_crop():
|
231 |
+
# images_face_landmark = GetLoadData.get_random_images(tahap="Face Landmark",public_url=public_url)
|
232 |
+
# images_face_extraction = GetLoadData.get_random_images(tahap="landmark Extraction", public_url=public_url)
|
233 |
+
|
234 |
+
# response = {
|
235 |
+
# "face_landmark": images_face_landmark,
|
236 |
+
# "landmark_extraction": images_face_extraction
|
237 |
+
# }
|
238 |
+
# return response
|
239 |
+
|
240 |
+
# @app.get('/do_preprocessing', tags=["Training"])
|
241 |
+
# async def do_preprocessing():
|
242 |
+
# try:
|
243 |
+
# data_train_pred.do_pre1(test="")
|
244 |
+
# data_train_pred.do_pre2(test="")
|
245 |
+
# return {'message': 'Preprocessing sukses'}
|
246 |
+
# except Exception as e:
|
247 |
+
# # Tangani kesalahan dan kembalikan respons kesalahan
|
248 |
+
# error_message = f'Error during preprocessing: {str(e)}'
|
249 |
+
# raise HTTPException(status_code=500, detail=error_message)
|
250 |
+
|
251 |
+
# @app.get('/do_training', tags=["Training"])
|
252 |
+
# def do_training():
|
253 |
+
# global epoch
|
254 |
+
# folder = ""
|
255 |
+
# if (face_landmark_img == True and landmark_extraction_img == True):
|
256 |
+
# folder = "Landmark Extraction"
|
257 |
+
# elif (face_landmark_img == True and landmark_extraction_img == False):
|
258 |
+
# folder = "Face Landmark"
|
259 |
+
# # --------------------------------------------------------------
|
260 |
+
# train_dataset_path = f"./static/dataset/{folder}/Training/"
|
261 |
+
# test_dataset_path = f"./static/dataset/{folder}/Testing/"
|
262 |
+
|
263 |
+
# train_image_df, test_image_df = GetLoadData.load_image_dataset(train_dataset_path, test_dataset_path)
|
264 |
+
|
265 |
+
# train_gen, test_gen = data_train_pred.data_configuration(train_image_df, test_image_df)
|
266 |
+
# model = data_train_pred.model_architecture()
|
267 |
+
|
268 |
+
# result = data_train_pred.train_model(model, train_gen, test_gen, epoch)
|
269 |
+
|
270 |
+
# # Mengambil nilai akurasi training dan validation dari objek result
|
271 |
+
# train_acc = result.history['accuracy'][-1]
|
272 |
+
# val_acc = result.history['val_accuracy'][-1]
|
273 |
+
|
274 |
+
# # Plot accuracy
|
275 |
+
# data_train_pred.plot_accuracy(result=result, epoch=epoch)
|
276 |
+
# acc_url = f'{public_url}/static/accuracy_plot.png'
|
277 |
+
|
278 |
+
# # Plot loss
|
279 |
+
# data_train_pred.plot_loss(result=result, epoch=epoch)
|
280 |
+
# loss_url = f'{public_url}/static/loss_plot.png'
|
281 |
+
|
282 |
+
# # Confusion Matrix
|
283 |
+
# data_train_pred.plot_confusion_matrix(model, test_gen)
|
284 |
+
# conf_url = f'{public_url}/static/confusion_matrix.png'
|
285 |
+
|
286 |
+
# return jsonify({'train_acc': train_acc, 'val_acc': val_acc, 'plot_acc': acc_url, 'plot_loss':loss_url,'conf':conf_url})
|
287 |
|
288 |
|
289 |
# -------------------------------------------------------------------------
|
|
|
291 |
# -------------------------------------------------------------------------
|
292 |
|
293 |
|
294 |
+
# @app.post('/upload/model', tags=["Model"])
|
295 |
+
# def upload_model():
|
296 |
+
# if 'file' not in request.files:
|
297 |
+
# return {'message': 'No file part in the request'}, 400
|
298 |
|
299 |
+
# file = request.files['file']
|
300 |
|
301 |
+
# if file.filename == '':
|
302 |
+
# return {'message': 'No file selected for uploading'}, 400
|
303 |
|
304 |
+
# if file and FileProcess.allowed_file(file.filename):
|
305 |
+
# filename = secure_filename(file.filename)
|
306 |
+
# filepath = os.path.join(app.config['UPLOAD_MODEL'], filename)
|
307 |
+
# file.save(filepath)
|
308 |
|
309 |
+
# return {'message': 'File successfully uploaded'}
|
310 |
|
311 |
+
# return {'message': 'File failed to uploaded'}
|
312 |
|
313 |
+
# @app.post('/selected_models')
|
314 |
+
# def select_models(index: int):
|
315 |
+
# global selected_model
|
316 |
+
# try:
|
317 |
+
# global selected_model
|
318 |
+
# selected_model = tf.keras.models.load_model(f'models/fc_model_{index}.h5')
|
319 |
|
320 |
+
# # Lakukan sesuatu dengan indeks yang diterima
|
321 |
|
322 |
+
# return {'message': 'Request berhasil diterima'}
|
323 |
+
# except Exception as e:
|
324 |
+
# raise HTTPException(status_code=500, detail=f'Error: {str(e)}')
|
325 |
|
326 |
if __name__ == '__main__':
|
327 |
import uvicorn
|