Skip to content

Commit

Permalink
frontend backend containerization added
Browse files Browse the repository at this point in the history
  • Loading branch information
mionaD-upc committed Dec 5, 2023
1 parent 75852f4 commit 8ad4cb6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
24 changes: 24 additions & 0 deletions Dockerfile-backend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Backend only
FROM python:3.9-slim

WORKDIR /app-beans

# Copy the application files to the container
COPY ./requirements-Docker.txt /app-beans/requirements-Docker.txt
COPY ./models /app-beans/models
COPY ./src /app-beans/src

RUN rm -rf /app-beans/src/data
RUN rm -rf /app-beans/src/features
RUN rm -rf /app-beans/src/visualization
RUN rm -rf /app-beans/src/web
RUN rm -rf /app-beans/src/__pycache__
RUN rm -rf /app-beans/src/app/__pycache__

# Install dependencies
RUN pip install --no-cache-dir -r requirements-Docker.txt -v


EXPOSE 8000

ENTRYPOINT ["uvicorn", "src.app.api:app", "--host", "0.0.0.0", "--port", "8000", "--reload", "--reload-dir", "src/app", "--reload-dir", "models"]
21 changes: 21 additions & 0 deletions Dockerfile-frontend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Frontend only
FROM python:3.9-slim

WORKDIR /app-beans

# Copy the application files to the container
COPY ./requirements-Docker-frontend.txt /app-beans/requirements-Docker-frontend.txt
COPY ./src/web /app-beans/src/web


# Install dependencies
RUN pip install --no-cache-dir -r requirements-Docker-frontend.txt -v

RUN apt-get update && \
apt-get install -y curl

WORKDIR /app-beans/src/web

EXPOSE 8000

CMD ["python3", "starter.py"]
1 change: 1 addition & 0 deletions requirements-Docker-frontend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==3.0.0
7 changes: 4 additions & 3 deletions src/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def process_input(input_str):
}

return result

adress = sys.argv[1]

app = Flask(__name__)
Expand All @@ -51,11 +50,13 @@ def upload_file():
# Save the file to a temporary location
temp_dir = tempfile.mkdtemp()
file_path = os.path.join(temp_dir, file.filename)
print(file_path)
file.save(file_path)

#print("The received argument variable is: ", adress)
# MD change : (Pau instructions added)
command = 'curl -X POST -H "Content-Type: multipart/form-data" -H "Accept: application/json" -F "beans_img=@{}" http://{}:443/make_prediction'.format(file_path.replace("\\", "\\\\"), adress)
command = 'curl -X POST -H "Content-Type: multipart/form-data" -H "Accept: application/json" -F "beans_img=@{}" host.docker.internal:443/make_prediction'.format(file_path.replace("\\", "\\\\"))

app.logger.info(command)
# Get the classification result
response = subprocess.getoutput(command)
Expand All @@ -67,4 +68,4 @@ def upload_file():
return render_template('result.html', result=result)

if __name__ == '__main__':
app.run(debug=True)
app.run(host="0.0.0.0",port=8000, debug=True)
12 changes: 6 additions & 6 deletions src/web/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def run_app(public_ip):
subprocess.run(["python3", "app.py", public_ip])

def main():
docker_status = get_docker_status()
if docker_status == "external":
public_ip = get_public_ip()
save_public_ip(public_ip)
else:
public_ip = "localhost"
# docker_status = get_docker_status()
# if docker_status == "external":
# public_ip = get_public_ip()
# save_public_ip(public_ip)
# else:
public_ip = "localhost"
run_app(public_ip)

if __name__ == "__main__":
Expand Down

0 comments on commit 8ad4cb6

Please sign in to comment.