Skip to content

Commit

Permalink
Updates admin for streamlit updates
Browse files Browse the repository at this point in the history
  • Loading branch information
howethomas committed Jan 25, 2024
1 parent edb9e8c commit c756106
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
22 changes: 22 additions & 0 deletions admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Make port 8501 available to the world outside this container
EXPOSE 8501

# Define environment variable
ENV NAME World

# Run admin.py when the container launches
CMD ["streamlit", "run", "admin.py"]

3 changes: 2 additions & 1 deletion admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# Uses st.cache_resource to only run once.
@st.cache_resource
def init_connection():
return pymongo.MongoClient(**st.secrets["mongo_host"])
url = st.secrets["mongo_db"]["url"]
return pymongo.MongoClient(url)

client = init_connection()

Expand Down
5 changes: 3 additions & 2 deletions admin/pages/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# Uses st.cache_resource to only run once.
@st.cache_resource
def init_connection():
return pymongo.MongoClient(**st.secrets["mongo_host"])
url = st.secrets["mongo_db"]["url"]
return pymongo.MongoClient(url)

client = init_connection()
# Title of the app
Expand Down Expand Up @@ -48,7 +49,7 @@ def init_connection():
"***EXPORT TO REDIS***"

# Get the URL for the Redis instance
redis_url = st.text_input("ENTER THE REDIS URL", value="redis://localhost:6379", key="redis_url_export")
redis_url = st.text_input("ENTER THE REDIS URL", value="redis://redis:6379", key="redis_url_export")
if redis_url:
if st.button("EXPORT VCONS", key="export_redis"):
# Connect to Redis
Expand Down
8 changes: 3 additions & 5 deletions admin/pages/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import redis
import boto3

# Enable large files
st.set_option('deprecation.showfileUploaderEncoding', False)

# Initialize connection.
# Uses st.cache_resource to only run once.
@st.cache_resource
def init_connection():
return pymongo.MongoClient(**st.secrets["mongo_host"])
url = st.secrets["mongo_db"]["url"]
return pymongo.MongoClient(url)

client = init_connection()

Expand All @@ -24,7 +22,7 @@ def init_connection():
"**UPLOAD A SINGLE VCON FILE**"

# Allow the user to upload a single JSON file
uploaded_file = st.file_uploader("UPLOAD", type="json, vcon")
uploaded_file = st.file_uploader("UPLOAD", type=["json", "vcon"])
if uploaded_file is not None:
if st.button("UPLOAD AND INSERT"):
db = client[st.secrets["mongo_db"]['db']]
Expand Down
7 changes: 4 additions & 3 deletions admin/pages/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

# Function to initialize the MongoDB connection
def get_mongo_client():
return pymongo.MongoClient(**st.secrets["mongo_host"])
url = st.secrets["mongo_db"]["url"]
return pymongo.MongoClient(url)

# Functin to return the summary of a vCon if it's available
def get_vcon_summary(vcon):
Expand All @@ -21,8 +22,8 @@ def get_vcon_summary(vcon):


# Get the query parameter (uuid) from the URL
q = st.experimental_get_query_params()
uuid = q.get('uuid', [''])[0]
uuids = st.query_params.get_all("uuid")
uuid = uuids[0] if uuids else None

if uuid:
st.write(f"INSPECTING VCON {uuid}")
Expand Down
3 changes: 2 additions & 1 deletion admin/pages/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# Function to initialize the MongoDB connection
def get_mongo_client():
return pymongo.MongoClient(**st.secrets["mongo_host"])
url = st.secrets["mongo_db"]["url"]
return pymongo.MongoClient(url)

# Functin to return the summary of a vCon if it's available
def get_vcon_summary(vcon):
Expand Down
7 changes: 7 additions & 0 deletions admin/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
streamlit>=1.30.0
redis
pandas
pymongo
boto3
openai

0 comments on commit c756106

Please sign in to comment.