Skip to content

Commit

Permalink
🚀 Release 0.2.4
Browse files Browse the repository at this point in the history
🚀 Release 0.2.4
  • Loading branch information
dkedar7 authored Aug 12, 2023
2 parents 42c7436 + f0d8cc6 commit 3229e43
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
# uncomment the following to omit files during running
source = fast_dash
omit = *tests*
[report]
exclude_lines =
Expand All @@ -8,6 +9,7 @@ exclude_lines =
if self.debug:
if settings.DEBUG
raise AssertionError
raise ValueError
raise NotImplementedError
if 0:
if __name__ == .__main__.:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name: dev workflow
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master,main,release ]
# push:
# branches: [ master,main,release ]
pull_request:
branches: [ master,main,release ]

Expand Down
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Release 0.2.3
# Release 0.2.4

## 0.2.3 (2023-08-01)
## 0.2.4 (2023-08-12)

### Features
### Improvements

- Dash components can be directly used as type hints. They are converted to Fast components during app initialization.
- Added a mosaic layout example to README.
- `dash` can be imported from `fast_dash` like this: `from fast_dash import dash`.
- Improve responsiveness on mobile views.
- `outputs` argument overrides callback function output hints.
- Improve pytest coverage.
80 changes: 49 additions & 31 deletions docs/Examples/03_chat_over_documents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"outputs": [],
"source": [
"import os\n",
"from fast_dash import fastdash, FastDash, Fastify, dcc\n",
"import dash_mantine_components as dmc\n",
"from fast_dash import fastdash, Fastify, dcc, dmc\n",
"\n",
"from embedchain import App\n",
"from embedchain.config import QueryConfig\n",
Expand Down Expand Up @@ -74,29 +73,37 @@
"outputs": [],
"source": [
"# Define components\n",
"openai_api_key_component = Fastify(\n",
" dmc.PasswordInput(\n",
" placeholder=\"API Key\",\n",
" description=\"Get yours at https://platform.openai.com/account/api-keys\",\n",
" ),\n",
" \"value\",\n",
"openai_api_key_component = dmc.PasswordInput(\n",
" placeholder=\"API Key\",\n",
" description=\"Get yours at https://platform.openai.com/account/api-keys\",\n",
" required=True,\n",
")\n",
"\n",
"web_page_urls_component = Fastify(\n",
" dmc.MultiSelect(\n",
" description=\"Include all the reference Web URLs\",\n",
" placeholder=\"Enter URLs separated by commas\",\n",
" searchable=True,\n",
" creatable=True,\n",
" ),\n",
" \"data\",\n",
"web_page_urls_component = dmc.MultiSelect(\n",
" description=\"Include all the reference web URLs\",\n",
" placeholder=\"Enter URLs separated by commas\",\n",
" searchable=True,\n",
" creatable=True,\n",
")\n",
"\n",
"text_component = Fastify(\n",
" dmc.Textarea(placeholder=\"Write your query here\", autosize=True, minRows=4), \"value\"\n",
"text_component = dmc.Textarea(\n",
" placeholder=\"Custom text\",\n",
" autosize=True,\n",
" minRows=4,\n",
" description=\"Any additional information that could be useful\",\n",
")\n",
"\n",
"answer_component = Fastify(dcc.Markdown(style={\"text-align\": \"left\", \"padding\": \"1%\"}), \"children\")"
"query_component = dmc.Textarea(\n",
" placeholder=\"Write your query here\",\n",
" autosize=True,\n",
" minRows=4,\n",
" required=True,\n",
" description=\"Write your query here\",\n",
")\n",
"\n",
"answer_component = dcc.Markdown(\n",
" style={\"text-align\": \"left\", \"padding\": \"1%\"}, link_target=\"_blank\"\n",
")"
]
},
{
Expand All @@ -115,29 +122,40 @@
" youtube_urls: web_page_urls_component,\n",
" pdf_urls: web_page_urls_component,\n",
" text: text_component,\n",
" query: text_component,\n",
" query: query_component,\n",
") -> answer_component:\n",
" \"\"\"\n",
" Input your sources and let GPT3.5 find answers. Built with Fast Dash.\n",
" Input your sources and let GPT4 find answers. Built with Fast Dash.\n",
" This app uses embedchain.ai, which abstracts the entire process of loading and chunking datasets, creating embeddings, and storing them in a vector database.\n",
" Embedchain itself uses Langchain and OpenAI's ChatGPT API.\n",
" \"\"\"\n",
" os.environ[\"OPENAI_API_KEY\"] = openai_api_key\n",
" app = App()\n",
"\n",
" if web_page_urls:\n",
" [app.add(\"web_page\", url[\"value\"]) for url in web_page_urls]\n",
" try:\n",
" app = App()\n",
"\n",
" if not openai_api_key:\n",
" return \"Did you forget adding your OpenAI API key? If you don't have one, you can get it [here](https://platform.openai.com/account/api-keys).\"\n",
" \n",
" if not query:\n",
" return \"Did you forget writing your query in the query box?\"\n",
" \n",
" if web_page_urls:\n",
" [app.add(\"web_page\", url) for url in web_page_urls]\n",
"\n",
" if youtube_urls:\n",
" [app.add(\"youtube_video\", url) for url in youtube_urls]\n",
"\n",
" if youtube_urls:\n",
" [app.add(\"youtube_video\", url[\"value\"]) for url in youtube_urls]\n",
" if pdf_urls:\n",
" [app.add(\"pdf_file\", url) for url in pdf_urls]\n",
"\n",
" if pdf_urls:\n",
" [app.add(\"pdf_file\", url[\"value\"]) for url in pdf_urls]\n",
" if text:\n",
" app.add_local(\"text\", text)\n",
"\n",
" if text:\n",
" app.add_local(\"text\", text)\n",
" answer = app.query(query, query_config)\n",
"\n",
" answer = app.chat(query, query_config)\n",
" except Exception as e:\n",
" answer = \"Oops, something went wrong! Please try again later or make a suggestion [here](https://github.com/dkedar7/embedchain-fastdash/issues).\"\n",
"\n",
" return answer"
]
Expand Down
10 changes: 10 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# History

