{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"gpuType":"T4","authorship_tag":"ABX9TyNGW7SKhuYSWVy08d6N46tj"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU"},"cells":[{"cell_type":"markdown","source":["# Install and Preparation..."],"metadata":{"id":"8oJW8II0V30G"}},{"cell_type":"code","source":["!pip install gcsfs==2023.6.0\n","!pip install fsspec==2023.6.0"],"metadata":{"collapsed":true,"id":"kufKx-VMEFWN","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1731433831603,"user_tz":-480,"elapsed":6923,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}},"outputId":"21151377-3bda-44c8-8189-79d86af1898d"},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: gcsfs==2023.6.0 in /usr/local/lib/python3.10/dist-packages (2023.6.0)\n","Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (3.10.10)\n","Requirement already satisfied: decorator>4.1.2 in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (4.4.2)\n","Requirement already satisfied: fsspec==2023.6.0 in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (2023.6.0)\n","Requirement already satisfied: google-auth>=1.2 in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (2.27.0)\n","Requirement already satisfied: google-auth-oauthlib in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (1.2.1)\n","Requirement already satisfied: google-cloud-storage in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (2.8.0)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from gcsfs==2023.6.0) (2.32.3)\n","Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (2.4.3)\n","Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (1.3.1)\n","Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (24.2.0)\n","Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (1.5.0)\n","Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (6.1.0)\n","Requirement already satisfied: yarl<2.0,>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (1.17.1)\n","Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (4.0.3)\n","Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth>=1.2->gcsfs==2023.6.0) (5.5.0)\n","Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth>=1.2->gcsfs==2023.6.0) (0.4.1)\n","Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth>=1.2->gcsfs==2023.6.0) (4.9)\n","Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib->gcsfs==2023.6.0) (1.3.1)\n","Requirement already satisfied: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5 in /usr/local/lib/python3.10/dist-packages (from google-cloud-storage->gcsfs==2023.6.0) (2.19.2)\n","Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from google-cloud-storage->gcsfs==2023.6.0) (2.4.1)\n","Requirement already satisfied: google-resumable-media>=2.3.2 in /usr/local/lib/python3.10/dist-packages (from google-cloud-storage->gcsfs==2023.6.0) (2.7.2)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->gcsfs==2023.6.0) (3.4.0)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->gcsfs==2023.6.0) (3.10)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->gcsfs==2023.6.0) (2.2.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->gcsfs==2023.6.0) (2024.8.30)\n","Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5->google-cloud-storage->gcsfs==2023.6.0) (1.65.0)\n","Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in /usr/local/lib/python3.10/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5->google-cloud-storage->gcsfs==2023.6.0) (4.25.5)\n","Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in /usr/local/lib/python3.10/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5->google-cloud-storage->gcsfs==2023.6.0) (1.25.0)\n","Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in /usr/local/lib/python3.10/dist-packages (from google-resumable-media>=2.3.2->google-cloud-storage->gcsfs==2023.6.0) (1.6.0)\n","Requirement already satisfied: typing-extensions>=4.1.0 in /usr/local/lib/python3.10/dist-packages (from multidict<7.0,>=4.5->aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (4.12.2)\n","Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth>=1.2->gcsfs==2023.6.0) (0.6.1)\n","Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib->gcsfs==2023.6.0) (3.2.2)\n","Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from yarl<2.0,>=1.12.0->aiohttp!=4.0.0a0,!=4.0.0a1->gcsfs==2023.6.0) (0.2.0)\n","Requirement already satisfied: fsspec==2023.6.0 in /usr/local/lib/python3.10/dist-packages (2023.6.0)\n"]}]},{"cell_type":"code","execution_count":12,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"LWcXtsQwC7mj","executionInfo":{"status":"ok","timestamp":1731433869008,"user_tz":-480,"elapsed":37412,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}},"outputId":"bb202204-0107-402b-9ce4-7e120470aba8"},"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (5.5.0)\n","Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n","Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n","Requirement already satisfied: fastapi<1.0,>=0.115.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.115.5)\n","Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.4.0)\n","Requirement already satisfied: gradio-client==1.4.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.4.2)\n","Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.27.2)\n","Requirement already satisfied: huggingface-hub>=0.25.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.26.2)\n","Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.4)\n","Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n","Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.26.4)\n","Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.10.11)\n","Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (24.2)\n","Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.2.2)\n","Requirement already satisfied: pillow<12.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (11.0.0)\n","Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.9.2)\n","Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n","Requirement already satisfied: python-multipart==0.0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.12)\n","Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.2)\n","Requirement already satisfied: ruff>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.7.3)\n","Requirement already satisfied: safehttpx<1.0,>=0.1.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.1.1)\n","Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n","Requirement already satisfied: starlette<1.0,>=0.40.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.41.2)\n","Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n","Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.13.0)\n","Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.12.2)\n","Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.32.0)\n","Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.4.2->gradio) (2023.6.0)\n","Requirement already satisfied: websockets<13.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.4.2->gradio) (12.0)\n","Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (3.10)\n","Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n","Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.2.2)\n","Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2024.8.30)\n","Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.0.6)\n","Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.25.1->gradio) (3.16.1)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.25.1->gradio) (2.32.3)\n","Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.25.1->gradio) (4.66.6)\n","Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2.8.2)\n","Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.2)\n","Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.2)\n","Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.7.0)\n","Requirement already satisfied: pydantic-core==2.23.4 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.23.4)\n","Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n","Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n","Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (13.9.4)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.16.0)\n","Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n","Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.25.1->gradio) (3.4.0)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.25.1->gradio) (2.2.3)\n","Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n","Requirement already satisfied: sentence-transformers==2.2.2 in /usr/local/lib/python3.10/dist-packages (2.2.2)\n","Requirement already satisfied: transformers<5.0.0,>=4.6.0 in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (4.25.1)\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (4.66.6)\n","Requirement already satisfied: torch>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (2.5.0+cu121)\n","Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (0.20.0+cu121)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (1.26.4)\n","Requirement already satisfied: scikit-learn in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (1.5.2)\n","Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (1.13.1)\n","Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (3.9.1)\n","Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (0.2.0)\n","Requirement already satisfied: huggingface-hub>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from sentence-transformers==2.2.2) (0.26.2)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (3.16.1)\n","Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (2023.6.0)\n","Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (24.2)\n","Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (6.0.2)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (2.32.3)\n","Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (4.12.2)\n","Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->sentence-transformers==2.2.2) (3.4.2)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->sentence-transformers==2.2.2) (3.1.4)\n","Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->sentence-transformers==2.2.2) (1.13.1)\n","Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch>=1.6.0->sentence-transformers==2.2.2) (1.3.0)\n","Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.6.0->sentence-transformers==2.2.2) (2024.9.11)\n","Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.6.0->sentence-transformers==2.2.2) (0.13.3)\n","Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk->sentence-transformers==2.2.2) (8.1.7)\n","Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk->sentence-transformers==2.2.2) (1.4.2)\n","Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->sentence-transformers==2.2.2) (3.5.0)\n","Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.10/dist-packages (from torchvision->sentence-transformers==2.2.2) (11.0.0)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.6.0->sentence-transformers==2.2.2) (2.1.5)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (3.4.0)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (3.10)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (2.2.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.4.0->sentence-transformers==2.2.2) (2024.8.30)\n","Requirement already satisfied: transformers==4.25.1 in /usr/local/lib/python3.10/dist-packages (4.25.1)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (3.16.1)\n","Requirement already satisfied: huggingface-hub<1.0,>=0.10.0 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (0.26.2)\n","Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (1.26.4)\n","Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (24.2)\n","Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (6.0.2)\n","Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (2024.9.11)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (2.32.3)\n","Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (0.13.3)\n","Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers==4.25.1) (4.66.6)\n","Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.10.0->transformers==4.25.1) (2023.6.0)\n","Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.10.0->transformers==4.25.1) (4.12.2)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers==4.25.1) (3.4.0)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers==4.25.1) (3.10)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers==4.25.1) (2.2.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers==4.25.1) (2024.8.30)\n","Requirement already satisfied: pytorch-lightning==1.9.0 in /usr/local/lib/python3.10/dist-packages (1.9.0)\n","Requirement already satisfied: numpy>=1.17.2 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (1.26.4)\n","Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (2.5.0+cu121)\n","Requirement already satisfied: tqdm>=4.57.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (4.66.6)\n","Requirement already satisfied: PyYAML>=5.4 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (6.0.2)\n","Requirement already satisfied: fsspec>2021.06.0 in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (2023.6.0)\n","Requirement already satisfied: torchmetrics>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (1.5.2)\n","Requirement already satisfied: packaging>=17.1 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (24.2)\n","Requirement already satisfied: typing-extensions>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (4.12.2)\n","Requirement already satisfied: lightning-utilities>=0.4.2 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning==1.9.0) (0.11.8)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (2.32.3)\n","Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (3.10.10)\n","Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from lightning-utilities>=0.4.2->pytorch-lightning==1.9.0) (75.1.0)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning==1.9.0) (3.16.1)\n","Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning==1.9.0) (3.4.2)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning==1.9.0) (3.1.4)\n","Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning==1.9.0) (1.13.1)\n","Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch>=1.10.0->pytorch-lightning==1.9.0) (1.3.0)\n","Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (2.4.3)\n","Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (1.3.1)\n","Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (24.2.0)\n","Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (1.5.0)\n","Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (6.1.0)\n","Requirement already satisfied: yarl<2.0,>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (1.17.1)\n","Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (4.0.3)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.10.0->pytorch-lightning==1.9.0) (2.1.5)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (3.4.0)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (3.10)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (2.2.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (2024.8.30)\n","Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from yarl<2.0,>=1.12.0->aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning==1.9.0) (0.2.0)\n","Requirement already satisfied: timm==0.5.4 in /usr/local/lib/python3.10/dist-packages (0.5.4)\n","Requirement already satisfied: torch>=1.4 in /usr/local/lib/python3.10/dist-packages (from timm==0.5.4) (2.5.0+cu121)\n","Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from timm==0.5.4) (0.20.0+cu121)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (3.16.1)\n","Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (4.12.2)\n","Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (3.4.2)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (3.1.4)\n","Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (2023.6.0)\n","Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch>=1.4->timm==0.5.4) (1.13.1)\n","Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch>=1.4->timm==0.5.4) (1.3.0)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from torchvision->timm==0.5.4) (1.26.4)\n","Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.10/dist-packages (from torchvision->timm==0.5.4) (11.0.0)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.4->timm==0.5.4) (2.1.5)\n","Requirement already satisfied: donut-python in /usr/local/lib/python3.10/dist-packages (1.0.9)\n","Requirement already satisfied: transformers>=4.11.3 in /usr/local/lib/python3.10/dist-packages (from donut-python) (4.25.1)\n","Requirement already satisfied: timm in /usr/local/lib/python3.10/dist-packages (from donut-python) (0.5.4)\n","Requirement already satisfied: datasets[vision] in /usr/local/lib/python3.10/dist-packages (from donut-python) (3.1.0)\n","Requirement already satisfied: pytorch-lightning>=1.6.4 in /usr/local/lib/python3.10/dist-packages (from donut-python) (1.9.0)\n","Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (from donut-python) (3.9.1)\n","Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/dist-packages (from donut-python) (0.2.0)\n","Requirement already satisfied: zss in /usr/local/lib/python3.10/dist-packages (from donut-python) (1.2.0)\n","Requirement already satisfied: sconf>=0.2.3 in /usr/local/lib/python3.10/dist-packages (from donut-python) (0.2.5)\n","Requirement already satisfied: numpy>=1.17.2 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (1.26.4)\n","Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (2.5.0+cu121)\n","Requirement already satisfied: tqdm>=4.57.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (4.66.6)\n","Requirement already satisfied: PyYAML>=5.4 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (6.0.2)\n","Requirement already satisfied: fsspec>2021.06.0 in /usr/local/lib/python3.10/dist-packages (from fsspec[http]>2021.06.0->pytorch-lightning>=1.6.4->donut-python) (2023.6.0)\n","Requirement already satisfied: torchmetrics>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (1.5.2)\n","Requirement already satisfied: packaging>=17.1 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (24.2)\n","Requirement already satisfied: typing-extensions>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (4.12.2)\n","Requirement already satisfied: lightning-utilities>=0.4.2 in /usr/local/lib/python3.10/dist-packages (from pytorch-lightning>=1.6.4->donut-python) (0.11.8)\n","Requirement already satisfied: ruamel.yaml in /usr/local/lib/python3.10/dist-packages (from sconf>=0.2.3->donut-python) (0.18.6)\n","Requirement already satisfied: munch in /usr/local/lib/python3.10/dist-packages (from sconf>=0.2.3->donut-python) (4.0.0)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers>=4.11.3->donut-python) (3.16.1)\n","Requirement already satisfied: huggingface-hub<1.0,>=0.10.0 in /usr/local/lib/python3.10/dist-packages (from transformers>=4.11.3->donut-python) (0.26.2)\n","Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers>=4.11.3->donut-python) (2024.9.11)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers>=4.11.3->donut-python) (2.32.3)\n","Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers>=4.11.3->donut-python) (0.13.3)\n","Requirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (17.0.0)\n","Requirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (0.3.8)\n","Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (2.2.2)\n","Requirement already satisfied: xxhash in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (3.5.0)\n","Requirement already satisfied: multiprocess<0.70.17 in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (0.70.16)\n","Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (3.10.10)\n","Requirement already satisfied: Pillow>=9.4.0 in /usr/local/lib/python3.10/dist-packages (from datasets[vision]->donut-python) (11.0.0)\n","Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk->donut-python) (8.1.7)\n","Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk->donut-python) (1.4.2)\n","Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from timm->donut-python) (0.20.0+cu121)\n","Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from zss->donut-python) (1.16.0)\n","Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (2.4.3)\n","Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (1.3.1)\n","Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (24.2.0)\n","Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (1.5.0)\n","Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (6.1.0)\n","Requirement already satisfied: yarl<2.0,>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (1.17.1)\n","Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets[vision]->donut-python) (4.0.3)\n","Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from lightning-utilities>=0.4.2->pytorch-lightning>=1.6.4->donut-python) (75.1.0)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.11.3->donut-python) (3.4.0)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.11.3->donut-python) (3.10)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.11.3->donut-python) (2.2.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.11.3->donut-python) (2024.8.30)\n","Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning>=1.6.4->donut-python) (3.4.2)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning>=1.6.4->donut-python) (3.1.4)\n","Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch>=1.10.0->pytorch-lightning>=1.6.4->donut-python) (1.13.1)\n","Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch>=1.10.0->pytorch-lightning>=1.6.4->donut-python) (1.3.0)\n","Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets[vision]->donut-python) (2.8.2)\n","Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets[vision]->donut-python) (2024.2)\n","Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets[vision]->donut-python) (2024.2)\n","Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /usr/local/lib/python3.10/dist-packages (from ruamel.yaml->sconf>=0.2.3->donut-python) (0.2.12)\n","Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from yarl<2.0,>=1.12.0->aiohttp->datasets[vision]->donut-python) (0.2.0)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.10.0->pytorch-lightning>=1.6.4->donut-python) (2.1.5)\n"]}],"source":["!pip install gradio\n","!pip install sentence-transformers==2.2.2\n","!pip install transformers==4.25.1\n","!pip install pytorch-lightning==1.9.0\n","!pip install timm==0.5.4\n","!pip install donut-python"]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')\n","%cd \"/content/drive/MyDrive/Colab Notebooks/Donut/donut/\""],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"NiKtmoiqIsuS","executionInfo":{"status":"ok","timestamp":1731433871854,"user_tz":-480,"elapsed":2853,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}},"outputId":"86a17e4d-4265-41d0-b36c-6d6503c09fe4"},"execution_count":13,"outputs":[{"output_type":"stream","name":"stdout","text":["Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n","/content/drive/MyDrive/Colab Notebooks/Donut/donut\n"]}]},{"cell_type":"code","source":["import gradio as gr\n","import argparse\n","import torch\n","from PIL import Image\n","from donut import DonutModel"],"metadata":{"id":"PnjyQXNBDmH6","executionInfo":{"status":"ok","timestamp":1731433871855,"user_tz":-480,"elapsed":19,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}}},"execution_count":14,"outputs":[]},{"cell_type":"code","source":["def demo_process(input_img):\n"," global model, task_prompt, task_name\n"," input_img = Image.fromarray(input_img)\n"," output = model.inference(image=input_img, prompt=task_prompt)[\"predictions\"][0]\n"," return output"],"metadata":{"id":"8_alWsH5UXWi","executionInfo":{"status":"ok","timestamp":1731433871855,"user_tz":-480,"elapsed":18,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}}},"execution_count":15,"outputs":[]},{"cell_type":"code","source":["parser = argparse.ArgumentParser()\n","parser.add_argument(\"--task\", type=str, default=\"Booking\")\n","parser.add_argument(\"--pretrained_path\", type=str, default=\"result/train_booking/20241112_150925\")\n","args, left_argv = parser.parse_known_args()\n","task_name = args.task\n","task_prompt = f\"\"\n","\n","model = DonutModel.from_pretrained(\"./result/train_booking/20241112_150925\")\n","if torch.cuda.is_available():\n"," model.half()\n"," device = torch.device(\"cuda\")\n"," model.to(device)\n","else:\n"," model.encoder.to(torch.bfloat16)\n","\n","model.eval()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"B1vfuxJbRWeQ","executionInfo":{"status":"ok","timestamp":1731433888326,"user_tz":-480,"elapsed":16488,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}},"outputId":"ec1e2f31-7058-45df-bb83-731ad318670d"},"execution_count":16,"outputs":[{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:399: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n"," return torch.load(checkpoint_file, map_location=\"cpu\")\n"]},{"output_type":"execute_result","data":{"text/plain":["DonutModel(\n"," (encoder): SwinEncoder(\n"," (model): SwinTransformer(\n"," (patch_embed): PatchEmbed(\n"," (proj): Conv2d(3, 128, kernel_size=(4, 4), stride=(4, 4))\n"," (norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True)\n"," )\n"," (pos_drop): Dropout(p=0.0, inplace=False)\n"," (layers): Sequential(\n"," (0): BasicLayer(\n"," dim=128, input_resolution=(320, 240), depth=2\n"," (blocks): ModuleList(\n"," (0): SwinTransformerBlock(\n"," (norm1): LayerNorm((128,), eps=1e-05, elementwise_affine=True)\n"," (attn): WindowAttention(\n"," (qkv): Linear(in_features=128, out_features=384, bias=True)\n"," (attn_drop): Dropout(p=0.0, inplace=False)\n"," (proj): Linear(in_features=128, out_features=128, bias=True)\n"," (proj_drop): Dropout(p=0.0, inplace=False)\n"," (softmax): Softmax(dim=-1)\n"," )\n"," (drop_path): Identity()\n"," (norm2): LayerNorm((128,), eps=1e-05, elementwise_affine=True)\n"," (mlp): Mlp(\n"," (fc1): Linear(in_features=128, out_features=512, bias=True)\n"," (act): GELU(approximate='none')\n"," (drop1): Dropout(p=0.0, inplace=False)\n"," (fc2): Linear(in_features=512, out_features=128, bias=True)\n"," (drop2): Dropout(p=0.0, inplace=False)\n"," )\n"," )\n"," (1): SwinTransformerBlock(\n"," (norm1): LayerNorm((128,), eps=1e-05, elementwise_affine=True)\n"," (attn): WindowAttention(\n"," (qkv): Linear(in_features=128, out_features=384, bias=True)\n"," (attn_drop): Dropout(p=0.0, inplace=False)\n"," (proj): Linear(in_features=128, out_features=128, bias=True)\n"," (proj_drop): Dropout(p=0.0, inplace=False)\n"," (softmax): Softmax(dim=-1)\n"," )\n"," (drop_path): DropPath()\n"," (norm2): LayerNorm((128,), eps=1e-05, elementwise_affine=True)\n"," (mlp): Mlp(\n"," (fc1): Linear(in_features=128, out_features=512, bias=True)\n"," (act): GELU(approximate='none')\n"," (drop1): Dropout(p=0.0, inplace=False)\n"," (fc2): Linear(in_features=512, out_features=128, bias=True)\n"," (drop2): Dropout(p=0.0, inplace=False)\n"," )\n"," )\n"," )\n"," (downsample): PatchMerging(\n"," input_resolution=(320, 240), dim=128\n"," (reduction): Linear(in_features=512, out_features=256, bias=False)\n"," (norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n"," )\n"," )\n"," (1): BasicLayer(\n"," dim=256, input_resolution=(160, 120), depth=2\n"," (blocks): ModuleList(\n"," (0-1): 2 x SwinTransformerBlock(\n"," (norm1): LayerNorm((256,), eps=1e-05, elementwise_affine=True)\n"," (attn): WindowAttention(\n"," (qkv): Linear(in_features=256, out_features=768, bias=True)\n"," (attn_drop): Dropout(p=0.0, inplace=False)\n"," (proj): Linear(in_features=256, out_features=256, bias=True)\n"," (proj_drop): Dropout(p=0.0, inplace=False)\n"," (softmax): Softmax(dim=-1)\n"," )\n"," (drop_path): DropPath()\n"," (norm2): LayerNorm((256,), eps=1e-05, elementwise_affine=True)\n"," (mlp): Mlp(\n"," (fc1): Linear(in_features=256, out_features=1024, bias=True)\n"," (act): GELU(approximate='none')\n"," (drop1): Dropout(p=0.0, inplace=False)\n"," (fc2): Linear(in_features=1024, out_features=256, bias=True)\n"," (drop2): Dropout(p=0.0, inplace=False)\n"," )\n"," )\n"," )\n"," (downsample): PatchMerging(\n"," input_resolution=(160, 120), dim=256\n"," (reduction): Linear(in_features=1024, out_features=512, bias=False)\n"," (norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," )\n"," )\n"," (2): BasicLayer(\n"," dim=512, input_resolution=(80, 60), depth=14\n"," (blocks): ModuleList(\n"," (0-13): 14 x SwinTransformerBlock(\n"," (norm1): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n"," (attn): WindowAttention(\n"," (qkv): Linear(in_features=512, out_features=1536, bias=True)\n"," (attn_drop): Dropout(p=0.0, inplace=False)\n"," (proj): Linear(in_features=512, out_features=512, bias=True)\n"," (proj_drop): Dropout(p=0.0, inplace=False)\n"," (softmax): Softmax(dim=-1)\n"," )\n"," (drop_path): DropPath()\n"," (norm2): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n"," (mlp): Mlp(\n"," (fc1): Linear(in_features=512, out_features=2048, bias=True)\n"," (act): GELU(approximate='none')\n"," (drop1): Dropout(p=0.0, inplace=False)\n"," (fc2): Linear(in_features=2048, out_features=512, bias=True)\n"," (drop2): Dropout(p=0.0, inplace=False)\n"," )\n"," )\n"," )\n"," (downsample): PatchMerging(\n"," input_resolution=(80, 60), dim=512\n"," (reduction): Linear(in_features=2048, out_features=1024, bias=False)\n"," (norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True)\n"," )\n"," )\n"," (3): BasicLayer(\n"," dim=1024, input_resolution=(40, 30), depth=2\n"," (blocks): ModuleList(\n"," (0-1): 2 x SwinTransformerBlock(\n"," (norm1): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," (attn): WindowAttention(\n"," (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n"," (attn_drop): Dropout(p=0.0, inplace=False)\n"," (proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (proj_drop): Dropout(p=0.0, inplace=False)\n"," (softmax): Softmax(dim=-1)\n"," )\n"," (drop_path): DropPath()\n"," (norm2): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," (mlp): Mlp(\n"," (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n"," (act): GELU(approximate='none')\n"," (drop1): Dropout(p=0.0, inplace=False)\n"," (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n"," (drop2): Dropout(p=0.0, inplace=False)\n"," )\n"," )\n"," )\n"," )\n"," )\n"," (norm): None\n"," (avgpool): AdaptiveAvgPool1d(output_size=1)\n"," (head): Identity()\n"," )\n"," )\n"," (decoder): BARTDecoder(\n"," (model): MBartForCausalLM(\n"," (model): MBartDecoderWrapper(\n"," (decoder): MBartDecoder(\n"," (embed_tokens): Embedding(57554, 1024, padding_idx=1)\n"," (embed_positions): MBartLearnedPositionalEmbedding(770, 1024)\n"," (layers): ModuleList(\n"," (0-3): 4 x MBartDecoderLayer(\n"," (self_attn): MBartAttention(\n"," (k_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (v_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (q_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (out_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," )\n"," (activation_fn): GELUActivation()\n"," (self_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," (encoder_attn): MBartAttention(\n"," (k_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (v_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (q_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," (out_proj): Linear(in_features=1024, out_features=1024, bias=True)\n"," )\n"," (encoder_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n"," (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n"," (final_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," )\n"," )\n"," (layernorm_embedding): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," (layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n"," )\n"," )\n"," (lm_head): Linear(in_features=1024, out_features=57554, bias=False)\n"," )\n"," )\n",")"]},"metadata":{},"execution_count":16}]},{"cell_type":"markdown","source":["# Start gradio..."],"metadata":{"id":"FTwdNk0yWOqs"}},{"cell_type":"code","source":["demo = gr.Interface(fn=demo_process,inputs=\"image\",outputs=\"json\", title=f\"Donut 🍩 demonstration for `{task_name}` task\",)\n","demo.launch(debug=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":680},"id":"6qccbLFaQuIU","executionInfo":{"status":"ok","timestamp":1731434081244,"user_tz":-480,"elapsed":181196,"user":{"displayName":"Timothy CHAN","userId":"13045196819212164142"}},"outputId":"95e572b7-cff1-457c-aa39-6027daba4a86"},"execution_count":17,"outputs":[{"output_type":"stream","name":"stdout","text":["Running Gradio in a Colab notebook requires sharing enabled. Automatically setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n","\n","Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n","* Running on public URL: https://fce912f4f29f9f530a.gradio.live\n","\n","This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"]},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["
"]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Keyboard interruption in main thread... closing server.\n","Killing tunnel 127.0.0.1:7860 <> https://fce912f4f29f9f530a.gradio.live\n"]},{"output_type":"execute_result","data":{"text/plain":[]},"metadata":{},"execution_count":17}]}]}