Skip to content

Commit

Permalink
feat: Working on local execution of streamlit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr0p42 committed May 20, 2024
1 parent 26f5cd3 commit e324acf
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
7 changes: 7 additions & 0 deletions apps/streamlit-chat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.11

RUN apt update && apt install --yes netcat-openbsd

ADD requirements.txt /tmp

RUN pip install -r /tmp/requirements.txt
34 changes: 34 additions & 0 deletions apps/streamlit-chat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
up: build .env
docker-compose up
python -m webbrowser "http://127.0.0.1:8501/"

down:
docker-compose down

build:
docker-compose build

# Using ANSI Shadow
define setup_message
\033[0;32m

┌───────────────────────────────────────────────────────────────────┐
│ │
│ █████╗ ██████╗ ██╗ ███████╗███████╗████████╗██╗ ██╗██████╗ │
│ ██╔══██╗██╔══██╗██║ ██╔════╝██╔════╝╚══██╔══╝██║ ██║██╔══██╗ │
│ ███████║██████╔╝██║ ███████╗█████╗ ██║ ██║ ██║██████╔╝ │
│ ██╔══██║██╔══██╗██║ ╚════██║██╔══╝ ██║ ██║ ██║██╔═══╝ │
│ ██║ ██║██████╔╝██║ ███████║███████╗ ██║ ╚██████╔╝██║ │
│ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ │
│ │
└───────────────────────────────────────────────────────────────────┘

We need to setup your .env file. Please provide the required information.
\033[0m
endef
export setup_message

.env:
@echo "$$setup_message"
@read -p "OpenAI API Key: " openai_key \
&& echo "OPENAI_API_KEY=$$openai_key" > .env
90 changes: 90 additions & 0 deletions apps/streamlit-chat/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
services:
streamlit:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/app
labels:
- "traefik.enable=true"
- "traefik.http.routers.streamlit.rule=Host(`streamlit.abi.localhost`)"
- "traefik.http.routers.streamlit.entrypoints=web"
- "traefik.http.services.streamlit.loadbalancer.server.port=8501"
working_dir: /app
tty: true
ports:
- 8501:8501
environment:
- NEO4J_URI=bolt://neo4j:7687
- NEO4J_USERNAME=neo4j
- NEO4J_PASSWORD=neo4j
env_file:
- .env
command:
- '/bin/bash'
- '-c'
- |
while ! nc -z neo4j 7687; do echo -e "\n🟡 Waiting for Neo4j to be ready\n" && sleep 3; done
echo -e "\n🟢 Neo4j is ready!\n"
streamlit run --server.address 0.0.0.0 bot.py
neo4j:
image: neo4j:5.19
volumes:
- ./neo4j_data:/data
environment:
- NEO4J_AUTH=none
labels:
- "traefik.enable=true"
- "traefik.http.routers.neo4j.rule=Host(`neo4j.abi.localhost`)"
- "traefik.http.routers.neo4j.entrypoints=web"
- "traefik.http.services.neo4j.loadbalancer.server.port=7474"
ports:
- 7474:7474
- 7687:7687

streamlit-ready:
image: alpine
depends_on:
- streamlit
tty: true
command:
- '/bin/sh'
- '-c'
- |
while ! nc -z streamlit 8501; do sleep 3; done
cat << EOF
┌───────────────────────────────────────────────────────────────────────────────────┐
│ │
│ █████╗ ██████╗ ██╗ ███████╗████████╗ █████╗ ██████╗ ████████╗███████╗██████╗ │
│ ██╔══██╗██╔══██╗██║ ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██╔══██╗ │
│ ███████║██████╔╝██║ ███████╗ ██║ ███████║██████╔╝ ██║ █████╗ ██║ ██║ │
│ ██╔══██║██╔══██╗██║ ╚════██║ ██║ ██╔══██║██╔══██╗ ██║ ██╔══╝ ██║ ██║ │
│ ██║ ██║██████╔╝██║ ███████║ ██║ ██║ ██║██║ ██║ ██║ ███████╗██████╔╝ │
│ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ │
│ │
└───────────────────────────────────────────────────────────────────────────────────┘
🟢 You can access the services at:
- Streamlit app: http://streamlit.abi.localhost
- Neo4j Browser: http://neo4j.abi.localhost
- Traefik dashboard: http://localhost:8080
EOF
traefik:
image: "traefik:v3.0"
container_name: "traefik-abi"
command:
# - "--log.level=DEBUG"
- "--api.insecure=true"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entryPoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
2 changes: 1 addition & 1 deletion apps/streamlit-chat/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from os import environ

openai_api_key = environ.get("OPENAI_API_KEY")
model = environ.get("OPENAI_MODEL")
model = environ.get("OPENAI_MODEL", "gpt-3.5-turbo")

llm = ChatOpenAI(
openai_api_key=openai_api_key,
Expand Down
2 changes: 1 addition & 1 deletion apps/streamlit-chat/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ openai==1.26.0
langchain_openai==0.1.6
neo4j-driver==5.2.1
streamlit==1.34.0
naas-python==1.3.3
naas-python
2 changes: 1 addition & 1 deletion apps/streamlit-chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os import environ

avatar_assistant = "https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/content_creation.png"
avatar_human = environ.get("AVATAR")
avatar_human = environ.get("AVATAR", "ABI")

def write_message(role, content, save=True):
"""
Expand Down

0 comments on commit e324acf

Please sign in to comment.