# Release 0.2.4

## 0.2.4 (2023-08-12)

### Improvements

- Improve responsiveness on mobile views.
- `outputs` argument overrides callback function output hints.
- Improve pytest coverage.

# Release 0.2.3

## 0.2.3 (2023-08-01)
Expand Down
53 changes: 30 additions & 23 deletions fast_dash/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
footer=True,
minimal=False,
scale_height=1,
app=None,
):
self.mosaic = mosaic
self.inputs = inputs
Expand All @@ -51,6 +52,7 @@ def __init__(
self.footer = footer
self.minimal = minimal
self.scale_height = scale_height
self.app = app

def generate_navbar_container(self):
if not self.navbar:
Expand Down Expand Up @@ -118,15 +120,16 @@ def generate_navbar_container(self):
dark=True,
fluid=True,
fixed=None,
expand=True,
style={"padding": "0 0 0 0"},
)

navbar_container = dbc.Container(
navbar_container = dbc.Row(
[navbar],
fluid=True,
# fluid=True,
style={"padding": "0 0 0 0"},
id="navbar3260780",
className="dbc",
# className="dbc",
)

return navbar_container
Expand Down Expand Up @@ -528,12 +531,12 @@ def generate_input_component(self):
return dbc.Col(
children=[dmc.Stack(children=self.inputs)],
id="input-group",
sm=2,
width=12,
xs=12,
md=2,
style={
"background-color": "#F5F7F7",
"display": "block",
"padding": "2% 1% 0 2%",
"padding": "2% 20px 0 20px",
"height": f"{self.scale_height * 110}vh",
},
class_name="border border-right",
Expand Down Expand Up @@ -573,6 +576,7 @@ def generate_output_component(self):
[layout] + [self.outputs[-1]],
class_name="g-1 d-flex flex-fill flex-column",
style={"height": f"{80 * self.scale_height}vh"},
width=12,
),
loaderProps=dict(variant="bars"),
)
Expand Down Expand Up @@ -626,35 +630,31 @@ def generate_layout(self):
self.generate_footer_container(),
],
fluid=True,
style={"padding": "0 0 0 0", "height": "100vh"},
style={"height": "100vh", "width": "100%"},
)
)

