diff --git a/chatify/assets/loading.gif b/chatify/assets/loading.gif new file mode 100644 index 0000000..9590093 Binary files /dev/null and b/chatify/assets/loading.gif differ diff --git a/chatify/main.py b/chatify/main.py index 7d22946..3c2f9d1 100644 --- a/chatify/main.py +++ b/chatify/main.py @@ -9,7 +9,7 @@ import ipywidgets as widgets from .chains import CreateLLMChain -from .widgets import option_widget, button_widget, text_widget, thumbs +from .widgets import option_widget, button_widget, text_widget, thumbs, loading_widget from .utils import check_dev_config, get_html @@ -71,7 +71,8 @@ def _read_prompt_dir(self): def _create_ui_elements(self): """Creates UI elements like buttons, prompt types, texts, and options.""" # Buttons and prompt types - self.button = button_widget() + self.execute_button = button_widget() + self.loading = loading_widget() self.prompt_types = self._read_prompt_dir() self.prompt_names = { item: key for item, key in enumerate(self.prompt_types.keys()) @@ -104,16 +105,13 @@ def _arrange_ui_elements(self, prompt_type): if self.cfg["feedback"]: elements = [ self.options[prompt_type], - self.button, + self.execute_button, self.thumbs_up, self.thumbs_down, ] else: - elements = [ - self.options[prompt_type], - self.button, - ] + elements = [self.options[prompt_type], self.execute_button, self.loading] hbox = widgets.HBox(elements) vbox = widgets.VBox([hbox, self.texts[prompt_type]]) return vbox @@ -156,6 +154,7 @@ def update_values(self, *args, **kwargs): *args Variable-length argument list. """ + self.loading.width = 30 index = self.tabs.selected_index selected_prompt = self.prompt_names[index] # Get the prompt @@ -164,6 +163,7 @@ def update_values(self, *args, **kwargs): ] self.texts[selected_prompt].value = self.gpt(self.cell_inputs, self.prompt) self.response = self.texts[selected_prompt].value + self.loading.width = 0 def record(self, *args): try: @@ -216,7 +216,7 @@ def explain(self, line, cell): display(accordion) # Button click - self.button.on_click(self.update_values) + self.execute_button.on_click(self.update_values) # Thumbs up and down self.thumbs_down.on_click(self.record) diff --git a/chatify/widgets.py b/chatify/widgets.py index 950b948..6c793cc 100644 --- a/chatify/widgets.py +++ b/chatify/widgets.py @@ -1,5 +1,7 @@ import ipywidgets as widgets +import pathlib + def option_widget(config): """Create an options dropdown widget based on the given configuration. @@ -41,6 +43,15 @@ def button_widget(): return button +def loading_widget(): + dirname = pathlib.Path(__file__).parent.resolve() + with open(f"{dirname}/assets/loading.gif", "rb") as file: + # read file as string into `image` + image = file.read() + loading = widgets.Image(value=image, format='gif', width=0, height=10) + return loading + + def thumbs(icon='fa-thumbs-up'): """Create a thumbs-up button widget. diff --git a/setup.py b/setup.py index 5c2d72e..f85eb38 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,28 @@ with open('HISTORY.rst') as history_file: history = history_file.read() -requirements = ['gptcache<=0.1.35', 'langchain<=0.0.226', 'openai', 'markdown', 'ipywidgets', 'requests', 'markdown-it-py[linkify,plugins]', 'pygments'] -extras = ['transformers', 'torch>=2.0', 'tensorflow>=2.0', 'flax', 'einops', 'accelerate', 'xformers', 'bitsandbytes', 'sentencepiece', 'llama-cpp-python'] +requirements = [ + 'gptcache<=0.1.35', + 'langchain<=0.0.226', + 'openai', + 'markdown', + 'ipywidgets', + 'requests', + 'markdown-it-py[linkify,plugins]', + 'pygments', +] +extras = [ + 'transformers', + 'torch>=2.0', + 'tensorflow>=2.0', + 'flax', + 'einops', + 'accelerate', + 'xformers', + 'bitsandbytes', + 'sentencepiece', + 'llama-cpp-python', +] test_requirements = [ 'pytest>=3', @@ -47,7 +67,7 @@ packages=find_packages(include=['chatify', 'chatify.*']), test_suite='tests', tests_require=test_requirements, - package_data={'': ['**/*.yaml']}, + package_data={'': ['**/*.yaml', '**/*.gif']}, url='https://github.com/ContextLab/chatify', version='0.2.1', zip_safe=False,