diff --git a/README.md b/README.md index ceb2aa0..4433a65 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ bob.initialize( ### Using custom endpoints -Custom endpoints can be used as well if they support the OpenAI API. Examples are [blablador](https://login.helmholtz.de/oauth2-as/oauth2-authz-web-entry) and [ollama](https://ollama.com/). +Custom endpoints can be used as well if they support the OpenAI API. Examples are [DeepSeek](https://www.deepseek.com/), [KISSKI](https://kisski.gwdg.de/leistungen/2-02-llm-service/), [blablador](https://login.helmholtz.de/oauth2-as/oauth2-authz-web-entry) and [ollama](https://ollama.com/). An example is shown in [this notebook](https://github.com/haesleinhuepf/bia-bob/blob/main/demo/custom_endpoints.ipynb): For this, just install the openai backend as explained above (tested version: 1.5.0). @@ -267,6 +267,11 @@ For this, just install the openai backend as explained above (tested version: 1. ``` bob.initialize(endpoint='ollama', model='codellama') ``` +* For using DeepSeek, you need to get an [API key](https://platform.deepseek.com/api_keys). Store it in your environment as `DEEPSEEK_API_KEY` variable. +``` +bob.initialize(endpoint='deepseek', model='deepseek-chat') +``` + * If you want to use blablador, which is free for German academics, just get an API key as explained on [this page](https://sdlaml.pages.jsc.fz-juelich.de/ai/guides/blablador_api_access/) and store it in your environment as `BLABLADOR_API_KEY` variable. ``` diff --git a/demo/deepseek.ipynb b/demo/deepseek.ipynb new file mode 100644 index 0000000..50d85f3 --- /dev/null +++ b/demo/deepseek.ipynb @@ -0,0 +1,165 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "0200083e-efe2-4c2d-826b-035e9a5d2085", + "metadata": {}, + "outputs": [], + "source": [ + "from bia_bob import bob" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d69f33c5-3a76-4f54-ada9-2a50c51d0816", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + " This notebook may contain text, code and images generated by artificial intelligence.\n", + " Used model: deepseek-chat, vision model: None, endpoint: https://api.deepseek.com, bia-bob version: 0.25.1.. Do not enter sensitive or private information and verify generated contents according to good scientific practice. Read more: https://github.com/haesleinhuepf/bia-bob#disclaimer\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "bob.initialize(endpoint='deepseek', model='deepseek-chat')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a49ce700-7c8e-499f-be36-d6d9a15eb150", + "metadata": {}, + "outputs": [], + "source": [ + "%%bob \n", + "* load blobs.tif\n", + "* segment and label the individual objects\n", + "* measure their area\n", + "* color-code the objects with the area\n", + "* show the result" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e9fbe37f-d085-4b75-a1ca-3ad69d4f8d5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
shape(254, 256)
dtypefloat32
size254.0 kB
min0.0
max1.0
\n", + "\n", + "
" + ], + "text/plain": [ + "StackViewNDArray([[0.03218646, 0.03218646, 0.03218646, ..., 0.19311875,\n", + " 0.19311875, 0.19311875],\n", + " [0.03218646, 0.03218646, 0.03218646, ..., 0.19311875,\n", + " 0.19311875, 0.19311875],\n", + " [0.03218646, 0.03218646, 0.03218646, ..., 0.19311875,\n", + " 0.19311875, 0.19311875],\n", + " ...,\n", + " [0.03218646, 0.03218646, 0.03218646, ..., 0.03218646,\n", + " 0.03218646, 0.03218646],\n", + " [0.03218646, 0.03218646, 0.03218646, ..., 0.03218646,\n", + " 0.03218646, 0.03218646],\n", + " [0.03218646, 0.03218646, 0.03218646, ..., 0.03218646,\n", + " 0.03218646, 0.03218646]], dtype=float32)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from skimage.io import imread\n", + "from skimage.measure import label, regionprops_table\n", + "import pandas as pd\n", + "import numpy as np\n", + "import stackview\n", + "import pyclesperanto_prototype as cle\n", + "\n", + "# 1. Load the image\n", + "image = imread(\"blobs.tif\")\n", + "\n", + "# 2. Segment the image using Otsu's thresholding\n", + "binary_image = cle.threshold_otsu(image)\n", + "\n", + "# 3. Label the segmented objects\n", + "label_image = cle.connected_components_labeling_box(binary_image)\n", + "\n", + "# 4. Measure the area of each labeled object\n", + "properties = ['label', 'area']\n", + "measurements = regionprops_table(label_image, properties=properties)\n", + "df = pd.DataFrame(measurements)\n", + "\n", + "# 5. Color-code the labeled objects based on their area\n", + "area_values = df['area'].values\n", + "area_values_normalized = (area_values - area_values.min()) / (area_values.max() - area_values.min())\n", + "colored_labels = cle.replace_intensities(label_image, area_values_normalized)\n", + "\n", + "# 6. Display the color-coded result\n", + "stackview.insight(colored_labels)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da8c47c9-95a6-4540-9dbe-aeffc7f8efe0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/bia_bob/__init__.py b/src/bia_bob/__init__.py index ef392ad..a407354 100644 --- a/src/bia_bob/__init__.py +++ b/src/bia_bob/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.25.1" +__version__ = "0.25.2" __all__ = ( ) diff --git a/src/bia_bob/_machinery.py b/src/bia_bob/_machinery.py index da39207..8137cd4 100644 --- a/src/bia_bob/_machinery.py +++ b/src/bia_bob/_machinery.py @@ -6,6 +6,7 @@ BLABLADOR_BASE_URL = 'https://helmholtz-blablador.fz-juelich.de:8000/v1' OLLAMA_BASE_URL = 'http://localhost:11434/v1' AZURE_BASE_URL = "https://models.inference.ai.azure.com" +DEEPSEEK_BASE_URL = "https://api.deepseek.com" class Context: diff --git a/src/bia_bob/_utilities.py b/src/bia_bob/_utilities.py index 81f4218..525a32a 100644 --- a/src/bia_bob/_utilities.py +++ b/src/bia_bob/_utilities.py @@ -444,11 +444,15 @@ def is_image(potential_image): def correct_endpoint(endpoint, api_key): import os - from ._machinery import BLABLADOR_BASE_URL, OLLAMA_BASE_URL, AZURE_BASE_URL + from ._machinery import BLABLADOR_BASE_URL, OLLAMA_BASE_URL, AZURE_BASE_URL, DEEPSEEK_BASE_URL if endpoint == 'blablador': endpoint = BLABLADOR_BASE_URL if api_key is None: api_key = os.environ.get('BLABLADOR_API_KEY') + elif endpoint == 'deepseek': + endpoint = DEEPSEEK_BASE_URL + if api_key is None: + api_key = os.environ.get('DEEPSEEK_API_KEY') elif endpoint == 'ollama': endpoint = OLLAMA_BASE_URL elif endpoint == "azure":