Spaces:
Runtime error
Runtime error
Commit
·
fa1eec9
1
Parent(s):
11408d6
My backend 0
Browse files- Dockerfile +24 -0
- app.py +27 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
RUN apt-get update -y && apt-get install -y build-essential
|
| 4 |
+
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
USER user
|
| 9 |
+
ENV HOME=/home/user \
|
| 10 |
+
PATH=/home/user/.local/bin:$PATH
|
| 11 |
+
|
| 12 |
+
WORKDIR $HOME/app
|
| 13 |
+
|
| 14 |
+
COPY --chown=user . $HOME/app
|
| 15 |
+
|
| 16 |
+
COPY app.py app.py
|
| 17 |
+
|
| 18 |
+
RUN pip install Flask
|
| 19 |
+
RUN pip install gunicorn
|
| 20 |
+
RUN pip install -U flask-cors
|
| 21 |
+
RUN pip install opencv-python-headless==4.5.5.64
|
| 22 |
+
RUN pip install rembg
|
| 23 |
+
|
| 24 |
+
CMD ["gunicorn","-b","0.0.0.0:7860", "app:app","--timeout","950"]
|
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file
|
| 2 |
+
from werkzeug.utils import secure_filename
|
| 3 |
+
from flask_cors import CORS
|
| 4 |
+
from rembg import remove
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
app = Flask(__name__)
|
| 8 |
+
CORS(app)
|
| 9 |
+
|
| 10 |
+
@app.route('/')
|
| 11 |
+
def index():
|
| 12 |
+
return "Please use frontend"
|
| 13 |
+
|
| 14 |
+
@app.route('/data',methods = ['POST'])
|
| 15 |
+
def inference():
|
| 16 |
+
file = request.files['file']
|
| 17 |
+
file.save(secure_filename(file.filename))
|
| 18 |
+
file_name = file.filename
|
| 19 |
+
image = cv2.imread(secure_filename(file_name))
|
| 20 |
+
output = remove(image) # remove background
|
| 21 |
+
cv2.imwrite(secure_filename(file.filename).split('.')[0]+'.png',output)
|
| 22 |
+
print(secure_filename(file.filename).split('.'))
|
| 23 |
+
return send_file(secure_filename(file.filename).split('.')[0]+'.png',mimetype='image/png')
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
app.run(debug=True,host="0.0.0.0",port=5000)
|