Skip to content

Commit

Permalink
Adds passwords and fixes workbench bug
Browse files Browse the repository at this point in the history
  • Loading branch information
howethomas committed Feb 8, 2024
1 parent 9a0bb74 commit 7458b8f
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 42 deletions.
47 changes: 12 additions & 35 deletions admin/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"""
## Admin Portal
This is the admin portal for the system. It allows you to view the current configuration, and to make changes to it.
"""

import streamlit as st
import redis
import pandas as pd
import pymongo
import json
import os

"""
## Admin Portal
from common import manage_session_state
# Check to make sure the user is logged in
manage_session_state()

This is the admin portal for the system. It allows you to view the current configuration, and to make changes to it.
"""
# Initialize connection.
# Uses st.cache_resource to only run once.
@st.cache_resource
Expand All @@ -21,41 +26,13 @@ def init_connection():

client = init_connection()

# Print the current directory to markdown
st.markdown(f"Current directory: {os.getcwd()}")

# Print the contents of the directory to markdown
st.markdown(f"Contents of the directory: {os.listdir()}")



# Current directory in the container is /app
# Check if the file exists
if os.path.isfile("custom_info.md"):
# Open the file and read its contents
with open("custom_info.md", "r") as file:
contents = file.read()
else:
contents = "No custom information available."

# Display the contents in the Streamlit app
st.markdown(contents)



col1, col2 = st.columns(2)
with col1:
st.header("Current Configuration")
st.write("The current configuration of the system is displayed below.")
st.write("To make changes, click on the 'Edit Configuration' button.")
if st.button("Edit Configuration"):
st.write("You clicked the button!")
with col2:
st.header("System Status")
st.write("The current status of the system is displayed below.")
st.write("To make changes, click on the 'Edit Status' button.")
if st.button("Edit Status"):
st.write("You clicked the button!")
st.markdown(contents)

# Add three tabs
st.header("Recent vCons")
Expand Down
43 changes: 43 additions & 0 deletions admin/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# common.py
import streamlit as st

def redirect(page_name):
st.session_state.current_page = page_name
st.experimental_rerun()

def logged_in():
if 'logged_in' not in st.session_state:
st.session_state.logged_in = False
return st.session_state.logged_in

def login():
st.session_state.logged_in = True
st.experimental_rerun()

def logout():
st.session_state.logged_in = False
st.experimental_rerun()

def manage_session_state():
# Check to make sure the user is logged in
if 'admin_password' not in st.secrets:
st.write("No admin password set. Please set the admin password in the secrets.")
st.stop()
else:
admin_password = st.secrets["admin_password"]['password']

if logged_in() is False:
# Log in the user by setting the session state variable
# Get the password from the secrets and compare it to the user input
# Make a login form
password = st.text_input("Enter password", type="password")
if st.button("Log in"):
if password == admin_password:
login()
else:
st.write("Incorrect password :", password, admin_password)
st.stop()

# Log out the user by setting the session state variable
if st.button("Log out"):
logout()
7 changes: 7 additions & 0 deletions admin/pages/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
import pymongo
import json
import redis
import sys
import os

# Add the parent directory to the system path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common import manage_session_state
# Check to make sure the user is logged in
manage_session_state()

# Initialize connection.
# Uses st.cache_resource to only run once.
Expand Down
10 changes: 10 additions & 0 deletions admin/pages/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
import json
import redis
import boto3
import sys
import os


# Add the parent directory to the system path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common import manage_session_state
# Check to make sure the user is logged in
manage_session_state()


# Initialize connection.
# Uses st.cache_resource to only run once.
Expand Down
9 changes: 9 additions & 0 deletions admin/pages/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import pymongo
import openai
import json
import sys
import os

# Add the parent directory to the system path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common import manage_session_state
# Check to make sure the user is logged in
manage_session_state()


# Title and page layout
st.title("VCON INSPECTOR")
Expand Down
26 changes: 19 additions & 7 deletions admin/pages/workbench.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import streamlit as st
import pymongo
import json
import sys
import os

# Add the parent directory to the system path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common import manage_session_state
# Check to make sure the user is logged in
manage_session_state()


# This code is for v1 of the openai package: pypi.org/project/openai
from openai import OpenAI
OPENAI_API_KEY="sk-xxxxxxxxxxx"
import json

# Get the OPENAI_API_KEY from the secrets
OPENAI_API_KEY=st.secrets["openai"]["OPENAI_API_KEY"]
open_ai_client = OpenAI(
api_key=OPENAI_API_KEY
)
Expand Down Expand Up @@ -162,13 +174,13 @@ def get_vcon_transcript(vcon):
mongo_client = get_mongo_client()
db = mongo_client[st.secrets["mongo_db"]["db"]]
vcon = db[st.secrets["mongo_db"]["collection"]].find_one({'uuid': vcon_uuid})
match input_type:
case "complete":
content = json.dumps(vcon)
case "summary":
content = ""
if input_type == "complete":
content = json.dumps(vcon)
if input_type == "summary":
content = get_vcon_summary(vcon)
case "transcript":
content = get_vcon_transcript(vcon)
if input_type == "transcript":
content = get_vcon_transcript(vcon)

# Call open AI to complete the prompt
st.subheader(f"RESULTS FOR VCON {vcon_uuid}")
Expand Down

0 comments on commit 7458b8f

Please sign in to comment.