diff --git a/Streamlit/Dockerfile b/Streamlit/Dockerfile new file mode 100644 index 0000000..2ded0f3 --- /dev/null +++ b/Streamlit/Dockerfile @@ -0,0 +1,51 @@ +FROM python:3.10-slim-bullseye AS base + +WORKDIR /app + +# Set utf-8 encoding for Python et al +ENV LANG=C.UTF-8 \ + # Turn off writing .pyc files + PYTHONDONTWRITEBYTECODE=1 \ + # Reduce the OS system calls for this tool it makes a difference + PYTHONUNBUFFERED=1 \ + # Disables cache dir in pip + PIP_NO_CACHE_DIR=1 \ + # Virtual environment + VENV="/opt/venv" \ + # Add new user + APPUSER=appuser \ + # Ensure that the python and pip executables used in the image + PATH="${VENV}/bin:$PATH" + + +FROM base as builder + +COPY requirements.txt . + +RUN apt-get update \ + && python -m venv ${VENV} \ + && . ${VENV}/bin/activate \ + && pip install --upgrade pip \ + && pip install -r requirements.txt + + +FROM base as runner + +COPY aplication.py . + + +COPY --from=builder ${VENV} ${VENV} +ENV PATH="${VENV}/bin:$PATH" + +# Update permissions & change user to not run as root +RUN chgrp -R 0 /app \ + && chmod -R g=u /app \ + && groupadd -r ${APPUSER} \ + && useradd -r -g ${APPUSER} ${APPUSER} \ + && chown -R ${APPUSER}:${APPUSER} /app \ + && usermod -d /app ${APPUSER} + + + +#$HEALTHCHECK CMD curl --fail http://localhost/_stcore/health +CMD ["streamlit", "run", "aplication.py", "--server.address=0.0.0.0"] \ No newline at end of file diff --git a/Streamlit/aplication.py b/Streamlit/aplication.py new file mode 100644 index 0000000..8232f40 --- /dev/null +++ b/Streamlit/aplication.py @@ -0,0 +1,36 @@ +import requests +import json +import streamlit as st +import os +from dotenv import load_dotenv +load_dotenv() +def predict(context,question): + url = os.getenv("URL") + #url = 'http://localhost:8090/predict' + data = {'context': context,'question': question} + json_data = json.dumps(data) + headers = {'Content-type': 'application/json'} + response = requests.post(url, data=json_data, headers=headers) + result = response.json() + return result + +def main(): + st.title("T5 model inference") + + # Vytvoríme polia pre zadanie hodnôt + context = st.text_input("context:") + question = st.text_input("question:") + prediction = predict(context,question) + # Vytvoríme tlačidlo pre vykonanie akcie + if st.button("Execute"): + + st.json({ + 'context': context, + 'question': question, + 'prediciton':prediction + }) + + + +if __name__ == "__main__": + main() diff --git a/Streamlit/requirements.txt b/Streamlit/requirements.txt new file mode 100644 index 0000000..c75c5f2 --- /dev/null +++ b/Streamlit/requirements.txt @@ -0,0 +1,3 @@ +requests +streamlit +python-dotenv \ No newline at end of file