Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,49 @@ HF_TOKEN=<required - get from https://huggingface.co/settings/tokens>

### Launch

The application supports two modes of operation:

#### Production Mode (Default)
```bash
streamlit run app.py
```

**Note:** Production mode requires authentication credentials to be configured in `.streamlit/secrets.toml`. If credentials are not configured, the application will show an error message with options to either:
- Switch to development mode
- Configure the required credentials

#### Development Mode
```bash
streamlit run app.py dev
```

**Note:** Development mode provides full functionality without authentication requirements, making it ideal for testing and development.

### Authentication Configuration (Production Mode)

For production mode, you need to configure authentication credentials in `.streamlit/secrets.toml`:

```toml
# For Auth0 authentication
[auth.auth0]
domain = "your-domain.auth0.com"
client_id = "your-client-id"
client_secret = "your-client-secret"
server_metadata_url = "https://your-domain.auth0.com/.well-known/openid_configuration"
client_kwargs = { "prompt" = "login"}

# OR for Google OAuth
[auth.google]
client_id = "your-google-client-id"
client_secret = "your-google-client-secret"
server_metadata_url = "https://accounts.google.com/.well-known/openid_configuration"

# General auth settings
[auth]
redirect_uri = "your-redirect-uri"
cookie_secret = "your-cookie-secret"
```

<img src="./images/add_knowledge.png" alt="HF Access Token" width="500" height="300"/>
<img src="./images/update_knowledge.png" alt="HF Access Token" width="500" height="300"/>

Expand Down
91 changes: 90 additions & 1 deletion src/mvt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from database import create_connection, create_table, create_prompts_table, get_user, insert_user
from homepage import gethomepage
import os
import sys
from dotenv import load_dotenv, find_dotenv

# Load environment variables FIRST, before any imports
Expand All @@ -15,12 +16,100 @@
else:
print("WARNING: HF_TOKEN not found in environment variables")

# Check command line arguments for mode
def get_operation_mode():
"""Determine operation mode from command line arguments or session state override"""
# Check if user switched to dev mode via button
if st.session_state.get("switch_to_dev", False):
return "dev"

# Check command line arguments
if len(sys.argv) > 1 and sys.argv[1] == "dev":
return "dev"
return "production"

# Define the mode of operation
operation_mode = "dev" # Change to "production" for production mode
operation_mode = get_operation_mode()

# Function to check if production credentials are configured
def check_production_credentials():
"""Check if required credentials are configured in secrets.toml"""
try:
# Check if auth0 credentials are configured
auth0_domain = st.secrets.get("auth.auth0.domain", "")
auth0_client_id = st.secrets.get("auth.auth0.client_id", "")
auth0_client_secret = st.secrets.get("auth.auth0.client_secret", "")

# Check if google credentials are configured
google_client_id = st.secrets.get("auth.google.client_id", "")
google_client_secret = st.secrets.get("auth.google.client_secret", "")

# Return True if at least one authentication method is configured
return bool(auth0_domain and auth0_client_id and auth0_client_secret) or \
bool(google_client_id and google_client_secret)
except Exception:
return False

# Function to display error message
def show_credentials_error():
"""Display error message for missing credentials"""
st.error("⚠️ Production Mode Error: Credentials not configured")

st.write("You're trying to run the application in **production mode**, but the required authentication credentials are not configured in your `.streamlit/secrets.toml` file.")

st.subheader("Solutions:")

st.write("**Option 1: Use Development Mode**")
st.code("streamlit run app.py dev")

st.write("**Option 2: Fill up credentials in secrets.toml for Production**")
st.write("For production mode, you need to fill up the credentials in your `.streamlit/secrets.toml` file:")

st.code("""
# For Auth0 authentication
[auth.auth0]
domain = "your-domain.auth0.com"
client_id = "your-client-id"
client_secret = "your-client-secret"
server_metadata_url = "https://your-domain.auth0.com/.well-known/openid_configuration"
client_kwargs = { "prompt" = "login"}

# OR for Google OAuth
[auth.google]
client_id = "your-google-client-id"
client_secret = "your-google-client-secret"
server_metadata_url = "https://accounts.google.com/.well-known/openid_configuration"

# General auth settings
[auth]
redirect_uri = "your-redirect-uri"
cookie_secret = "your-cookie-secret"
""")

st.warning("⚠️ **For Production Mode:** Either fill up the credentials in `secrets.toml` or use dev mode by running `streamlit run app.py dev`")

# Check if we're in production mode and credentials are missing
if operation_mode == "production" and not check_production_credentials():
show_credentials_error()
# Don't stop here, let the button work
if st.button("🔄 Switch to Development Mode", type="primary"):
# Set a session state to indicate dev mode switch
st.session_state.switch_to_dev = True
st.rerun()

# Only stop if user hasn't clicked the switch button
if not st.session_state.get("switch_to_dev", False):
st.stop()

# Get markdown homepage
st.markdown(body=gethomepage(), unsafe_allow_html=True)

# Display current mode indicator
if operation_mode == "dev":
st.sidebar.info("Development Mode")
else:
st.sidebar.success("Production Mode")

if (operation_mode == "dev"):
# Development mode: no authentication required
# Initialize all necessary session state variables for full functionality
Expand Down