Skip to content

Commit

Permalink
Merge pull request #29 from MLOps-essi-upc/web-modified
Browse files Browse the repository at this point in the history
Web modified
  • Loading branch information
wwoszczek authored Dec 6, 2023
2 parents a2fdd6c + 67ac1a8 commit 38cbb4d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Dockerfile.txt → Dockerfile-backend.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# 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 ./requirements-Docker-backend.txt /app-beans/requirements-Docker-backend.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
RUN pip install --no-cache-dir -r requirements-Docker-backend.txt -v


EXPOSE 8000
Expand Down
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"]
File renamed without changes.
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ python-multipart==0.0.6
fastapi==0.68.0
uvicorn[standard]==0.24.0.post1
httpx==0.21.0
datasets==2.15.0
datasets==2.15.0
Flask==3.0.0
9 changes: 6 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,10 +50,14 @@ 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)
command = f"curl -X POST -H 'Content-Type: multipart/form-data' -H 'Accept: application/json' -F 'beans_img=@{file_path}' http://{adress}:4000/make_prediction"
# MD change : (Pau instructions added)
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 @@ -65,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)
15 changes: 8 additions & 7 deletions src/web/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ def save_public_ip(public_ip):

def run_app(public_ip):
# Run app.py passing the public IP as an argument
subprocess.run(["python", "app.py", public_ip])
# MD change: to python3
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 38cbb4d

Please sign in to comment.