diff --git a/models/content-engine/__plugin__.ipynb b/models/content-engine/__plugin__.ipynb index d942257..318db9a 100644 --- a/models/content-engine/__plugin__.ipynb +++ b/models/content-engine/__plugin__.ipynb @@ -144,7 +144,7 @@ "name = \"📲 Content Assistant\"\n", "model = \"gpt-4-1106-preview\"\n", "temperature = 0.5\n", - "description = \"Track your content performance across platforms, leverage AI for optimized strategies and assistance in writing impactful new content that will increase reach & boost engagement.\"\n", + "description = \"Streamline the generation and distribution of content that aligns with the user's or business's brand voice and audience engagement goals.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"content-engine\")\n", "\n", diff --git a/models/finance-engine/__plugin__.ipynb b/models/finance-engine/__plugin__.ipynb index e451ce5..1c26c27 100644 --- a/models/finance-engine/__plugin__.ipynb +++ b/models/finance-engine/__plugin__.ipynb @@ -141,7 +141,7 @@ "\"\"\"\n", "model = \"gpt-3.5-turbo-16k\"\n", "temperature = 0\n", - "description = \"This plugin is used to setup the Finance Engine\"\n", + "description = \"Manage financial transactions accurately and maintain comprehensive records for informed financial planning and analysis.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"finance-engine\")\n", "\n", diff --git a/models/finance-engine/core/domain/Plotly_Follow_cash_flow.ipynb b/models/finance-engine/core/domain/Plotly_Follow_cash_flow.ipynb new file mode 100644 index 0000000..95e57ef --- /dev/null +++ b/models/finance-engine/core/domain/Plotly_Follow_cash_flow.ipynb @@ -0,0 +1,626 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "6859e258-5916-47e0-bafe-840216bccb66", + "metadata": { + "execution": { + "iopub.execute_input": "2021-02-23T14:22:16.610471Z", + "iopub.status.busy": "2021-02-23T14:22:16.610129Z", + "iopub.status.idle": "2021-02-23T14:22:16.627784Z", + "shell.execute_reply": "2021-02-23T14:22:16.626866Z", + "shell.execute_reply.started": "2021-02-23T14:22:16.610384Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Plotly.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "53d8faa3-625a-4ce0-8ac0-2144fc572bf9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Plotly - Follow cash flow" + ] + }, + { + "cell_type": "markdown", + "id": "c333a80d-ed9a-4721-9980-8b2724b12dc6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #plotly #html #csv #image #finance #analytics #transactions #ledger #metric" + ] + }, + { + "cell_type": "markdown", + "id": "8df1c2de-f9b1-44f6-abdd-dc6fe4251c14", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "7d7c58bc-96fa-4961-96d8-7f7ef5c535b4", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook creates a barline chart graph tracking your cashflows over the last 12 months." + ] + }, + { + "cell_type": "markdown", + "id": "distinguished-truth", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "numeric-mediterranean", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "potential-surfing", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import plotly.graph_objects as go\n", + "from plotly.subplots import make_subplots\n", + "import pandas as pd\n", + "import naas\n", + "import random\n", + "import os\n", + "from datetime import date, datetime, timedelta\n", + "import naas_data_product" + ] + }, + { + "cell_type": "markdown", + "id": "9b63f92e-b1e0-43cc-86d8-db12ae89558e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Inputs**\n", + "- `entity_dir`: Entity directory.\n", + "- `entity_name`: Entity name.\n", + "- `input_dir`: Input directory to retrieve file from.\n", + "- `input_file`: Input file.\n", + "- `spreadsheet_url`: Google Sheets spreadsheet URL.\n", + "- `sheet_name`: Google Sheets sheet name.\n", + "- `title`: Graph title.\n", + "\n", + "**Outputs**\n", + "- `output_dir`: This variable is used for storing the path to the directory where the output files will be saved." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47b21878-f530-436b-95f8-4ed65b42da19", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Inputs\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_dir\")\n", + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_name\")\n", + "input_dir = os.path.join(entity_dir, \"finance-engine\", date.today().isoformat())\n", + "input_file = \"transactions\"\n", + "spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"abi_spreadsheet\")\n", + "sheet_name = \"TRANSACTIONS\"\n", + "title = \"Cash Flow Statement\"\n", + "\n", + "# Outputs\n", + "output_dir = os.path.join(entity_dir, \"finance-engine\", date.today().isoformat())\n", + "os.makedirs(output_dir, exist_ok=True)\n", + "output_name = \"finance_trend\"" + ] + }, + { + "cell_type": "markdown", + "id": "registered-showcase", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "6c59de19-9541-47b9-8561-55ad88243907", + "metadata": {}, + "source": [ + "### Set outputs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5948dbb-fb9b-48b2-ac10-ce635837609e", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "html_output = os.path.join(output_dir, f\"{output_name}.html\")\n", + "image_output = os.path.join(output_dir, f\"{output_name}.png\")" + ] + }, + { + "cell_type": "markdown", + "id": "0df10ed5-44fe-4abd-a3c1-61154c819e8c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get \"Cashin\" data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82cb0b6e-1a32-46fb-96b2-a1fba5ff515e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "data_cashin = {\n", + " \"ENTITY\": [\"Abi\"] * 12,\n", + " \"SCENARIO\": [\"2023-12\"] * 12,\n", + " \"LABEL\": [\n", + " \"2023-01\",\n", + " \"2023-02\",\n", + " \"2023-03\",\n", + " \"2023-04\",\n", + " \"2023-05\",\n", + " \"2023-06\",\n", + " \"2023-07\",\n", + " \"2023-08\",\n", + " \"2023-09\",\n", + " \"2023-10\",\n", + " \"2023-11\",\n", + " \"2023-12\",\n", + " ],\n", + " \"GROUP\": [\"Cash in\"] * 12,\n", + " \"VALUE\": [random.randint(250, 500) for i in range(0, 12)],\n", + "}\n", + "\n", + "df_cashin = pd.DataFrame(data_cashin)\n", + "df_cashin" + ] + }, + { + "cell_type": "markdown", + "id": "706da888-645f-4d24-a2df-08570dcf10e3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get \"Cashout\" data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df314ec4-6836-4cb8-a488-59ebd71937e9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "data_cashout = {\n", + " \"ENTITY\": [\"Abi\"] * 12,\n", + " \"SCENARIO\": [\"2023-12\"] * 12,\n", + " \"LABEL\": [\n", + " \"2023-01\",\n", + " \"2023-02\",\n", + " \"2023-03\",\n", + " \"2023-04\",\n", + " \"2023-05\",\n", + " \"2023-06\",\n", + " \"2023-07\",\n", + " \"2023-08\",\n", + " \"2023-09\",\n", + " \"2023-10\",\n", + " \"2023-11\",\n", + " \"2023-12\",\n", + " ],\n", + " \"GROUP\": [\"Cash out\"] * 12,\n", + " \"VALUE\": [random.randint(0, 350) * -1 for i in range(0, 12)],\n", + "}\n", + "df_cashout = pd.DataFrame(data_cashout)\n", + "df_cashout" + ] + }, + { + "cell_type": "markdown", + "id": "9a8484e3-708e-4453-81e5-05122c4dacb5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Calculate \"Cash Position\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "081e987c-a03a-4c98-8573-180ec3d7c6a1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# concat cash in and cash out\n", + "df_position = pd.concat([df_cashin, df_cashout])\n", + "\n", + "# rename column GROUP = \"Position\" and groupby + agg\n", + "to_group = [\n", + " \"ENTITY\",\n", + " \"SCENARIO\",\n", + " \"LABEL\",\n", + " \"GROUP\"\n", + "]\n", + "to_agg = {\n", + " \"VALUE\": \"sum\"\n", + "}\n", + "df_position[\"GROUP\"] = \"Position\"\n", + "df_position[\"VALUE\"] = df_position[\"VALUE\"] + 1000\n", + "df_position = df_position.groupby(to_group, as_index=False).agg(to_agg)\n", + "df_position" + ] + }, + { + "cell_type": "markdown", + "id": "392bcc8b-0844-4d69-ac89-d07eccbaaa7c", + "metadata": {}, + "source": [ + "### Create title and logo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f15b017-bdc8-4d19-bd85-31ab1082144d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "# Calc data\n", + "total = df_position.loc[df_position.index[-1], \"VALUE\"]\n", + "total_n1 = df_position.loc[df_position.index[-2], \"VALUE\"]\n", + "varv = df_cashin.loc[df_cashin.index[-1], \"VALUE\"] + df_cashout.loc[df_cashout.index[-1], \"VALUE\"]\n", + "varp = 0\n", + "if total_n1 != 0:\n", + " varp = varv / total_n1\n", + "\n", + "# Create value to displayed\n", + "total_d = \"{:,.0f}\".format(total).replace(\",\", \" \")\n", + "varv_d = \"{:,.0f}\".format(varv).replace(\",\", \" \")\n", + "varp_d = \"{:,.0%}\".format(varp).replace(\",\", \" \")\n", + "if varv >= 0:\n", + " varv_d = f\"+{varv_d}\"\n", + " varp_d = f\"+{varp_d}\"\n", + "title_full = f\"{title}
{total_d} | {varv_d} ({varp_d}) vs last month\"\n", + "\n", + "# Logo\n", + "logo = None\n", + "if varv > 0:\n", + " logo = arrow_up\n", + "elif varv > -0.2:\n", + " logo = arrow_right\n", + "else:\n", + " logo = arrow_down\n", + "print(\"Title:\", title_full)" + ] + }, + { + "cell_type": "markdown", + "id": "tested-astrology", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create barlinechart using Plotly" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "crude-louisville", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def create_barlinechart(\n", + " df_cashin,\n", + " df_cashout,\n", + " df_position,\n", + " xaxis_title=None,\n", + " yaxis_title_r=None,\n", + " yaxis_title_l=None,\n", + "):\n", + " # Create figure with secondary y-axis\n", + " fig = make_subplots(specs=[[{\"secondary_y\": True}]])\n", + "\n", + " # Add traces\n", + " fig.add_trace(\n", + " go.Bar(\n", + " name=\"Encaissement\",\n", + " x=df_cashin[\"LABEL\"],\n", + " y=df_cashin[\"VALUE\"],\n", + " marker=dict(color=\"#1b7656\"),\n", + " ),\n", + " secondary_y=False,\n", + " )\n", + " fig.add_trace(\n", + " go.Bar(\n", + " name=\"Décaissement\",\n", + " x=df_cashout[\"LABEL\"],\n", + " y=df_cashout[\"VALUE\"] * -1,\n", + " marker=dict(color=\"#cd3244\"),\n", + " ),\n", + " secondary_y=False,\n", + " )\n", + " fig.add_trace(\n", + " go.Scatter(\n", + " x=df_position[\"LABEL\"],\n", + " y=df_position[\"VALUE\"],\n", + " mode=\"lines\",\n", + " line=dict(color=\"#46a7f5\", width=2.5),\n", + " ),\n", + " secondary_y=True,\n", + " )\n", + " # Add logo\n", + " fig.add_layout_image(\n", + " dict(\n", + " source=logo,\n", + " xref=\"paper\",\n", + " yref=\"paper\",\n", + " x=0.01,\n", + " y=1.05,\n", + " sizex=0.12,\n", + " sizey=0.12,\n", + " xanchor=\"right\",\n", + " yanchor=\"bottom\",\n", + " )\n", + " )\n", + "\n", + " # Add figure title\n", + " fig.update_layout(\n", + " title=title_full,\n", + " title_x=0.09,\n", + " title_font=dict(family=\"Arial\", color=\"black\"),\n", + " paper_bgcolor=\"#ffffff\",\n", + " plot_bgcolor=\"#ffffff\",\n", + " legend=None,\n", + " margin_pad=10,\n", + " margin_r=10,\n", + " width=1200,\n", + " height=600,\n", + " xaxis_title=xaxis_title,\n", + " xaxis_title_font=dict(family=\"Arial\", size=12, color=\"black\"),\n", + " xaxis={\"type\": \"category\"},\n", + " )\n", + "\n", + " # Set y-axes titles\n", + " fig.update_yaxes(\n", + " title_text=yaxis_title_r,\n", + " title_font=dict(family=\"Arial\", size=12, color=\"black\"),\n", + " secondary_y=False,\n", + " )\n", + " fig.update_yaxes(\n", + " title_text=yaxis_title_l,\n", + " title_font=dict(family=\"Arial\", size=12, color=\"black\"),\n", + " secondary_y=True,\n", + " )\n", + " fig.update_traces(showlegend=False)\n", + " fig.show()\n", + " return fig\n", + "\n", + "\n", + "fig = create_barlinechart(\n", + " df_cashin,\n", + " df_cashout,\n", + " df_position,\n", + " xaxis_title=None,\n", + " yaxis_title_r=\"Flows\",\n", + " yaxis_title_l=\"Position\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "lonely-pacific", + "metadata": { + "execution": { + "iopub.execute_input": "2021-07-02T23:32:10.789097Z", + "iopub.status.busy": "2021-07-02T23:32:10.788829Z", + "iopub.status.idle": "2021-07-02T23:32:10.796900Z", + "shell.execute_reply": "2021-07-02T23:32:10.796358Z", + "shell.execute_reply.started": "2021-07-02T23:32:10.789033Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "87c9da68-5ca9-4294-b44d-f2514cce77ef", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your csv file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "438645b6-1c1f-4725-9649-5b9f0fdb8da9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# # Save your dataframe in CSV\n", + "# df_trend.to_csv(csv_output, index=False)" + ] + }, + { + "cell_type": "markdown", + "id": "2748d1c8-1fdc-4e73-837d-61f24080227f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your graph in HTML\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1721bf1f-c2a9-4111-802a-6d03203ac6ba", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Save your graph in HTML\n", + "fig.write_html(html_output)\n", + "\n", + "# Share output with naas\n", + "html_link = naas.asset.add(html_output, override_prod=True, params={\"inline\": True})\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete(html_output)" + ] + }, + { + "cell_type": "markdown", + "id": "6d05d5bf-e745-4392-9603-d10b8314cdf5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your graph in image\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f51a9529-41fe-4236-9023-b13c1e0cce6b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Save your graph in PNG\n", + "fig.write_image(image_output)\n", + "\n", + "# Share output with naas\n", + "image_link = naas.asset.add(image_output, override_prod=True, params={\"inline\": True})\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete(image_output)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "d73ae271b1557432c42c76c41c62f94628dd97120e11e41b0f1c0f0eee97a9c5", + "notebook_path": "FEC/FEC_Visualiser_Trésorerie_Barline_Chart.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.3" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/models/growth-engine/__plugin__.ipynb b/models/growth-engine/__plugin__.ipynb index 2584668..1a9a52e 100644 --- a/models/growth-engine/__plugin__.ipynb +++ b/models/growth-engine/__plugin__.ipynb @@ -144,7 +144,7 @@ "name = \"🚀 Growth Assistant\"\n", "model = \"gpt-4-1106-preview\"\n", "temperature = 0.5\n", - "description = \"Track your growth performance, understand your audience with cohorts analysis and meet your new marketing qualified leads.\"\n", + "description = \"Analyze content engagement, identifying potential leads through social media engagement, scoring interactions, and enriching profiles for targeted sales outreach.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"growth-engine\")\n", "\n", diff --git a/models/opendata-engine/__plugin__.ipynb b/models/opendata-engine/__plugin__.ipynb index a029f09..6044731 100644 --- a/models/opendata-engine/__plugin__.ipynb +++ b/models/opendata-engine/__plugin__.ipynb @@ -137,9 +137,9 @@ "Your role is to help people follow the portfolio of indicators that makes sense for them.\n", "Start by presenting yourself.\n", "\"\"\"\n", - "model = \"gpt-3.5-turbo-16k\"\n", + "model = \"gpt-4-1106-preview\"\n", "temperature = 0\n", - "description = \"This plugin is used to setup the Open Data Engine\"\n", + "description = \"Harness external data for enriching business intelligence and supporting strategic adaptation.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"opendata-engine\")\n", "\n", diff --git a/models/opendata-engine/core/domain/Matplotlib_Create_content_world_cloud.ipynb b/models/opendata-engine/core/domain/Matplotlib_Create_content_world_cloud.ipynb new file mode 100644 index 0000000..2d70893 --- /dev/null +++ b/models/opendata-engine/core/domain/Matplotlib_Create_content_world_cloud.ipynb @@ -0,0 +1,347 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e46cda1e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Matplotlib.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "b0d4ced6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Matplotlib - Create content world cloud" + ] + }, + { + "cell_type": "markdown", + "id": "06cb7cb7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #linkedin #worldcloud #content #analytics #dependency" + ] + }, + { + "cell_type": "markdown", + "id": "c64eee3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "694879b8-e278-423d-bc29-2373efbff404", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook demonstrates how to create a word cloud using Matplotlib. It provides a step-by-step guide on how to generate a word cloud from a given text data, which is a popular way to visualize high-frequency words in a dataset. The result is a word cloud image that visualizes the frequency of words in the given text data. The size of each word in the image corresponds to its frequency in the text data." + ] + }, + { + "cell_type": "markdown", + "id": "f65cd676", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "428474ab", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6214ae90", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "try:\n", + " from wordcloud import WordCloud\n", + "except:\n", + " !pip install wordcloud --user\n", + " from wordcloud import WordCloud\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd\n", + "import os\n", + "from datetime import date, datetime, timedelta\n", + "import naas_data_product\n", + "from naas_drivers import gsheet" + ] + }, + { + "cell_type": "markdown", + "id": "b4c94227-a6d1-41ac-9126-a84bced89012", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Inputs**\n", + "- `entity_dir`: Entity directory.\n", + "- `entity_name`: Entity name.\n", + "- `input_dir`: Input directory to retrieve file from.\n", + "- `input_file`: Input file.\n", + "- `spreadsheet_url`: Google Sheets spreadsheet URL.\n", + "- `sheet_name`: Google Sheets sheet name.\n", + "- `title`: Graph title.\n", + "\n", + "**Outputs**\n", + "- `output_dir`: This variable is used for storing the path to the directory where the output files will be saved." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "190b8d21", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Inputs\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_dir\")\n", + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_name\")\n", + "input_dir = os.path.join(entity_dir, \"opendata-engine\", date.today().isoformat())\n", + "input_file = \"opendata\"\n", + "spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"abi_spreadsheet\")\n", + "sheet_name = \"EVENTS\"\n", + "column_text = \"CONTENT\"\n", + "\n", + "# Outputs\n", + "output_dir = os.path.join(entity_dir, \"opendata-engine\", date.today().isoformat())\n", + "os.makedirs(output_dir, exist_ok=True)\n", + "output_name = \"opendata_worldcloud\"" + ] + }, + { + "cell_type": "markdown", + "id": "b3566c94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "294a8bb7-84cf-4767-8398-dc1e1bad046c", + "metadata": {}, + "source": [ + "### Set outputs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c60b9e8b-78b3-4b3e-8004-ba8d0b2721d7", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "image_output = os.path.join(output_dir, f\"{output_name}.png\")" + ] + }, + { + "cell_type": "markdown", + "id": "ba2000df", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get data from spreadsheet" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13a489d5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df_init = gsheet.connect(spreadsheet_url).get(sheet_name=sheet_name)\n", + "print(\"- Data fetched:\", len(df_init))\n", + "df_init.head(1)" + ] + }, + { + "cell_type": "markdown", + "id": "7456a048", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Extract text from CONTENT" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22b41e65", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Creating the text variable\n", + "text = \" \".join(text for text in df_init.astype(str)[column_text])\n", + "# text" + ] + }, + { + "cell_type": "markdown", + "id": "4d76ebbf-beae-4671-960c-3950cec63400", + "metadata": {}, + "source": [ + "### Create worldcloud" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c21e9add-8dab-4030-b3dd-d2d13f2c3ccd", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Creating word_cloud with text as argument in .generate() method\n", + "wordcloud = WordCloud(\n", + " collocations=False,\n", + " background_color=\"white\",\n", + " width=1200,\n", + " height=600\n", + ").generate(remove_emojis(text))\n", + "\n", + "# Display the generated image\n", + "plt.imshow(wordcloud, interpolation=\"bilinear\")\n", + "plt.axis(\"off\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "c8083216", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "91a987c6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your graph in image\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8342abf9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Save your image in PNG\n", + "wordcloud.to_file(image_output)\n", + "\n", + "# Share output with naas\n", + "naas.asset.add(image_output)\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete(image_output)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9cbe797a-0ec7-4abe-acc6-db5e7ad189fb", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "11b2c07be26f4a540e850f376dd2cfffa6b41699fbb48e33fd0a5eecd9155e20", + "notebook_path": "LinkedIn/LinkedIn_Extract_content_world_cloud.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/models/operations-engine/__plugin__.ipynb b/models/operations-engine/__plugin__.ipynb index eb83e53..fe318a4 100644 --- a/models/operations-engine/__plugin__.ipynb +++ b/models/operations-engine/__plugin__.ipynb @@ -141,7 +141,7 @@ "\"\"\"\n", "model = \"gpt-3.5-turbo-16k\"\n", "temperature = 0\n", - "description = \"This plugin is used to setup the Operations Engine\"\n", + "description = \"Automate and optimize operational tasks and meeting management, ensuring enhanced efficiency and streamlined workflows.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"operations-engine\")\n", "\n", diff --git a/models/operations-engine/core/domain/Plotly_Follow_meetings_and_tasks.ipynb b/models/operations-engine/core/domain/Plotly_Follow_meetings_and_tasks.ipynb new file mode 100644 index 0000000..fc1b5cf --- /dev/null +++ b/models/operations-engine/core/domain/Plotly_Follow_meetings_and_tasks.ipynb @@ -0,0 +1,541 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "35673cb3-a65e-4e94-a60b-8b3863fd455b", + "metadata": { + "execution": { + "iopub.execute_input": "2021-02-23T14:22:16.610471Z", + "iopub.status.busy": "2021-02-23T14:22:16.610129Z", + "iopub.status.idle": "2021-02-23T14:22:16.627784Z", + "shell.execute_reply": "2021-02-23T14:22:16.626866Z", + "shell.execute_reply.started": "2021-02-23T14:22:16.610384Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Plotly.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "b0d4ced6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Plotly - Follow meetings and tasks" + ] + }, + { + "cell_type": "markdown", + "id": "06cb7cb7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #plotly #html #csv #image #operations #analytics #meetings #tasks #metric" + ] + }, + { + "cell_type": "markdown", + "id": "c64eee3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook creates a barchart graph tracking your daily meetings and tasks over the past two weeks." + ] + }, + { + "cell_type": "markdown", + "id": "f65cd676", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "428474ab", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6214ae90", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import plotly.graph_objects as go\n", + "from naas_drivers import gsheet\n", + "import pandas as pd\n", + "import os\n", + "from datetime import date, datetime, timedelta\n", + "import naas_data_product\n", + "import random" + ] + }, + { + "cell_type": "markdown", + "id": "5ed1bed1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Inputs**\n", + "- `entity_dir`: Entity directory.\n", + "- `entity_name`: Entity name.\n", + "- `input_dir`: Input directory to retrieve file from.\n", + "- `input_file`: Input file.\n", + "- `spreadsheet_url`: Google Sheets spreadsheet URL.\n", + "- `sheet_name`: Google Sheets sheet name.\n", + "- `title`: Graph title.\n", + "\n", + "**Outputs**\n", + "- `output_dir`: This variable is used for storing the path to the directory where the output files will be saved." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "190b8d21", + "metadata": { + "papermill": {}, + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "# Inputs\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_dir\")\n", + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_name\")\n", + "input_dir = os.path.join(entity_dir, \"operations-engine\", date.today().isoformat())\n", + "input_file = \"meetings\"\n", + "input_file2 = \"tasks\"\n", + "spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"abi_spreadsheet\")\n", + "sheet_name = \"MEETINGS\"\n", + "sheet_name2 = \"TASKS\"\n", + "title = \"Ops\"\n", + "\n", + "# Outputs\n", + "output_dir = os.path.join(entity_dir, \"operations-engine\", date.today().isoformat())\n", + "os.makedirs(output_dir, exist_ok=True)\n", + "output_name = \"ops_trend\"" + ] + }, + { + "cell_type": "markdown", + "id": "b3566c94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "f306feb8-0889-44c5-bb0a-99e74fdd729d", + "metadata": {}, + "source": [ + "### Set outputs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a6f8da1-d66e-4f21-8d5f-56d67924895c", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "html_output = os.path.join(output_dir, f\"{output_name}.html\")\n", + "image_output = os.path.join(output_dir, f\"{output_name}.png\")" + ] + }, + { + "cell_type": "markdown", + "id": "2c6dbd38-52a8-4af8-aef9-f1d6551e06ef", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get input data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4ce220d-952b-4321-aed6-e1b3afe63ab8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "DATE_FORMAT = \"%Y-%m-%d\"\n", + "PERIOD = \"%Y-%m-%d\"\n", + "PERIOD_TEXT = \"This day\"\n", + "\n", + "data1 = {\n", + " \"ENTITY\": [\"Abi\"] * 10,\n", + " \"SCENARIO\": [\"W03-2024\"] * 5 + [\"W04-2024\"] * 5,\n", + " \"LABEL\": [\n", + " \"2024-02-12\",\n", + " \"2024-02-13\",\n", + " \"2024-02-14\",\n", + " \"2024-02-15\",\n", + " \"2024-02-16\",\n", + " \"2024-02-19\",\n", + " \"2024-02-20\",\n", + " \"2024-02-21\",\n", + " \"2024-02-22\",\n", + " \"2024-02-23\",\n", + " ],\n", + " \"GROUP\": [\"Meetings\"] * 10,\n", + " \"VALUE\": [random.randint(0, 5) for i in range(0, 10)],\n", + "}\n", + "df1 = pd.DataFrame(data1)\n", + "\n", + "data2 = {\n", + " \"ENTITY\": [\"Abi\"] * 10,\n", + " \"SCENARIO\": [\"W03-2024\"] * 5 + [\"W04-2024\"] * 5,\n", + " \"LABEL\": [\n", + " \"2024-02-12\",\n", + " \"2024-02-13\",\n", + " \"2024-02-14\",\n", + " \"2024-02-15\",\n", + " \"2024-02-16\",\n", + " \"2024-02-19\",\n", + " \"2024-02-20\",\n", + " \"2024-02-21\",\n", + " \"2024-02-22\",\n", + " \"2024-02-23\",\n", + " ],\n", + " \"GROUP\": [\"Tasks\"] * 10,\n", + " \"VALUE\": [random.randint(0, 10) for i in range(0, 10)],\n", + "}\n", + "df2 = pd.DataFrame(data2)\n", + "df_trend = pd.concat([df1, df2])\n", + "df_trend[\"LABEL_D\"] = pd.to_datetime(df_trend[\"LABEL\"], format=PERIOD).dt.strftime(\"%a %d %b\")\n", + "df_trend[\"COLOR\"] = df_trend[\"GROUP\"].map({\"Meetings\": \"grey\", \"Tasks\": \"lightgrey\"})\n", + "df_trend" + ] + }, + { + "cell_type": "markdown", + "id": "91e37140-3961-4ef7-ab6e-a8af744e8e8b", + "metadata": {}, + "source": [ + "### Create title and logo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ddb389e1-2919-4036-ba30-5e0302b6a933", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def get_kpis(df):\n", + " # Groupby weeks\n", + " if len(df) > 0 and \"SCENARIO\" in df.columns:\n", + " df = df.groupby([\"SCENARIO\"], as_index=False).agg({\"VALUE\": \"sum\"})\n", + "\n", + " # Get total and total n-1\n", + " if len(df) == 0:\n", + " total = 0\n", + " total_n1 = 0\n", + " elif len(df) == 1:\n", + " if df.loc[0, \"SCENARIO\"] == TW:\n", + " total = df.loc[0, \"VALUE\"]\n", + " total_n1 = 0\n", + " else:\n", + " total = 0\n", + " total_n1 = df.loc[0, \"VALUE\"]\n", + " else:\n", + " total = df.loc[df.index[-1], \"VALUE\"]\n", + " total_n1 = df.loc[df.index[-2], \"VALUE\"]\n", + "\n", + " # Calc variation in value and pourcentage \n", + " varv = total - total_n1\n", + " if total == 0:\n", + " varp = -1\n", + " elif total_n1 == 0:\n", + " varp = 1\n", + " else:\n", + " varp = varv / total_n1\n", + "\n", + " # Create value to displayed\n", + " total_d = \"{:,.0f}\".format(total).replace(\",\", \" \")\n", + " varv_d = \"{:,.0f}\".format(varv).replace(\",\", \" \")\n", + " varp_d = \"{:,.0%}\".format(varp).replace(\",\", \" \")\n", + " if varv >= 0:\n", + " varv_d = f\"+{varv_d}\"\n", + " varp_d = f\"+{varp_d}\"\n", + " \n", + " # Logo\n", + " logo = None\n", + " if varv > 0:\n", + " logo = arrow_up\n", + " elif varv > -0.2:\n", + " logo = arrow_right\n", + " else:\n", + " logo = arrow_down\n", + " \n", + " return total_d, varv_d, varp_d, logo\n", + " \n", + "total_d, varv_d, varp_d, logo = get_kpis(df1)\n", + "total_d2, varv_d2, varp_d2, logo2 = get_kpis(df2)\n", + "title_full = f\"Meetings: {total_d} | {varv_d} ({varp_d})
Tasks: {total_d2} | {varv_d2} ({varp_d2})\"\n", + "print(\"Title:\", title_full)" + ] + }, + { + "cell_type": "markdown", + "id": "7456a048", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create trend dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22b41e65", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def create_barchart(df, label, groups, value, title):\n", + " fig = go.Figure()\n", + "\n", + " list_groups = df[groups].unique()\n", + " for group in list_groups:\n", + " tmp_df = df[df[groups] == group]\n", + " fig.add_trace(go.Bar(x=tmp_df[label], y=tmp_df[value], name=group, marker=dict(color=tmp_df[\"COLOR\"]),))\n", + " \n", + " # Add logo\n", + " fig.add_layout_image(\n", + " dict(\n", + " source=logo,\n", + " xref=\"paper\",\n", + " yref=\"paper\",\n", + " x=0.01,\n", + " y=1.05,\n", + " sizex=0.12,\n", + " sizey=0.12,\n", + " xanchor=\"right\",\n", + " yanchor=\"bottom\",\n", + " )\n", + " )\n", + " # Add legend\n", + " fig.update_layout(\n", + " legend=dict(\n", + " orientation=\"h\",\n", + " yanchor=\"bottom\",\n", + " y=-0.2,\n", + " xanchor=\"center\",\n", + " x=0.5\n", + " )\n", + " )\n", + " \n", + " # Update layout\n", + " fig.update_layout(\n", + " title=title_full,\n", + " title_x=0.09,\n", + " title_font=dict(family=\"Arial\", color=\"black\"),\n", + " paper_bgcolor=\"#ffffff\",\n", + " plot_bgcolor=\"#ffffff\",\n", + " width=1200,\n", + " height=600,\n", + " xaxis_tickfont_size=14,\n", + " legend=dict(bgcolor=\"white\", bordercolor=\"white\"),\n", + " barmode=\"group\",\n", + " bargap=0.1, # gap between bars of adjacent location coordinates.\n", + " bargroupgap=0.1, # gap between bars of the same location coordinate.\n", + " )\n", + " config = {\"displayModeBar\": False}\n", + " fig.show(config=config)\n", + " return fig\n", + "\n", + "fig = create_barchart(df_trend, label=\"LABEL_D\", groups=\"GROUP\", value=\"VALUE\", title=title)" + ] + }, + { + "cell_type": "markdown", + "id": "c8083216", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "541e16a0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your csv file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "61cc88bf", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "pdump(output_dir, df_trend, output_name)" + ] + }, + { + "cell_type": "markdown", + "id": "d28cd477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your graph in HTML\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3421d37f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Save your graph in HTML\n", + "fig.write_html(html_output)\n", + "\n", + "# Share output with naas\n", + "html_link = naas.asset.add(html_output, override_prod=True, params={\"inline\": True})\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete(html_output)" + ] + }, + { + "cell_type": "markdown", + "id": "91a987c6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save and share your graph in image\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8342abf9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Save your graph in PNG\n", + "fig.write_image(image_output)\n", + "\n", + "# Share output with naas\n", + "image_link = naas.asset.add(image_output, override_prod=True, params={\"inline\": True})\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete(image_output)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b99cbc5e-25ab-4e47-9ed1-d9637719d951", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/models/sales-engine/__plugin__.ipynb b/models/sales-engine/__plugin__.ipynb index 778c487..8c24911 100644 --- a/models/sales-engine/__plugin__.ipynb +++ b/models/sales-engine/__plugin__.ipynb @@ -144,7 +144,7 @@ "name = \"⚡️ Sales Assistant\"\n", "model = \"gpt-4-1106-preview\"\n", "temperature = 0.2\n", - "description = \"Nurture your sales qualified leads and ensure they progress through the sales pipeline effectively.\"\n", + "description = \"Manage and facilitate the sales process from lead generation to deal closure.\"\n", "avatar = \"\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"sales-engine\")\n", "input_image = \"deals_trend.png\"\n",