Spaces:
Paused
Paused
giorgio-caparvi
commited on
Commit
·
c69f75c
1
Parent(s):
ff79bde
fixed docker file
Browse files- Dockerfile +6 -7
- api/Dockerfile_backend +0 -14
- api/app.py +6 -5
- api/environment.yml +24 -3
Dockerfile
CHANGED
@@ -14,12 +14,11 @@ WORKDIR /api
|
|
14 |
# Copy the environment file and install dependencies
|
15 |
COPY --chown=user api/environment.yml ./
|
16 |
|
17 |
-
#
|
18 |
-
RUN conda
|
19 |
-
bash -c "source ~/.bashrc && conda env create -f environment.yml && conda clean -a -y"
|
20 |
|
21 |
-
#
|
22 |
-
RUN
|
23 |
|
24 |
# Copy the backend application code
|
25 |
COPY --chown=user api/ .
|
@@ -27,5 +26,5 @@ COPY --chown=user api/ .
|
|
27 |
# Expose port 7860 for the backend service
|
28 |
EXPOSE 7860
|
29 |
|
30 |
-
# Set default command to
|
31 |
-
CMD ["bash", "-c", "source
|
|
|
14 |
# Copy the environment file and install dependencies
|
15 |
COPY --chown=user api/environment.yml ./
|
16 |
|
17 |
+
# Install the conda environment
|
18 |
+
RUN conda env create -n mgd --file environment.yml && conda clean -a -y
|
|
|
19 |
|
20 |
+
# Install additional Python packages via pip after activating conda environment
|
21 |
+
RUN /bin/bash -c "source /opt/conda/etc/profile.d/conda.sh && conda activate mgd && pip install Flask Flask-Cors Flask-Limiter gunicorn"
|
22 |
|
23 |
# Copy the backend application code
|
24 |
COPY --chown=user api/ .
|
|
|
26 |
# Expose port 7860 for the backend service
|
27 |
EXPOSE 7860
|
28 |
|
29 |
+
# Set default command to initialize conda, activate the environment, and start the backend model
|
30 |
+
CMD ["bash", "-c", "source /opt/conda/etc/profile.d/conda.sh && conda activate mgd && python app.py --port 7860"]
|
api/Dockerfile_backend
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
# import conda
|
2 |
-
FROM continuumio/miniconda3:latest
|
3 |
-
|
4 |
-
RUN conda create -n mgd -y python=3.9
|
5 |
-
RUN conda activate mgd
|
6 |
-
RUN pip install torch==1.12.1 torchmetrics==0.11.0 opencv-python==4.7.0.68 diffusers==0.12.0 transformers==4.25.1 accelerate==0.15.0 clean-fid==0.1.35 torchmetrics[image]==0.11.0 flask
|
7 |
-
|
8 |
-
|
9 |
-
WORKDIR /app
|
10 |
-
#COPY requirements.txt requirements.txt
|
11 |
-
#RUN pip install -r requirements.txt
|
12 |
-
COPY . .
|
13 |
-
|
14 |
-
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/app.py
CHANGED
@@ -9,9 +9,10 @@ CORS(app)
|
|
9 |
# Ensure that Flask looks for the HTML templates in the correct folder
|
10 |
app.template_folder = './templates'
|
11 |
|
|
|
12 |
# Set the directory for the output images
|
13 |
output_dir = 'api/output'
|
14 |
-
image_filename = '
|
15 |
|
16 |
@app.route('/')
|
17 |
def index():
|
@@ -21,11 +22,11 @@ def index():
|
|
21 |
def generate_design():
|
22 |
# Command handling
|
23 |
command = [
|
24 |
-
'python', '
|
25 |
-
'--dataset_path', './assets/data/vitonhd',
|
26 |
'--batch_size', '1',
|
27 |
'--mixed_precision', 'fp16',
|
28 |
-
'--output_dir',
|
29 |
'--save_name', 'generato_paired',
|
30 |
'--num_workers_test', '4',
|
31 |
'--sketch_cond_rate', '0.2',
|
@@ -41,7 +42,7 @@ def generate_design():
|
|
41 |
# Check if the image was generated
|
42 |
if os.path.exists(image_path):
|
43 |
print("IMMAGINE CREATA")
|
44 |
-
return jsonify({"status": "success", "image_url": f"/output/{image_filename}"})
|
45 |
else:
|
46 |
print("IMMAGINE NON CREATA")
|
47 |
return jsonify({"status": "error", "message": "Image generation failed"}), 500
|
|
|
9 |
# Ensure that Flask looks for the HTML templates in the correct folder
|
10 |
app.template_folder = './templates'
|
11 |
|
12 |
+
print(f"Current working directory: {os.getcwd()}")
|
13 |
# Set the directory for the output images
|
14 |
output_dir = 'api/output'
|
15 |
+
image_filename = '03191_00.jpg'
|
16 |
|
17 |
@app.route('/')
|
18 |
def index():
|
|
|
22 |
def generate_design():
|
23 |
# Command handling
|
24 |
command = [
|
25 |
+
'python', './model/src/eval.py',
|
26 |
+
'--dataset_path', './model/assets/data/vitonhd/test',
|
27 |
'--batch_size', '1',
|
28 |
'--mixed_precision', 'fp16',
|
29 |
+
'--output_dir', './output',
|
30 |
'--save_name', 'generato_paired',
|
31 |
'--num_workers_test', '4',
|
32 |
'--sketch_cond_rate', '0.2',
|
|
|
42 |
# Check if the image was generated
|
43 |
if os.path.exists(image_path):
|
44 |
print("IMMAGINE CREATA")
|
45 |
+
return jsonify({"status": "success", "image_url": f"/output/generato_paired_paired/images/{image_filename}"})
|
46 |
else:
|
47 |
print("IMMAGINE NON CREATA")
|
48 |
return jsonify({"status": "error", "message": "Image generation failed"}), 500
|
api/environment.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
name: mgd
|
2 |
channels:
|
3 |
- defaults
|
|
|
4 |
dependencies:
|
5 |
- _libgcc_mutex=0.1=main
|
6 |
- _openmp_mutex=5.1=1_gnu
|
@@ -22,6 +23,7 @@ dependencies:
|
|
22 |
- wheel=0.38.4=py39h06a4308_0
|
23 |
- xz=5.4.2=h5eee18b_0
|
24 |
- zlib=1.2.13=h5eee18b_0
|
|
|
25 |
- pip:
|
26 |
- accelerate==0.15.0
|
27 |
- certifi==2023.7.22
|
@@ -29,8 +31,6 @@ dependencies:
|
|
29 |
- clean-fid==0.1.35
|
30 |
- diffusers==0.12.0
|
31 |
- filelock==3.12.4
|
32 |
-
- flask
|
33 |
-
- flask-cors
|
34 |
- fsspec==2023.9.1
|
35 |
- huggingface-hub==0.17.2
|
36 |
- idna==3.4
|
@@ -53,6 +53,27 @@ dependencies:
|
|
53 |
- torchvision==0.13.1
|
54 |
- tqdm==4.66.1
|
55 |
- transformers==4.25.1
|
56 |
-
- typing-extensions==4.
|
57 |
- urllib3==2.0.5
|
58 |
- zipp==3.17.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
name: mgd
|
2 |
channels:
|
3 |
- defaults
|
4 |
+
- conda-forge
|
5 |
dependencies:
|
6 |
- _libgcc_mutex=0.1=main
|
7 |
- _openmp_mutex=5.1=1_gnu
|
|
|
23 |
- wheel=0.38.4=py39h06a4308_0
|
24 |
- xz=5.4.2=h5eee18b_0
|
25 |
- zlib=1.2.13=h5eee18b_0
|
26 |
+
- libglib # Se disponibile su conda-forge
|
27 |
- pip:
|
28 |
- accelerate==0.15.0
|
29 |
- certifi==2023.7.22
|
|
|
31 |
- clean-fid==0.1.35
|
32 |
- diffusers==0.12.0
|
33 |
- filelock==3.12.4
|
|
|
|
|
34 |
- fsspec==2023.9.1
|
35 |
- huggingface-hub==0.17.2
|
36 |
- idna==3.4
|
|
|
53 |
- torchvision==0.13.1
|
54 |
- tqdm==4.66.1
|
55 |
- transformers==4.25.1
|
56 |
+
- typing-extensions==4.12.2
|
57 |
- urllib3==2.0.5
|
58 |
- zipp==3.17.0
|
59 |
+
- blinker==1.8.2
|
60 |
+
- click==8.1.7
|
61 |
+
- colorama==0.4.6
|
62 |
+
- Deprecated==1.2.14
|
63 |
+
- Flask==3.0.3
|
64 |
+
- Flask-Cors==4.0.1
|
65 |
+
- Flask-Limiter==3.8.0
|
66 |
+
- gunicorn==23.0.0
|
67 |
+
- importlib_resources==6.4.4
|
68 |
+
- itsdangerous==2.2.0
|
69 |
+
- Jinja2==3.1.4
|
70 |
+
- limits==3.13.0
|
71 |
+
- markdown-it-py==3.0.0
|
72 |
+
- MarkupSafe==2.1.5
|
73 |
+
- mdurl==0.1.2
|
74 |
+
- ordered-set==4.1.0
|
75 |
+
- Pygments==2.18.0
|
76 |
+
- rich==13.7.1
|
77 |
+
- typing_extensions==4.12.2
|
78 |
+
- Werkzeug==3.0.4
|
79 |
+
- wrapt==1.16.0
|