Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Integrate Frontend Service with Docker #1

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'

services:
backend:
build:
context: . # Directory containing the backend Dockerfile and source code
dockerfile: Dockerfile # Path to backend Dockerfile
args:
API_KEY: ${API_KEY}
ports:
- "8000:8000" # Expose the port the backend service runs on
env_file:
- .env

frontend:
build:
context: ./frontend # Directory the frontend Dockerfile and source code
dockerfile: Dockerfile # Path to your frontend Dockerfile
ports:
- "8501:8501" # Expose the port the frontend service runs on
27 changes: 27 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use the official Python image
FROM python:3.10

# Set the working directory in the container to /app
WORKDIR /frontend

# Copy the poetry files
COPY pyproject.toml poetry.lock /frontend/

# Install poetry
RUN pip install poetry

# Install the dependencies globally within the container.
RUN poetry config virtualenvs.create false

# Install project dependencies
RUN poetry lock
RUN poetry install

# Copy the frontend application file to the working directory
COPY frontend_app.py .

# Expose the port the app runs on
EXPOSE 8501

# Execute the script when the container starts
CMD ["streamlit", "run", "frontend_app.py"]
Empty file added frontend/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions app/frontend_app.py → frontend/frontend_app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import streamlit as st
import requests # Import requests library
import requests

# FastAPI server URL
SERVER_URL = "http://localhost:8000/recommendations/" # Replace with your FastAPI server URL
SERVER_URL = "http://backend:8000/recommendations/" # Replace with localhost if running locally

st.title('Movie Recommendation System')

Expand All @@ -11,8 +11,8 @@
num_rec = st.number_input('Number of Recommendations:', min_value=1, value=10) # Number of recommendations

# Get Recommendations Button
if st.button('Get Recommendations'): # If the button is pressed
if query: # If a query is entered
if st.button('Get Recommendations'):
if query:
st.subheader('Recommendations for "{}":'.format(query))

# Prepare payload
Expand Down
1,186 changes: 1,186 additions & 0 deletions frontend/poetry.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions frontend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "movie-rec-system-frontend"
version = "0.1.0"
description = "Frontend for Movie Recommendation System"
authors = ["Magnus <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
streamlit = "^1.25.0"
requests = "^2.31"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
476 changes: 57 additions & 419 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "movie-rec-system"
version = "0.1.0"
description = ""
description = "Backend for Movie Recommendation System"
authors = ["Magnus <[email protected]>"]
readme = "README.md"

Expand All @@ -21,7 +21,6 @@ pytest = "7.4.0"
uvicorn = "0.23.2"
httpx = "^0.24.1"
seaborn = "^0.12.2"
streamlit = "^1.25.0"

[tool.jupysql.SqlMagic]
autopandas = true
Expand Down