Upload files to 'Streamlit'
update streamlit
This commit is contained in:
parent
6e57cab13f
commit
24dc8fd808
51
Streamlit/Dockerfile
Normal file
51
Streamlit/Dockerfile
Normal file
@ -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"]
|
36
Streamlit/aplication.py
Normal file
36
Streamlit/aplication.py
Normal file
@ -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()
|
3
Streamlit/requirements.txt
Normal file
3
Streamlit/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
requests
|
||||||
|
streamlit
|
||||||
|
python-dotenv
|
Loading…
Reference in New Issue
Block a user