Skip to content

Commit

Permalink
Initialised
Browse files Browse the repository at this point in the history
  • Loading branch information
Sprocketer committed Apr 3, 2024
0 parents commit 4dc946f
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
19 changes: 19 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[client]
showErrorDetails = false
toolbarMode = "viewer"

[runner]
magicEnabled = true

[server]
port = 8501

[browser]
serverPort = 8501

[theme]
base = "dark"
primaryColor = "#a6d189"
backgroundColor="#232634"
secondaryBackgroundColor="#303446"
textColor="#e78284"
Empty file added .streamlit/secrets.toml
Empty file.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Streamlit Base

## Intended Use

### Gist

This is a *template repository*, so its intended use is to create other repositories which **build off of this web app template**.

### Use cases

Set up by default with an **authentication system** - this is suited for general websites, but of course also works for data display apps.


## Dependencies

### Pip Packages

All pip requirements are listed in *`requirements.txt`*


## Authentication

### Authentication Widgets

Uses streamlit-authenticator library for authentication widgets

### Credentials

Credentials are stored in *`config.yaml`*


## Config && Secrets

### Config

Configuration for Streamlit is stored in *`/.streamlit/config.toml`*

### Secrets

Secrets for Streamlit environment are stored in *`/.streamlit/secrets.toml`*


## Github Actions

### Pylint

Default Pylint Github Action is set up in *`/.github/workflows/pylint.yml`*


## Licensing

### None (ish).

Unlicensed using **`https://unlicense.org/`** - see *`UNLICENSE`* file
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
14 changes: 14 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cookie:
expiry_days: 0
key: credentials_key
name: credentials
credentials:
usernames:
example: # delete after first user is created
email: [email protected]
logged_in: false
name: Example
password: $bVAxa0JEenI1TkdGdnl2Uw$8qbxUe51emMU4d2VFeJivw
preauthorized:
emails:
- [email protected]
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
streamlit
extra-streamlit-components
streamlit-authenticator
57 changes: 57 additions & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
""" Main Streamlit site file """

from yaml.loader import SafeLoader
import yaml

import streamlit as st
import streamlit_authenticator as stauth

# Uncomment below if you need cookies:
# import extra_streamlit_components as stx

# Config page
PAGE_TITLE = ""
PAGE_ICON = ""
st.set_page_config(
PAGE_TITLE, PAGE_ICON, layout="wide", initial_sidebar_state="collapsed"
)
#

# Checks for empty variables
if not PAGE_TITLE:
raise ValueError(
"Please set the PAGE_TITLE variable to the title of your app")

if not PAGE_ICON:
raise ValueError(
"Please set the PAGE_ICON variable to the icon of your app")
#

with open('config.yaml', 'r', encoding="utf-8") as file:
config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)

authenticator.login()

auth_state = st.session_state["authentication_status"]
if auth_state is False or auth_state is None:
st.error('Username/password is incorrect')
try:
email, username, name = authenticator.register_user(
preauthorization=False)
if email:
st.success('User registered successfully')
with open('config.yaml', 'w', encoding="utf-8") as file:
yaml.dump(config, file, default_flow_style=False)
except Exception as e:
st.error(e)
else:
# LOGGED IN CONTENT
pass
24 changes: 24 additions & 0 deletions workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint -d W0703 $(git ls-files '*.py')

0 comments on commit 4dc946f

Please sign in to comment.