From 426b6431112d55f8e321e8e638bbdeac6eb6d367 Mon Sep 17 00:00:00 2001 From: jorsincl Date: Thu, 20 Nov 2025 14:00:44 -0700 Subject: [PATCH] Created Streamlit app UI --- .gitignore | 4 +++- frontend/Dockerfile | 20 ++++++++++++++++ frontend/readcrumbs_app.py | 49 ++++++++++++++++++++++++++++++++++++++ frontend/requirements.txt | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 frontend/Dockerfile create mode 100644 frontend/readcrumbs_app.py create mode 100644 frontend/requirements.txt diff --git a/.gitignore b/.gitignore index 734a980..478b169 100644 --- a/.gitignore +++ b/.gitignore @@ -208,4 +208,6 @@ __marimo__/ # Data raw/ -processed/ \ No newline at end of file +processed/ + +.DS_store \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..69416e0 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.12-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements file into the container at /app +COPY frontend/requirements.txt /app/ + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the application code into the container at /app +COPY frontend/readcrumbs_app.py /app/ + + +# Make port 8501 available to the world outside this container +EXPOSE 8501 + +# Run app.py when the container launches +CMD ["streamlit", "run", "app.py"] \ No newline at end of file diff --git a/frontend/readcrumbs_app.py b/frontend/readcrumbs_app.py new file mode 100644 index 0000000..1a407b6 --- /dev/null +++ b/frontend/readcrumbs_app.py @@ -0,0 +1,49 @@ +import streamlit as st +import requests + +# API URL (probably need to change) +API_URL = "http://54.91.115.10:8000" + +# Setup the streamlit page +title = "Readcrumbs" +description = "Provides book recommendations based on your favorite titles." +st.set_page_config(page_title=title, page_icon="📚") +st.title(title) +st.write(description) + +input_text = st.text_area("What are some of your favorite books?", height=150) + +# Button and Prediction Logic: +# Use the return value of st.button() to control when the prediction is made. +if st.button("Analyze Sentiment"): + # If no review is entered, show a warning. + if input_text.strip() == "": + st.warning("Please enter a movie review to analyze.") + else: + # Connect with the API to make a prediction. Should pass a list of titles. + input_list = input_text.split(", ") + + # Create json data from input_list. + data_to_send = { + "items": input_list + } + + response = requests.post(f"{API_URL}/predict", json=data_to_send) + + if response.status_code == 200: + prediction = response.json() + prediction = prediction["recs"] + + # Display result + st.subheader("Your Recommendations") + for r in prediction: + # display title + st.text(r) + +# Footer with name and link to GitHub repository +st.divider() +col1, col2 = st.columns(2) +with col1: + st.markdown("Developed by Jordan Sinclair and Jordan Larson") +with col2: + st.link_button("GitHub Repository", "https://github.com/smiley-maker/readcrumbs") \ No newline at end of file diff --git a/frontend/requirements.txt b/frontend/requirements.txt new file mode 100644 index 0000000..e251330 --- /dev/null +++ b/frontend/requirements.txt @@ -0,0 +1 @@ +streamlit \ No newline at end of file