{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/kask/miniconda3/envs/innovatie-week/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from transformers import AutoProcessor, AutoModelForVision2Seq\n", "from transformers.image_utils import load_image\n", "import numpy as np\n", "import gradio as gr\n", "import torch\n", "from PIL import Image" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cpu\n" ] } ], "source": [ "# Set the device (GPU or CPU)\n", "DEVICE = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", "print(DEVICE)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Some kwargs in processor config are unused and will not have any effect: image_seq_len. \n" ] }, { "ename": "", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n", "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n", "\u001b[1;31mClick here for more info. \n", "\u001b[1;31mView Jupyter log for further details." ] } ], "source": [ "# Initialize processor and model\n", "try:\n", " processor = AutoProcessor.from_pretrained(\"HuggingFaceTB/SmolVLM-Instruct\")\n", " model = AutoModelForVision2Seq.from_pretrained(\n", " \"HuggingFaceTB/SmolVLM-Instruct\",\n", " torch_dtype=torch.bfloat16,\n", " _attn_implementation=\"flash_attention_2\" if DEVICE == \"cuda\" else \"eager\",).to(DEVICE)\n", "except Exception as e:\n", " print(f\"Error loading model or processor: {str(e)}\")\n", " exit(1)" ] } ], "metadata": { "kernelspec": { "display_name": "innovatie-week", "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.12.1" } }, "nbformat": 4, "nbformat_minor": 2 }