return layout

def callbacks(self, app):
@app.callback(
[Output("input-group", "style"), Output("output-group-col", "width")],
[Output("input-group", "style")],
[Input("sidebar-button", "opened")],
[State("input-group", "style")],
)
def toggle_sidebar(opened, input_style):
input_style = {} if input_style is None else input_style
width = 10

display = input_style.get("display", "block")

# Condition to collapse the sidebar
if not opened:
# Condition to collapse the sidebar:
# Burger icon is closed or no inputs are specified
if not opened or self.app.inputs == [] or self.app.inputs is None:
input_style.update({"display": "none"})
width = 12

# Expand by default
else:
input_style.update({"display": "block"})
width = 10

return input_style, width
return (input_style,)


_map_types_to_readable_names = {
Expand Down Expand Up @@ -1002,17 +1002,24 @@ def _infer_input_components(func):
return components


def _infer_output_components(func, output_labels):
def _infer_output_components(func, outputs, output_labels):
signature = inspect.signature(func)
components = []

parameters = list(
enumerate(
signature.return_annotation
if isinstance(signature.return_annotation, tuple)
else [signature.return_annotation]
if isinstance(outputs, list):
parameters = [(None, o) for o in outputs]

elif outputs is not None:
parameters = [(None, outputs)]

else:
parameters = list(
enumerate(
signature.return_annotation
if isinstance(signature.return_annotation, tuple)
else [signature.return_annotation]
)
)
)

if output_labels is None:
output_labels = [None] * len(parameters)
Expand Down
2 changes: 1 addition & 1 deletion fast_dash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Kedar Dabhadkar"""
__email__ = "[email protected]"
__version__ = "0.2.3"
__version__ = "4"

from fast_dash.Components import (
Graph,
Expand Down
9 changes: 3 additions & 6 deletions fast_dash/fast_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,11 @@ def __init__(
self.mosaic = mosaic
self.output_labels = output_labels

if output_labels:
if output_labels == "infer":
self.output_labels = _infer_variable_names(callback_fn)

self.inputs = _infer_input_components(callback_fn) if inputs is None else inputs
self.outputs = (
_infer_output_components(callback_fn, self.output_labels)
if outputs is None
else outputs
)
self.outputs = _infer_output_components(callback_fn, outputs, self.output_labels)
self.update_live = update_live
self.mode = mode
self.disable_logs = disable_logs
Expand Down Expand Up @@ -260,6 +256,7 @@ def set_layout(self):
"footer": self.footer,
"minimal": self.minimal,
"scale_height": self.scale_height,
"app": self
}

if self.layout_pattern == "sidebar":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool]
[tool.poetry]
name = "fast_dash"
version = "0.2.3"
version = "0.2.4"
homepage = "https://github.com/dkedar7/fast_dash"
description = "Build Machine Learning prototypes web applications lightning fast."
authors = ["Kedar Dabhadkar <[email protected]>"]
Expand Down
9 changes: 8 additions & 1 deletion tests/test_fast_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,11 @@ def test_fdfd010_output_labels(dash_duo):
"Test the auto-infer variable name feature"

app = FastDash(callback_fn=simple_text_to_multiple_outputs)
assert app.output_labels == ["FIG", "RETURN_SOME_TEXT"]
assert app.output_labels == ["FIG", "RETURN_SOME_TEXT"]


def test_fdfd011_base_layout(dash_duo):
"Test base layout"

app = FastDash(callback_fn=simple_text_to_multiple_outputs, layout="base")
assert app.output_labels == ["FIG", "RETURN_SOME_TEXT"]

0 comments on commit 3229e43

Please sign in to comment.