From fb1d5394b0794589c4f11bf781982b2772967e8e Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Tue, 1 Aug 2023 22:42:23 -0400 Subject: [PATCH 1/7] Upgrade example #3 to v0.2.3 --- docs/Examples/03_chat_over_documents.ipynb | 80 +++++++++++++--------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/docs/Examples/03_chat_over_documents.ipynb b/docs/Examples/03_chat_over_documents.ipynb index dcd009f..80ac272 100644 --- a/docs/Examples/03_chat_over_documents.ipynb +++ b/docs/Examples/03_chat_over_documents.ipynb @@ -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", @@ -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", + ")" ] }, { @@ -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" ] From 98000cd8545619fc92e49fb57a7213dc28df88fa Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 14:42:30 -0400 Subject: [PATCH 2/7] Improve mobile layout (sidebar and output widths) --- fast_dash/Components.py | 32 ++++++++++++++++---------------- fast_dash/fast_dash.py | 1 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fast_dash/Components.py b/fast_dash/Components.py index 1cd1b98..d902408 100644 --- a/fast_dash/Components.py +++ b/fast_dash/Components.py @@ -37,6 +37,7 @@ def __init__( footer=True, minimal=False, scale_height=1, + app=None, ): self.mosaic = mosaic self.inputs = inputs @@ -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: @@ -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 @@ -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", @@ -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"), ) @@ -626,7 +630,7 @@ def generate_layout(self): self.generate_footer_container(), ], fluid=True, - style={"padding": "0 0 0 0", "height": "100vh"}, + style={"height": "100vh", "width": "100%"}, ) ) @@ -634,27 +638,23 @@ def generate_layout(self): 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 len(self.app.inputs) == 0: 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 = { diff --git a/fast_dash/fast_dash.py b/fast_dash/fast_dash.py index 61a7ad2..fdf5a9d 100644 --- a/fast_dash/fast_dash.py +++ b/fast_dash/fast_dash.py @@ -260,6 +260,7 @@ def set_layout(self): "footer": self.footer, "minimal": self.minimal, "scale_height": self.scale_height, + "app": self } if self.layout_pattern == "sidebar": From cb7d6fd833de2d80cc8513a5322c1d2b246420ec Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 16:26:37 -0400 Subject: [PATCH 3/7] Limit pytest coverate to fast_dash and omit error lines --- .coveragerc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.coveragerc b/.coveragerc index f377bdf..fffdac3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,6 @@ [run] # uncomment the following to omit files during running +source = fast_dash omit = *tests* [report] exclude_lines = @@ -8,6 +9,7 @@ exclude_lines = if self.debug: if settings.DEBUG raise AssertionError + raise ValueError raise NotImplementedError if 0: if __name__ == .__main__.: From 10ca2b0e2c46dcccefd2a12caf4a8d2fa45b6ef7 Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 16:27:02 -0400 Subject: [PATCH 4/7] {Add test] Base layout --- tests/test_fast_dash.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_fast_dash.py b/tests/test_fast_dash.py index 52d6713..6ef6fea 100644 --- a/tests/test_fast_dash.py +++ b/tests/test_fast_dash.py @@ -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"] \ No newline at end of file + 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"] From 904fe36cc417e4f270cdb0c5455c135be885ce3e Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 16:27:38 -0400 Subject: [PATCH 5/7] Fix: Outputs argument overwrites output hints --- fast_dash/Components.py | 23 +++++++++++++++-------- fast_dash/fast_dash.py | 8 ++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/fast_dash/Components.py b/fast_dash/Components.py index d902408..8ecfe34 100644 --- a/fast_dash/Components.py +++ b/fast_dash/Components.py @@ -647,7 +647,7 @@ def toggle_sidebar(opened, input_style): # Condition to collapse the sidebar: # Burger icon is closed or no inputs are specified - if not opened or len(self.app.inputs) == 0: + if not opened or self.app.inputs == [] or self.app.inputs is None: input_style.update({"display": "none"}) # Expand by default @@ -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) diff --git a/fast_dash/fast_dash.py b/fast_dash/fast_dash.py index fdf5a9d..d16cf5f 100644 --- a/fast_dash/fast_dash.py +++ b/fast_dash/fast_dash.py @@ -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 From e1a51fe83b243c9118c2a37efa62d4b39b3e09c8 Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 16:30:40 -0400 Subject: [PATCH 6/7] [Action] Disable rerunning dev workflow on push to main --- .github/workflows/dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index edb43d0..7f109ea 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -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 ] From f0d8cc66a38bf5bf95596bac6711351170670f9d Mon Sep 17 00:00:00 2001 From: Kedar Dabhadkar Date: Sat, 12 Aug 2023 16:36:47 -0400 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=9A=80=20Release=200.2.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++------ docs/history.md | 10 ++++++++++ fast_dash/__init__.py | 2 +- pyproject.toml | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd5c857..af4f046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. \ No newline at end of file +- Improve responsiveness on mobile views. +- `outputs` argument overrides callback function output hints. +- Improve pytest coverage. \ No newline at end of file diff --git a/docs/history.md b/docs/history.md index 3ae23fc..dd4c314 100644 --- a/docs/history.md +++ b/docs/history.md @@ -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) diff --git a/fast_dash/__init__.py b/fast_dash/__init__.py index 3e677e0..dcfc70f 100644 --- a/fast_dash/__init__.py +++ b/fast_dash/__init__.py @@ -2,7 +2,7 @@ __author__ = """Kedar Dabhadkar""" __email__ = "kedar@fastdash.app" -__version__ = "0.2.3" +__version__ = "4" from fast_dash.Components import ( Graph, diff --git a/pyproject.toml b/pyproject.toml index 8b93c32..dd75660 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "]