ZDPLI commited on
Commit
f012e5a
·
verified ·
1 Parent(s): a87f7ef

Upload DermaScanVicuna.ipynb

Browse files

Added ipynb notebook with custom WebUI on Gradio and RAG support for pdfs

Files changed (1) hide show
  1. DermaScanVicuna.ipynb +740 -0
DermaScanVicuna.ipynb ADDED
@@ -0,0 +1,740 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "d797e3ac-c8df-47fc-b349-5d2466d12ca6",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Collecting gradio\n",
14
+ " Downloading gradio-5.12.0-py3-none-any.whl.metadata (16 kB)\n",
15
+ "Collecting PyMuPDF\n",
16
+ " Downloading pymupdf-1.25.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (3.4 kB)\n",
17
+ "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (1.24.1)\n",
18
+ "Collecting faiss-gpu\n",
19
+ " Downloading faiss_gpu-1.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.4 kB)\n",
20
+ "Collecting transformers\n",
21
+ " Downloading transformers-4.48.0-py3-none-any.whl.metadata (44 kB)\n",
22
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.4/44.4 kB\u001b[0m \u001b[31m849.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
23
+ "\u001b[?25hCollecting sentence-transformers\n",
24
+ " Downloading sentence_transformers-3.3.1-py3-none-any.whl.metadata (10 kB)\n",
25
+ "Collecting protobuf\n",
26
+ " Downloading protobuf-5.29.3-cp38-abi3-manylinux2014_x86_64.whl.metadata (592 bytes)\n",
27
+ "Collecting tokenizers\n",
28
+ " Downloading tokenizers-0.21.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)\n",
29
+ "Collecting accelerate\n",
30
+ " Downloading accelerate-1.2.1-py3-none-any.whl.metadata (19 kB)\n",
31
+ "Collecting sentencepiece\n",
32
+ " Downloading sentencepiece-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.7 kB)\n",
33
+ "Collecting aiofiles<24.0,>=22.0 (from gradio)\n",
34
+ " Downloading aiofiles-23.2.1-py3-none-any.whl.metadata (9.7 kB)\n",
35
+ "Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.0.0)\n",
36
+ "Collecting fastapi<1.0,>=0.115.2 (from gradio)\n",
37
+ " Downloading fastapi-0.115.6-py3-none-any.whl.metadata (27 kB)\n",
38
+ "Collecting ffmpy (from gradio)\n",
39
+ " Downloading ffmpy-0.5.0-py3-none-any.whl.metadata (3.0 kB)\n",
40
+ "Collecting gradio-client==1.5.4 (from gradio)\n",
41
+ " Downloading gradio_client-1.5.4-py3-none-any.whl.metadata (7.1 kB)\n",
42
+ "Collecting httpx>=0.24.1 (from gradio)\n",
43
+ " Downloading httpx-0.28.1-py3-none-any.whl.metadata (7.1 kB)\n",
44
+ "Collecting huggingface-hub>=0.25.1 (from gradio)\n",
45
+ " Downloading huggingface_hub-0.27.1-py3-none-any.whl.metadata (13 kB)\n",
46
+ "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.2)\n",
47
+ "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.2)\n",
48
+ "Collecting orjson~=3.0 (from gradio)\n",
49
+ " Downloading orjson-3.10.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (41 kB)\n",
50
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.8/41.8 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
51
+ "\u001b[?25hRequirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2)\n",
52
+ "Collecting pandas<3.0,>=1.0 (from gradio)\n",
53
+ " Downloading pandas-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (89 kB)\n",
54
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m89.9/89.9 kB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
55
+ "\u001b[?25hRequirement already satisfied: pillow<12.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.3.0)\n",
56
+ "Collecting pydantic>=2.0 (from gradio)\n",
57
+ " Downloading pydantic-2.10.5-py3-none-any.whl.metadata (30 kB)\n",
58
+ "Collecting pydub (from gradio)\n",
59
+ " Downloading pydub-0.25.1-py2.py3-none-any.whl.metadata (1.4 kB)\n",
60
+ "Collecting python-multipart>=0.0.18 (from gradio)\n",
61
+ " Downloading python_multipart-0.0.20-py3-none-any.whl.metadata (1.8 kB)\n",
62
+ "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
63
+ "Collecting ruff>=0.2.2 (from gradio)\n",
64
+ " Downloading ruff-0.9.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (25 kB)\n",
65
+ "Collecting safehttpx<0.2.0,>=0.1.6 (from gradio)\n",
66
+ " Downloading safehttpx-0.1.6-py3-none-any.whl.metadata (4.2 kB)\n",
67
+ "Collecting semantic-version~=2.0 (from gradio)\n",
68
+ " Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\n",
69
+ "Collecting starlette<1.0,>=0.40.0 (from gradio)\n",
70
+ " Downloading starlette-0.45.2-py3-none-any.whl.metadata (6.3 kB)\n",
71
+ "Collecting tomlkit<0.14.0,>=0.12.0 (from gradio)\n",
72
+ " Downloading tomlkit-0.13.2-py3-none-any.whl.metadata (2.7 kB)\n",
73
+ "Collecting typer<1.0,>=0.12 (from gradio)\n",
74
+ " Downloading typer-0.15.1-py3-none-any.whl.metadata (15 kB)\n",
75
+ "Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.4.0)\n",
76
+ "Collecting uvicorn>=0.14.0 (from gradio)\n",
77
+ " Downloading uvicorn-0.34.0-py3-none-any.whl.metadata (6.5 kB)\n",
78
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.5.4->gradio) (2023.4.0)\n",
79
+ "Collecting websockets<15.0,>=10.0 (from gradio-client==1.5.4->gradio)\n",
80
+ " Downloading websockets-14.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)\n",
81
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers) (3.9.0)\n",
82
+ "Collecting regex!=2019.12.17 (from transformers)\n",
83
+ " Downloading regex-2024.11.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (40 kB)\n",
84
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m40.5/40.5 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
85
+ "\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers) (2.31.0)\n",
86
+ "Collecting safetensors>=0.4.1 (from transformers)\n",
87
+ " Downloading safetensors-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)\n",
88
+ "Collecting tqdm>=4.27 (from transformers)\n",
89
+ " Downloading tqdm-4.67.1-py3-none-any.whl.metadata (57 kB)\n",
90
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.7/57.7 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
91
+ "\u001b[?25hRequirement already satisfied: torch>=1.11.0 in /usr/local/lib/python3.10/dist-packages (from sentence-transformers) (2.1.0+cu118)\n",
92
+ "Collecting scikit-learn (from sentence-transformers)\n",
93
+ " Downloading scikit_learn-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)\n",
94
+ "Collecting scipy (from sentence-transformers)\n",
95
+ " Downloading scipy-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)\n",
96
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.0/62.0 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
97
+ "\u001b[?25hRequirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from accelerate) (5.9.6)\n",
98
+ "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (3.4)\n",
99
+ "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.0)\n",
100
+ "Requirement already satisfied: exceptiongroup>=1.0.2 in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio) (1.1.3)\n",
101
+ "Collecting starlette<1.0,>=0.40.0 (from gradio)\n",
102
+ " Downloading starlette-0.41.3-py3-none-any.whl.metadata (6.0 kB)\n",
103
+ "Collecting typing-extensions~=4.0 (from gradio)\n",
104
+ " Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)\n",
105
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2022.12.7)\n",
106
+ "Collecting httpcore==1.* (from httpx>=0.24.1->gradio)\n",
107
+ " Downloading httpcore-1.0.7-py3-none-any.whl.metadata (21 kB)\n",
108
+ "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.24.1->gradio)\n",
109
+ " Downloading h11-0.14.0-py3-none-any.whl.metadata (8.2 kB)\n",
110
+ "Collecting fsspec (from gradio-client==1.5.4->gradio)\n",
111
+ " Downloading fsspec-2024.12.0-py3-none-any.whl.metadata (11 kB)\n",
112
+ "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",
113
+ "Collecting pytz>=2020.1 (from pandas<3.0,>=1.0->gradio)\n",
114
+ " Downloading pytz-2024.2-py2.py3-none-any.whl.metadata (22 kB)\n",
115
+ "Collecting tzdata>=2022.7 (from pandas<3.0,>=1.0->gradio)\n",
116
+ " Downloading tzdata-2024.2-py2.py3-none-any.whl.metadata (1.4 kB)\n",
117
+ "Collecting annotated-types>=0.6.0 (from pydantic>=2.0->gradio)\n",
118
+ " Downloading annotated_types-0.7.0-py3-none-any.whl.metadata (15 kB)\n",
119
+ "Collecting pydantic-core==2.27.2 (from pydantic>=2.0->gradio)\n",
120
+ " Downloading pydantic_core-2.27.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.6 kB)\n",
121
+ "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=1.11.0->sentence-transformers) (1.12)\n",
122
+ "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.11.0->sentence-transformers) (3.0)\n",
123
+ "Requirement already satisfied: triton==2.1.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.11.0->sentence-transformers) (2.1.0)\n",
124
+ "Collecting click>=8.0.0 (from typer<1.0,>=0.12->gradio)\n",
125
+ " Downloading click-8.1.8-py3-none-any.whl.metadata (2.3 kB)\n",
126
+ "Collecting shellingham>=1.3.0 (from typer<1.0,>=0.12->gradio)\n",
127
+ " Downloading shellingham-1.5.4-py2.py3-none-any.whl.metadata (3.5 kB)\n",
128
+ "Collecting rich>=10.11.0 (from typer<1.0,>=0.12->gradio)\n",
129
+ " Downloading rich-13.9.4-py3-none-any.whl.metadata (18 kB)\n",
130
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2.1.1)\n",
131
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (1.26.13)\n",
132
+ "Collecting joblib>=1.2.0 (from scikit-learn->sentence-transformers)\n",
133
+ " Downloading joblib-1.4.2-py3-none-any.whl.metadata (5.4 kB)\n",
134
+ "Collecting threadpoolctl>=3.1.0 (from scikit-learn->sentence-transformers)\n",
135
+ " Downloading threadpoolctl-3.5.0-py3-none-any.whl.metadata (13 kB)\n",
136
+ "Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.16.0)\n",
137
+ "Collecting markdown-it-py>=2.2.0 (from rich>=10.11.0->typer<1.0,>=0.12->gradio)\n",
138
+ " Downloading markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)\n",
139
+ "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.16.1)\n",
140
+ "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=1.11.0->sentence-transformers) (1.3.0)\n",
141
+ "Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio)\n",
142
+ " Downloading mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)\n",
143
+ "Downloading gradio-5.12.0-py3-none-any.whl (57.6 MB)\n",
144
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.6/57.6 MB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0mm\n",
145
+ "\u001b[?25hDownloading gradio_client-1.5.4-py3-none-any.whl (321 kB)\n",
146
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m321.4/321.4 kB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
147
+ "\u001b[?25hDownloading pymupdf-1.25.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (20.0 MB)\n",
148
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m20.0/20.0 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
149
+ "\u001b[?25hDownloading faiss_gpu-1.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (85.5 MB)\n",
150
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m85.5/85.5 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
151
+ "\u001b[?25hDownloading transformers-4.48.0-py3-none-any.whl (9.7 MB)\n",
152
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.7/9.7 MB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
153
+ "\u001b[?25hDownloading sentence_transformers-3.3.1-py3-none-any.whl (268 kB)\n",
154
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m268.8/268.8 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
155
+ "\u001b[?25hDownloading protobuf-5.29.3-cp38-abi3-manylinux2014_x86_64.whl (319 kB)\n",
156
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m319.7/319.7 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
157
+ "\u001b[?25hDownloading tokenizers-0.21.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)\n",
158
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.0/3.0 MB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0mm\n",
159
+ "\u001b[?25hDownloading accelerate-1.2.1-py3-none-any.whl (336 kB)\n",
160
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m336.4/336.4 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
161
+ "\u001b[?25hDownloading sentencepiece-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n",
162
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
163
+ "\u001b[?25hDownloading aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
164
+ "Downloading fastapi-0.115.6-py3-none-any.whl (94 kB)\n",
165
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m94.8/94.8 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
166
+ "\u001b[?25hDownloading httpx-0.28.1-py3-none-any.whl (73 kB)\n",
167
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.5/73.5 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
168
+ "\u001b[?25hDownloading httpcore-1.0.7-py3-none-any.whl (78 kB)\n",
169
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.6/78.6 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
170
+ "\u001b[?25hDownloading huggingface_hub-0.27.1-py3-none-any.whl (450 kB)\n",
171
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m450.7/450.7 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
172
+ "\u001b[?25hDownloading orjson-3.10.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (130 kB)\n",
173
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.4/130.4 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
174
+ "\u001b[?25hDownloading pandas-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB)\n",
175
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.1/13.1 MB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
176
+ "\u001b[?25hDownloading pydantic-2.10.5-py3-none-any.whl (431 kB)\n",
177
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m431.4/431.4 kB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
178
+ "\u001b[?25hDownloading pydantic_core-2.27.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB)\n",
179
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
180
+ "\u001b[?25hDownloading python_multipart-0.0.20-py3-none-any.whl (24 kB)\n",
181
+ "Downloading regex-2024.11.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (781 kB)\n",
182
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m781.7/781.7 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
183
+ "\u001b[?25hDownloading ruff-0.9.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.3 MB)\n",
184
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.3/11.3 MB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
185
+ "\u001b[?25hDownloading safehttpx-0.1.6-py3-none-any.whl (8.7 kB)\n",
186
+ "Downloading safetensors-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (461 kB)\n",
187
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m462.0/462.0 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
188
+ "\u001b[?25hDownloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
189
+ "Downloading starlette-0.41.3-py3-none-any.whl (73 kB)\n",
190
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.2/73.2 kB\u001b[0m \u001b[31m1.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
191
+ "\u001b[?25hDownloading tomlkit-0.13.2-py3-none-any.whl (37 kB)\n",
192
+ "Downloading tqdm-4.67.1-py3-none-any.whl (78 kB)\n",
193
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.5/78.5 kB\u001b[0m \u001b[31m1.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
194
+ "\u001b[?25hDownloading typer-0.15.1-py3-none-any.whl (44 kB)\n",
195
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.9/44.9 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
196
+ "\u001b[?25hDownloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)\n",
197
+ "Downloading uvicorn-0.34.0-py3-none-any.whl (62 kB)\n",
198
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.3/62.3 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
199
+ "\u001b[?25hDownloading ffmpy-0.5.0-py3-none-any.whl (6.0 kB)\n",
200
+ "Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
201
+ "Downloading scikit_learn-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.5 MB)\n",
202
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.5/13.5 MB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
203
+ "\u001b[?25hDownloading scipy-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.6 MB)\n",
204
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m40.6/40.6 MB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
205
+ "\u001b[?25hDownloading annotated_types-0.7.0-py3-none-any.whl (13 kB)\n",
206
+ "Downloading click-8.1.8-py3-none-any.whl (98 kB)\n",
207
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m98.2/98.2 kB\u001b[0m \u001b[31m833.6 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
208
+ "\u001b[?25hDownloading fsspec-2024.12.0-py3-none-any.whl (183 kB)\n",
209
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m183.9/183.9 kB\u001b[0m \u001b[31m895.7 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
210
+ "\u001b[?25hDownloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
211
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m942.8 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\u001b[36m0:00:01\u001b[0m\n",
212
+ "\u001b[?25hDownloading joblib-1.4.2-py3-none-any.whl (301 kB)\n",
213
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m301.8/301.8 kB\u001b[0m \u001b[31m975.2 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
214
+ "\u001b[?25hDownloading pytz-2024.2-py2.py3-none-any.whl (508 kB)\n",
215
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m508.0/508.0 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0mm\n",
216
+ "\u001b[?25hDownloading rich-13.9.4-py3-none-any.whl (242 kB)\n",
217
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m242.4/242.4 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
218
+ "\u001b[?25hDownloading shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n",
219
+ "Downloading threadpoolctl-3.5.0-py3-none-any.whl (18 kB)\n",
220
+ "Downloading tzdata-2024.2-py2.py3-none-any.whl (346 kB)\n",
221
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m346.6/346.6 kB\u001b[0m \u001b[31m974.3 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
222
+ "\u001b[?25hDownloading websockets-14.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (168 kB)\n",
223
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m168.2/168.2 kB\u001b[0m \u001b[31m1.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0mm\n",
224
+ "\u001b[?25hDownloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)\n",
225
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m87.5/87.5 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
226
+ "\u001b[?25hDownloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n",
227
+ "Installing collected packages: sentencepiece, pytz, pydub, faiss-gpu, websockets, tzdata, typing-extensions, tqdm, tomlkit, threadpoolctl, shellingham, semantic-version, scipy, safetensors, ruff, regex, python-multipart, PyMuPDF, protobuf, orjson, mdurl, joblib, h11, fsspec, ffmpy, click, annotated-types, aiofiles, uvicorn, starlette, scikit-learn, pydantic-core, pandas, markdown-it-py, huggingface-hub, httpcore, tokenizers, rich, pydantic, httpx, accelerate, typer, transformers, safehttpx, gradio-client, fastapi, sentence-transformers, gradio\n",
228
+ " Attempting uninstall: typing-extensions\n",
229
+ " Found existing installation: typing_extensions 4.4.0\n",
230
+ " Uninstalling typing_extensions-4.4.0:\n",
231
+ " Successfully uninstalled typing_extensions-4.4.0\n",
232
+ " Attempting uninstall: fsspec\n",
233
+ " Found existing installation: fsspec 2023.4.0\n",
234
+ " Uninstalling fsspec-2023.4.0:\n",
235
+ " Successfully uninstalled fsspec-2023.4.0\n",
236
+ "Successfully installed PyMuPDF-1.25.1 accelerate-1.2.1 aiofiles-23.2.1 annotated-types-0.7.0 click-8.1.8 faiss-gpu-1.7.2 fastapi-0.115.6 ffmpy-0.5.0 fsspec-2024.12.0 gradio-5.12.0 gradio-client-1.5.4 h11-0.14.0 httpcore-1.0.7 httpx-0.28.1 huggingface-hub-0.27.1 joblib-1.4.2 markdown-it-py-3.0.0 mdurl-0.1.2 orjson-3.10.14 pandas-2.2.3 protobuf-5.29.3 pydantic-2.10.5 pydantic-core-2.27.2 pydub-0.25.1 python-multipart-0.0.20 pytz-2024.2 regex-2024.11.6 rich-13.9.4 ruff-0.9.1 safehttpx-0.1.6 safetensors-0.5.2 scikit-learn-1.6.1 scipy-1.15.1 semantic-version-2.10.0 sentence-transformers-3.3.1 sentencepiece-0.2.0 shellingham-1.5.4 starlette-0.41.3 threadpoolctl-3.5.0 tokenizers-0.21.0 tomlkit-0.13.2 tqdm-4.67.1 transformers-4.48.0 typer-0.15.1 typing-extensions-4.12.2 tzdata-2024.2 uvicorn-0.34.0 websockets-14.1\n",
237
+ "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
238
+ "\u001b[0m\n",
239
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
240
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n"
241
+ ]
242
+ }
243
+ ],
244
+ "source": [
245
+ "!pip install gradio PyMuPDF numpy faiss-gpu transformers sentence-transformers protobuf tokenizers accelerate sentencepiece"
246
+ ]
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "execution_count": 3,
251
+ "id": "e952b997-7a55-4eae-8b44-3be6a82b1bcf",
252
+ "metadata": {},
253
+ "outputs": [
254
+ {
255
+ "name": "stdout",
256
+ "output_type": "stream",
257
+ "text": [
258
+ "Collecting bitsandbytes\n",
259
+ " Downloading bitsandbytes-0.45.0-py3-none-manylinux_2_24_x86_64.whl.metadata (2.9 kB)\n",
260
+ "Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (from bitsandbytes) (2.1.0+cu118)\n",
261
+ "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from bitsandbytes) (1.24.1)\n",
262
+ "Requirement already satisfied: typing_extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from bitsandbytes) (4.12.2)\n",
263
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (3.9.0)\n",
264
+ "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (1.12)\n",
265
+ "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (3.0)\n",
266
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (3.1.2)\n",
267
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (2024.12.0)\n",
268
+ "Requirement already satisfied: triton==2.1.0 in /usr/local/lib/python3.10/dist-packages (from torch->bitsandbytes) (2.1.0)\n",
269
+ "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch->bitsandbytes) (2.1.2)\n",
270
+ "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch->bitsandbytes) (1.3.0)\n",
271
+ "Downloading bitsandbytes-0.45.0-py3-none-manylinux_2_24_x86_64.whl (69.1 MB)\n",
272
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m69.1/69.1 MB\u001b[0m \u001b[31m41.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
273
+ "\u001b[?25hInstalling collected packages: bitsandbytes\n",
274
+ "Successfully installed bitsandbytes-0.45.0\n",
275
+ "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
276
+ "\u001b[0m\n",
277
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
278
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n"
279
+ ]
280
+ }
281
+ ],
282
+ "source": [
283
+ "!pip install bitsandbytes"
284
+ ]
285
+ },
286
+ {
287
+ "cell_type": "code",
288
+ "execution_count": 1,
289
+ "id": "ba87e888-bde5-4fc9-816b-a4cc4361d1bb",
290
+ "metadata": {},
291
+ "outputs": [
292
+ {
293
+ "name": "stderr",
294
+ "output_type": "stream",
295
+ "text": [
296
+ "You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama.LlamaTokenizer'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565 - if you loaded a llama tokenizer from a GGUF file you can ignore this message\n",
297
+ "You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama_fast.LlamaTokenizerFast'>. This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thoroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565 - if you loaded a llama tokenizer from a GGUF file you can ignore this message.\n"
298
+ ]
299
+ },
300
+ {
301
+ "data": {
302
+ "application/vnd.jupyter.widget-view+json": {
303
+ "model_id": "9931b1deaeca47309c3ddffc40647368",
304
+ "version_major": 2,
305
+ "version_minor": 0
306
+ },
307
+ "text/plain": [
308
+ "pytorch_model.bin.index.json: 0%| | 0.00/33.4k [00:00<?, ?B/s]"
309
+ ]
310
+ },
311
+ "metadata": {},
312
+ "output_type": "display_data"
313
+ },
314
+ {
315
+ "data": {
316
+ "application/vnd.jupyter.widget-view+json": {
317
+ "model_id": "b73368a1856f45fdbebe3a06737160b2",
318
+ "version_major": 2,
319
+ "version_minor": 0
320
+ },
321
+ "text/plain": [
322
+ "Downloading shards: 0%| | 0/3 [00:00<?, ?it/s]"
323
+ ]
324
+ },
325
+ "metadata": {},
326
+ "output_type": "display_data"
327
+ },
328
+ {
329
+ "data": {
330
+ "application/vnd.jupyter.widget-view+json": {
331
+ "model_id": "402148343b0542299aa4cb5694a52539",
332
+ "version_major": 2,
333
+ "version_minor": 0
334
+ },
335
+ "text/plain": [
336
+ "pytorch_model-00001-of-00003.bin: 0%| | 0.00/9.95G [00:00<?, ?B/s]"
337
+ ]
338
+ },
339
+ "metadata": {},
340
+ "output_type": "display_data"
341
+ },
342
+ {
343
+ "data": {
344
+ "application/vnd.jupyter.widget-view+json": {
345
+ "model_id": "bd93bcd6c5254050ac004d7a06ceccbe",
346
+ "version_major": 2,
347
+ "version_minor": 0
348
+ },
349
+ "text/plain": [
350
+ "pytorch_model-00002-of-00003.bin: 0%| | 0.00/9.90G [00:00<?, ?B/s]"
351
+ ]
352
+ },
353
+ "metadata": {},
354
+ "output_type": "display_data"
355
+ },
356
+ {
357
+ "data": {
358
+ "application/vnd.jupyter.widget-view+json": {
359
+ "model_id": "756ad98692b646e19095658889c1da7a",
360
+ "version_major": 2,
361
+ "version_minor": 0
362
+ },
363
+ "text/plain": [
364
+ "pytorch_model-00003-of-00003.bin: 0%| | 0.00/6.18G [00:00<?, ?B/s]"
365
+ ]
366
+ },
367
+ "metadata": {},
368
+ "output_type": "display_data"
369
+ },
370
+ {
371
+ "data": {
372
+ "application/vnd.jupyter.widget-view+json": {
373
+ "model_id": "9067276802da41ac9bdcd0cf439b7887",
374
+ "version_major": 2,
375
+ "version_minor": 0
376
+ },
377
+ "text/plain": [
378
+ "Loading checkpoint shards: 0%| | 0/3 [00:00<?, ?it/s]"
379
+ ]
380
+ },
381
+ "metadata": {},
382
+ "output_type": "display_data"
383
+ },
384
+ {
385
+ "name": "stderr",
386
+ "output_type": "stream",
387
+ "text": [
388
+ "/usr/local/lib/python3.10/dist-packages/torch/_utils.py:831: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()\n",
389
+ " return self.fget.__get__(instance, owner)()\n"
390
+ ]
391
+ },
392
+ {
393
+ "data": {
394
+ "application/vnd.jupyter.widget-view+json": {
395
+ "model_id": "c31865eaedec400496e790306cddfd60",
396
+ "version_major": 2,
397
+ "version_minor": 0
398
+ },
399
+ "text/plain": [
400
+ "generation_config.json: 0%| | 0.00/132 [00:00<?, ?B/s]"
401
+ ]
402
+ },
403
+ "metadata": {},
404
+ "output_type": "display_data"
405
+ }
406
+ ],
407
+ "source": [
408
+ "import gradio as gr\n",
409
+ "import fitz # PyMuPDF\n",
410
+ "import numpy as np\n",
411
+ "import faiss\n",
412
+ "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
413
+ "from sentence_transformers import SentenceTransformer\n",
414
+ "import torch\n",
415
+ "from transformers import BitsAndBytesConfig\n",
416
+ "\n",
417
+ "\n",
418
+ "model_name = \"ZDPLI/SkinGPTVicunaMerged\" # Example open-source model\n",
419
+ "quantization_config = BitsAndBytesConfig(load_in_8bit=True)\n",
420
+ "tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
421
+ "model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=quantization_config, device_map=\"auto\")"
422
+ ]
423
+ },
424
+ {
425
+ "cell_type": "code",
426
+ "execution_count": 3,
427
+ "id": "f0256261-1610-4b6f-b947-58c398a99bd9",
428
+ "metadata": {},
429
+ "outputs": [
430
+ {
431
+ "name": "stdout",
432
+ "output_type": "stream",
433
+ "text": [
434
+ "* Running on local URL: http://127.0.0.1:7860\n",
435
+ "* Running on public URL: https://e9a1fd35c9941c2e3f.gradio.live\n",
436
+ "\n",
437
+ "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"
438
+ ]
439
+ },
440
+ {
441
+ "data": {
442
+ "text/html": [
443
+ "<div><iframe src=\"https://e9a1fd35c9941c2e3f.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
444
+ ],
445
+ "text/plain": [
446
+ "<IPython.core.display.HTML object>"
447
+ ]
448
+ },
449
+ "metadata": {},
450
+ "output_type": "display_data"
451
+ },
452
+ {
453
+ "data": {
454
+ "text/plain": []
455
+ },
456
+ "execution_count": 3,
457
+ "metadata": {},
458
+ "output_type": "execute_result"
459
+ },
460
+ {
461
+ "data": {
462
+ "application/vnd.jupyter.widget-view+json": {
463
+ "model_id": "04ea1db8d4094ed6ba1e997c5631dcad",
464
+ "version_major": 2,
465
+ "version_minor": 0
466
+ },
467
+ "text/plain": [
468
+ "modules.json: 0%| | 0.00/349 [00:00<?, ?B/s]"
469
+ ]
470
+ },
471
+ "metadata": {},
472
+ "output_type": "display_data"
473
+ },
474
+ {
475
+ "data": {
476
+ "application/vnd.jupyter.widget-view+json": {
477
+ "model_id": "a92a037d6809413eb47e6bb3a4d1061b",
478
+ "version_major": 2,
479
+ "version_minor": 0
480
+ },
481
+ "text/plain": [
482
+ "config_sentence_transformers.json: 0%| | 0.00/116 [00:00<?, ?B/s]"
483
+ ]
484
+ },
485
+ "metadata": {},
486
+ "output_type": "display_data"
487
+ },
488
+ {
489
+ "data": {
490
+ "application/vnd.jupyter.widget-view+json": {
491
+ "model_id": "ce812db4cb204caabf396c361295efb5",
492
+ "version_major": 2,
493
+ "version_minor": 0
494
+ },
495
+ "text/plain": [
496
+ "README.md: 0%| | 0.00/10.7k [00:00<?, ?B/s]"
497
+ ]
498
+ },
499
+ "metadata": {},
500
+ "output_type": "display_data"
501
+ },
502
+ {
503
+ "data": {
504
+ "application/vnd.jupyter.widget-view+json": {
505
+ "model_id": "a837445d4b364b4290ee3c4709cdf571",
506
+ "version_major": 2,
507
+ "version_minor": 0
508
+ },
509
+ "text/plain": [
510
+ "sentence_bert_config.json: 0%| | 0.00/53.0 [00:00<?, ?B/s]"
511
+ ]
512
+ },
513
+ "metadata": {},
514
+ "output_type": "display_data"
515
+ },
516
+ {
517
+ "data": {
518
+ "application/vnd.jupyter.widget-view+json": {
519
+ "model_id": "9c806eb19cbe45399728273ece902cc3",
520
+ "version_major": 2,
521
+ "version_minor": 0
522
+ },
523
+ "text/plain": [
524
+ "config.json: 0%| | 0.00/612 [00:00<?, ?B/s]"
525
+ ]
526
+ },
527
+ "metadata": {},
528
+ "output_type": "display_data"
529
+ },
530
+ {
531
+ "data": {
532
+ "application/vnd.jupyter.widget-view+json": {
533
+ "model_id": "e37a60d807424b37aa0a210279bfaa30",
534
+ "version_major": 2,
535
+ "version_minor": 0
536
+ },
537
+ "text/plain": [
538
+ "model.safetensors: 0%| | 0.00/90.9M [00:00<?, ?B/s]"
539
+ ]
540
+ },
541
+ "metadata": {},
542
+ "output_type": "display_data"
543
+ },
544
+ {
545
+ "data": {
546
+ "application/vnd.jupyter.widget-view+json": {
547
+ "model_id": "ab101967752941abb386512322d8d728",
548
+ "version_major": 2,
549
+ "version_minor": 0
550
+ },
551
+ "text/plain": [
552
+ "tokenizer_config.json: 0%| | 0.00/350 [00:00<?, ?B/s]"
553
+ ]
554
+ },
555
+ "metadata": {},
556
+ "output_type": "display_data"
557
+ },
558
+ {
559
+ "data": {
560
+ "application/vnd.jupyter.widget-view+json": {
561
+ "model_id": "94efbc8231a342e995f380ac1d01b6d6",
562
+ "version_major": 2,
563
+ "version_minor": 0
564
+ },
565
+ "text/plain": [
566
+ "vocab.txt: 0%| | 0.00/232k [00:00<?, ?B/s]"
567
+ ]
568
+ },
569
+ "metadata": {},
570
+ "output_type": "display_data"
571
+ },
572
+ {
573
+ "data": {
574
+ "application/vnd.jupyter.widget-view+json": {
575
+ "model_id": "dfbcffd3466a423cb78f639fcf7864af",
576
+ "version_major": 2,
577
+ "version_minor": 0
578
+ },
579
+ "text/plain": [
580
+ "tokenizer.json: 0%| | 0.00/466k [00:00<?, ?B/s]"
581
+ ]
582
+ },
583
+ "metadata": {},
584
+ "output_type": "display_data"
585
+ },
586
+ {
587
+ "data": {
588
+ "application/vnd.jupyter.widget-view+json": {
589
+ "model_id": "5f8e73e7e4994381a0c45bb9098def94",
590
+ "version_major": 2,
591
+ "version_minor": 0
592
+ },
593
+ "text/plain": [
594
+ "special_tokens_map.json: 0%| | 0.00/112 [00:00<?, ?B/s]"
595
+ ]
596
+ },
597
+ "metadata": {},
598
+ "output_type": "display_data"
599
+ },
600
+ {
601
+ "data": {
602
+ "application/vnd.jupyter.widget-view+json": {
603
+ "model_id": "9cbd21d1770f4ce59c25bbf4c5ea20d2",
604
+ "version_major": 2,
605
+ "version_minor": 0
606
+ },
607
+ "text/plain": [
608
+ "1_Pooling/config.json: 0%| | 0.00/190 [00:00<?, ?B/s]"
609
+ ]
610
+ },
611
+ "metadata": {},
612
+ "output_type": "display_data"
613
+ }
614
+ ],
615
+ "source": [
616
+ "import gradio as gr\n",
617
+ "import fitz # PyMuPDF\n",
618
+ "import numpy as np\n",
619
+ "import faiss\n",
620
+ "from transformers import AutoTokenizer, AutoModelForCausalLM\n",
621
+ "from sentence_transformers import SentenceTransformer\n",
622
+ "import torch\n",
623
+ "from transformers import BitsAndBytesConfig\n",
624
+ "\n",
625
+ "# Helper functions\n",
626
+ "def extract_text_from_pdf(pdf_file):\n",
627
+ " \"\"\"Extract text from a PDF file.\"\"\"\n",
628
+ " text = \"\"\n",
629
+ " with fitz.open(stream=pdf_file.read(), filetype=\"pdf\") as doc:\n",
630
+ " for page in doc:\n",
631
+ " text += page.get_text()\n",
632
+ " return text\n",
633
+ "\n",
634
+ "def chunk_text(text, chunk_size=1000, chunk_overlap=200):\n",
635
+ " \"\"\"Split text into overlapping chunks.\"\"\"\n",
636
+ " chunks = []\n",
637
+ " for i in range(0, len(text), chunk_size - chunk_overlap):\n",
638
+ " chunks.append(text[i : i + chunk_size])\n",
639
+ " return chunks\n",
640
+ "\n",
641
+ "def embed_chunks(chunks, embedder):\n",
642
+ " \"\"\"Generate embeddings for text chunks.\"\"\"\n",
643
+ " return embedder.encode(chunks, convert_to_tensor=True)\n",
644
+ "\n",
645
+ "def create_vector_store(embeddings):\n",
646
+ " \"\"\"Create a FAISS vector store for the embeddings.\"\"\"\n",
647
+ " dimension = embeddings.shape[1]\n",
648
+ " index = faiss.IndexFlatL2(dimension)\n",
649
+ " index.add(embeddings.cpu().numpy().astype(\"float32\"))\n",
650
+ " return index\n",
651
+ "\n",
652
+ "def retrieve_relevant_chunks(query, index, chunks, embedder, top_k=5):\n",
653
+ " \"\"\"Retrieve the most relevant chunks for a query.\"\"\"\n",
654
+ " query_embedding = embedder.encode([query], convert_to_tensor=True).cpu().numpy()\n",
655
+ " distances, indices = index.search(query_embedding, top_k)\n",
656
+ " return [chunks[i] for i in indices[0]]\n",
657
+ "\n",
658
+ "def process_query(pdf_file, image, user_query):\n",
659
+ " \"\"\"Process user query using uploaded PDF and/or image.\"\"\"\n",
660
+ " embedder = SentenceTransformer(\"all-MiniLM-L6-v2\")\n",
661
+ "\n",
662
+ " # Initialize variables for context\n",
663
+ " extracted_text = \"\"\n",
664
+ " chunks = []\n",
665
+ "\n",
666
+ " if pdf_file is not None:\n",
667
+ " extracted_text = extract_text_from_pdf(pdf_file)\n",
668
+ " chunks = chunk_text(extracted_text)\n",
669
+ " embeddings = embed_chunks(chunks, embedder)\n",
670
+ " vector_store = create_vector_store(embeddings)\n",
671
+ " relevant_chunks = retrieve_relevant_chunks(user_query, vector_store, chunks, embedder)\n",
672
+ " else:\n",
673
+ " relevant_chunks = []\n",
674
+ "\n",
675
+ " # Prepare context\n",
676
+ " context = \" \".join(relevant_chunks)\n",
677
+ " if image is not None:\n",
678
+ " context += \" Image information is available for analysis.\" # Placeholder for image processing integration\n",
679
+ "\n",
680
+ " # Generate response\n",
681
+ " input_text = f\"Context: {context}\\n\\nQuestion: {user_query}\\n\\nAnswer:\"\n",
682
+ " inputs = tokenizer(input_text, return_tensors=\"pt\").to(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
683
+ " outputs = model.generate(**inputs, max_length=512, num_return_sequences=1)\n",
684
+ " response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
685
+ "\n",
686
+ " return \"\\n\\n\".join(relevant_chunks) if relevant_chunks else \"No relevant PDF content found.\", response\n",
687
+ "\n",
688
+ "# Gradio WebUI\n",
689
+ "with gr.Blocks() as demo:\n",
690
+ " gr.Markdown(\"# SkinGPT-4 Custom WebUI (Vicuna-based)\")\n",
691
+ "\n",
692
+ " with gr.Row():\n",
693
+ " pdf_input = gr.File(label=\"Upload PDF (optional)\", file_types=[\".pdf\"])\n",
694
+ " image_input = gr.Image(label=\"Upload Image (optional)\")\n",
695
+ " user_query = gr.Textbox(label=\"Enter your question\")\n",
696
+ "\n",
697
+ " with gr.Row():\n",
698
+ " relevant_info = gr.Textbox(label=\"Relevant Information from PDF\", lines=10)\n",
699
+ " model_response = gr.Textbox(label=\"Model's Response\", lines=10)\n",
700
+ "\n",
701
+ " submit_button = gr.Button(\"Submit\")\n",
702
+ "\n",
703
+ " submit_button.click(\n",
704
+ " process_query, inputs=[pdf_input, image_input, user_query], outputs=[relevant_info, model_response]\n",
705
+ " )\n",
706
+ "\n",
707
+ "demo.launch(share=True)\n"
708
+ ]
709
+ },
710
+ {
711
+ "cell_type": "code",
712
+ "execution_count": null,
713
+ "id": "a7c65ea7-548f-49df-a0d7-75343b0af67e",
714
+ "metadata": {},
715
+ "outputs": [],
716
+ "source": []
717
+ }
718
+ ],
719
+ "metadata": {
720
+ "kernelspec": {
721
+ "display_name": "Python 3 (ipykernel)",
722
+ "language": "python",
723
+ "name": "python3"
724
+ },
725
+ "language_info": {
726
+ "codemirror_mode": {
727
+ "name": "ipython",
728
+ "version": 3
729
+ },
730
+ "file_extension": ".py",
731
+ "mimetype": "text/x-python",
732
+ "name": "python",
733
+ "nbconvert_exporter": "python",
734
+ "pygments_lexer": "ipython3",
735
+ "version": "3.10.12"
736
+ }
737
+ },
738
+ "nbformat": 4,
739
+ "nbformat_minor": 5
740
+ }