Lambang commited on
Commit
7f25d73
·
1 Parent(s): 07d4dbb

dockerupdatecjek

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -2
  2. main.py +16 -16
Dockerfile CHANGED
@@ -1,6 +1,8 @@
1
-
2
  FROM python:3.9
3
 
 
 
 
4
  WORKDIR /code
5
 
6
  COPY ./requirements.txt /code/requirements.txt
@@ -9,4 +11,4 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
9
 
10
  COPY . .
11
 
12
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
  FROM python:3.9
2
 
3
+ # Menjalankan perintah untuk menginstal paket-paket yang dibutuhkan
4
+ RUN apt-get update && apt-get install -y ffmpeg libsm6 libxext6
5
+
6
  WORKDIR /code
7
 
8
  COPY ./requirements.txt /code/requirements.txt
 
11
 
12
  COPY . .
13
 
14
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py CHANGED
@@ -3,7 +3,7 @@ import pickle
3
  import uvicorn
4
  import pandas as pd
5
  import shutil
6
- # import cv2
7
  import tensorflow as tf
8
  import os
9
  from flask import Flask, jsonify, request, flash, redirect, url_for
@@ -89,25 +89,25 @@ def preprocessing(filepath):
89
  # ## API UNTUK MELAKUKAN PROSES PREDIKSI
90
  # ## -------------------------------------------------------------------------
91
 
92
- # @app.post('/upload/file',tags=["Predicting"])
93
- # async def upload_file(picture: UploadFile):
94
- # file_extension = picture.filename.split('.')[-1].lower()
95
 
96
 
97
- # if file_extension not in ALLOWED_EXTENSIONS:
98
- # raise HTTPException(status_code=400, detail='Invalid file extension')
99
 
100
- # os.makedirs(UPLOAD_FOLDER, exist_ok=True)
101
- # file_path = os.path.join(UPLOAD_FOLDER, secure_filename(picture.filename))
102
- # with open(file_path, 'wb') as f:
103
- # f.write(picture.file.read())
104
- # try:
105
- # processed_img = preprocessing(cv2.imread(file_path))
106
- # except Exception as e:
107
- # os.remove(file_path)
108
- # raise HTTPException(status_code=500, detail=f'Error processing image: {str(e)}')
109
 
110
- # return JSONResponse(content={'message': 'File successfully uploaded'}, status_code=200)
111
 
112
  # @app.get('/get_images', tags=["Predicting"])
113
  # def get_images():
 
3
  import uvicorn
4
  import pandas as pd
5
  import shutil
6
+ import cv2
7
  import tensorflow as tf
8
  import os
9
  from flask import Flask, jsonify, request, flash, redirect, url_for
 
89
  # ## API UNTUK MELAKUKAN PROSES PREDIKSI
90
  # ## -------------------------------------------------------------------------
91
 
92
+ @app.post('/upload/file',tags=["Predicting"])
93
+ async def upload_file(picture: UploadFile):
94
+ file_extension = picture.filename.split('.')[-1].lower()
95
 
96
 
97
+ if file_extension not in ALLOWED_EXTENSIONS:
98
+ raise HTTPException(status_code=400, detail='Invalid file extension')
99
 
100
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
101
+ file_path = os.path.join(UPLOAD_FOLDER, secure_filename(picture.filename))
102
+ with open(file_path, 'wb') as f:
103
+ f.write(picture.file.read())
104
+ try:
105
+ processed_img = preprocessing(cv2.imread(file_path))
106
+ except Exception as e:
107
+ os.remove(file_path)
108
+ raise HTTPException(status_code=500, detail=f'Error processing image: {str(e)}')
109
 
110
+ return JSONResponse(content={'message': 'File successfully uploaded'}, status_code=200)
111
 
112
  # @app.get('/get_images', tags=["Predicting"])
113
  # def get_images():