Skip to content

Commit

Permalink
Add super simple concept
Browse files Browse the repository at this point in the history
  • Loading branch information
blythed committed Nov 4, 2024
1 parent d2017ed commit 924803b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/ci_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,29 @@ jobs:
if: env.mode == 'changed'
id: set-matrix-1
run: |
IFS=$'\n'
changed_files=(${{ steps.changed-files-specific.outputs.all_changed_files }})
# IFS=$'\n'
changed_files=(superduper/components/streamlit.py .github/workflows/ci_templates.yaml .gitignore superduper/__init__.py)
declare -A template_set
# Check each file if it's in the templates/ directory
for file in "${changed_files[@]}"; do
if [[ "$file" =~ ^templates/ ]]; then
template_name=$(echo "$file" | cut -d '/' -f 2)
template_set[$template_name]=1
fi
done
templates=("${!template_set[@]}")
matrix_json=$(printf '%s\n' "${templates[@]}" | jq -R -s -c '{template: split("\n")[:-1]}')
# Generate a single-line JSON
matrix_json=$(printf '%s' "${templates[@]}" | jq -R -s 'if . == "" then {template: []} else {template: (./"\n" | map(select(. != "")))} end' | jq -c .)
echo "matrix_json=$matrix_json"
echo "Changed templates: ${templates[*]}"
echo "matrix_json: $matrix_json"
echo "matrix_json=$matrix_json" >> $GITHUB_ENV
- name: Get all templates to test
if: env.mode == 'all'
id: set-matrix-2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,5 @@ test/sleep.json
/output/
/deploy/testenv/requirements.txt
/superduper/rest/superdupertmp
/example.py

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### New Features & Functionality

- Streamlit component and server

#### Bug Fixes

## [0.4.2](https://github.com/superduper-io/superduper/compare/0.4.2...0.4.1]) (2024-Nov-03)
Expand Down
2 changes: 2 additions & 0 deletions superduper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
from .components.plugin import Plugin
from .components.schema import Schema
from .components.streamlit import Streamlit
from .components.table import Table
from .components.template import QueryTemplate, Template
from .components.vector_index import VectorIndex, vector
Expand Down Expand Up @@ -71,4 +72,5 @@
'templates',
'imported',
'imported_value',
'Streamlit',
)
53 changes: 53 additions & 0 deletions superduper/components/streamlit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import dataclasses as dc
import typing as t

from superduper import Component


class Streamlit(Component):
"""Streamlit demo function to be deployed on the streamlit server.
:param demo_func: Callable which builds the demo.
:param default: Set to `True` if this is to be the frontpage.
"""

type_id: t.ClassVar[str] = 'streamlit'
demo_func: t.Callable
demo_kwargs: t.Dict = dc.field(default_factory=dict)
default: bool = False

@property
def page(self):
"""Get the streamlit page for the multi-page app."""
import streamlit as st

def demo_func():
return self.demo_func(db=self.db, **self.demo_kwargs)

return st.Page(demo_func, title=self.identifier, default=self.default)


if __name__ == '__main__':

def func_default():
"""Default page."""
import streamlit as st

st.title('Welcome to the Superduper Streamlit Server!')

from superduper import superduper

db = superduper()

pages = []
for demo_name in db.show('streamlit'):
demo = db.load('streamlit', demo_name)
demo.init()
pages.append(demo.page)

import streamlit as st

landing = st.Page(func_default, title="Landing", default=True)
pg = st.navigation([landing, *pages])
st.set_page_config(page_title="Data manager", page_icon=":material/edit:")
pg.run()

0 comments on commit 924803b

Please sign in to comment.