tal1992 commited on
Commit
e71edca
·
1 Parent(s): ab648e4

Upload first version of app to Spaces

Browse files
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14
+ KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
15
+ OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
16
+ jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
17
+ qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
18
+ rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
19
+ HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
20
+ hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
21
+ ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
22
+ 3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
23
+ NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
24
+ ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
25
+ TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
26
+ jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
27
+ oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
28
+ 4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
29
+ mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
.ipynb_checkpoints/Audio-to-Text Summarization-checkpoint.ipynb ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "5a2fa919-19ea-48c6-b566-39e00f9a44d5",
7
+ "metadata": {
8
+ "scrolled": true
9
+ },
10
+ "outputs": [
11
+ {
12
+ "name": "stderr",
13
+ "output_type": "stream",
14
+ "text": [
15
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
16
+ " from .autonotebook import tqdm as notebook_tqdm\n"
17
+ ]
18
+ }
19
+ ],
20
+ "source": [
21
+ "# imports\n",
22
+ "\n",
23
+ "import os\n",
24
+ "from dotenv import load_dotenv\n",
25
+ "from IPython.display import Markdown, display, update_display\n",
26
+ "#from openai import OpenAI\n",
27
+ "import whisper\n",
28
+ "from huggingface_hub import login\n",
29
+ "from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer, BitsAndBytesConfig\n",
30
+ "import torch"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 2,
36
+ "id": "914837b3-67b7-4a14-9754-fef7cdac3861",
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "text/plain": [
42
+ "True"
43
+ ]
44
+ },
45
+ "execution_count": 2,
46
+ "metadata": {},
47
+ "output_type": "execute_result"
48
+ }
49
+ ],
50
+ "source": [
51
+ "load_dotenv(override=True)"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 3,
57
+ "id": "54a2f467-477c-4034-8a3e-a05df3dbdc2e",
58
+ "metadata": {},
59
+ "outputs": [
60
+ {
61
+ "name": "stdout",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "HuggingFace API Key exists and begins hf_FXpUT\n"
65
+ ]
66
+ }
67
+ ],
68
+ "source": [
69
+ "hf_api_key = os.getenv('HF_TOKEN')\n",
70
+ "if hf_api_key:\n",
71
+ " print(f\"HuggingFace API Key exists and begins {hf_api_key[:8]}\")\n",
72
+ "else: \n",
73
+ " print(\"HuggingFace API Key not set\")"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": 4,
79
+ "id": "1bb335ba-1c53-4e46-92ad-c51e700507d5",
80
+ "metadata": {},
81
+ "outputs": [],
82
+ "source": [
83
+ "# Load environment variables in a file called .env\n",
84
+ "\n",
85
+ "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')\n",
86
+ "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
87
+ "#openai = OpenAI()"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 5,
93
+ "id": "dc042550-6331-4c18-924b-90276c43e03f",
94
+ "metadata": {},
95
+ "outputs": [
96
+ {
97
+ "name": "stdout",
98
+ "output_type": "stream",
99
+ "text": [
100
+ "CUDA Available: True\n",
101
+ "Number of GPUs: 1\n",
102
+ "Current CUDA Device: NVIDIA GeForce RTX 4060 Laptop GPU\n"
103
+ ]
104
+ }
105
+ ],
106
+ "source": [
107
+ "# Check if CUDA is available\n",
108
+ "print(\"CUDA Available: \", torch.cuda.is_available())\n",
109
+ "\n",
110
+ "# List available GPUs\n",
111
+ "print(\"Number of GPUs: \", torch.cuda.device_count())\n",
112
+ "\n",
113
+ "# Get the name of the current device\n",
114
+ "print(\"Current CUDA Device: \", torch.cuda.get_device_name(torch.cuda.current_device()))"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 6,
120
+ "id": "c7663c9e-23eb-4806-808a-bdd3c4476371",
121
+ "metadata": {},
122
+ "outputs": [],
123
+ "source": [
124
+ "# Constants\n",
125
+ "\n",
126
+ "AUDIO_MODEL = \"whisper-1\"\n",
127
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\""
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": 13,
133
+ "id": "79677c44-6765-449c-844e-d6f9dcb65bfb",
134
+ "metadata": {
135
+ "scrolled": true
136
+ },
137
+ "outputs": [],
138
+ "source": [
139
+ "audio_filename = \"phone_20250226-104954__19042343028.mp3\""
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": 15,
145
+ "id": "6837cddf-aa2c-4026-b7ec-6042a9c2c58f",
146
+ "metadata": {
147
+ "scrolled": true
148
+ },
149
+ "outputs": [
150
+ {
151
+ "name": "stderr",
152
+ "output_type": "stream",
153
+ "text": [
154
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\file_download.py:142: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\Tal-Jacobi\\.cache\\huggingface\\hub\\models--openai--whisper-large-v2. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
155
+ "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
156
+ " warnings.warn(message)\n"
157
+ ]
158
+ },
159
+ {
160
+ "ename": "KeyboardInterrupt",
161
+ "evalue": "",
162
+ "output_type": "error",
163
+ "traceback": [
164
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
165
+ "\u001b[31mKeyboardInterrupt\u001b[39m Traceback (most recent call last)",
166
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[15]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m pipeline\n\u001b[32m 3\u001b[39m \u001b[38;5;66;03m# Load the Whisper v2 model pipeline\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m pipe = \u001b[43mpipeline\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43mtask\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mautomatic-speech-recognition\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mopenai/whisper-large-v2\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\n\u001b[32m 7\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 9\u001b[39m \u001b[38;5;66;03m# Transcribe your audio file (WAV, MP3, FLAC etc.)\u001b[39;00m\n\u001b[32m 10\u001b[39m result = pipe(\u001b[33m\"\u001b[39m\u001b[33mphone_20250226-104954__19042343028.mp3\u001b[39m\u001b[33m\"\u001b[39m)\n",
167
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\pipelines\\__init__.py:940\u001b[39m, in \u001b[36mpipeline\u001b[39m\u001b[34m(task, model, config, tokenizer, feature_extractor, image_processor, processor, framework, revision, use_fast, token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)\u001b[39m\n\u001b[32m 938\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(model, \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m framework \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m 939\u001b[39m model_classes = {\u001b[33m\"\u001b[39m\u001b[33mtf\u001b[39m\u001b[33m\"\u001b[39m: targeted_task[\u001b[33m\"\u001b[39m\u001b[33mtf\u001b[39m\u001b[33m\"\u001b[39m], \u001b[33m\"\u001b[39m\u001b[33mpt\u001b[39m\u001b[33m\"\u001b[39m: targeted_task[\u001b[33m\"\u001b[39m\u001b[33mpt\u001b[39m\u001b[33m\"\u001b[39m]}\n\u001b[32m--> \u001b[39m\u001b[32m940\u001b[39m framework, model = \u001b[43minfer_framework_load_model\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 941\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 942\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel_classes\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmodel_classes\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 943\u001b[39m \u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m=\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 944\u001b[39m \u001b[43m \u001b[49m\u001b[43mframework\u001b[49m\u001b[43m=\u001b[49m\u001b[43mframework\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 945\u001b[39m \u001b[43m \u001b[49m\u001b[43mtask\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 946\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mhub_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 947\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mmodel_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 948\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 950\u001b[39m model_config = model.config\n\u001b[32m 951\u001b[39m hub_kwargs[\u001b[33m\"\u001b[39m\u001b[33m_commit_hash\u001b[39m\u001b[33m\"\u001b[39m] = model.config._commit_hash\n",
168
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\pipelines\\base.py:290\u001b[39m, in \u001b[36minfer_framework_load_model\u001b[39m\u001b[34m(model, config, model_classes, task, framework, **model_kwargs)\u001b[39m\n\u001b[32m 284\u001b[39m logger.warning(\n\u001b[32m 285\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mModel might be a PyTorch model (ending with `.bin`) but PyTorch is not available. \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 286\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mTrying to load the model with Tensorflow.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 287\u001b[39m )\n\u001b[32m 289\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m290\u001b[39m model = \u001b[43mmodel_class\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 291\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(model, \u001b[33m\"\u001b[39m\u001b[33meval\u001b[39m\u001b[33m\"\u001b[39m):\n\u001b[32m 292\u001b[39m model = model.eval()\n",
169
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\auto\\auto_factory.py:564\u001b[39m, in \u001b[36m_BaseAutoModelClass.from_pretrained\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[39m\n\u001b[32m 562\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mtype\u001b[39m(config) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mcls\u001b[39m._model_mapping.keys():\n\u001b[32m 563\u001b[39m model_class = _get_model_class(config, \u001b[38;5;28mcls\u001b[39m._model_mapping)\n\u001b[32m--> \u001b[39m\u001b[32m564\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mmodel_class\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 565\u001b[39m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43mmodel_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m=\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mhub_kwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\n\u001b[32m 566\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 567\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 568\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mUnrecognized configuration class \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mconfig.\u001b[34m__class__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m for this kind of AutoModel: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mcls\u001b[39m.\u001b[34m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 569\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mModel type should be one of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m, \u001b[39m\u001b[33m'\u001b[39m.join(c.\u001b[34m__name__\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mc\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28mcls\u001b[39m._model_mapping.keys())\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 570\u001b[39m )\n",
170
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\modeling_utils.py:262\u001b[39m, in \u001b[36mrestore_default_torch_dtype.<locals>._wrapper\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 260\u001b[39m old_dtype = torch.get_default_dtype()\n\u001b[32m 261\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m262\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 263\u001b[39m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[32m 264\u001b[39m torch.set_default_dtype(old_dtype)\n",
171
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\modeling_utils.py:3854\u001b[39m, in \u001b[36mPreTrainedModel.from_pretrained\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, *model_args, **kwargs)\u001b[39m\n\u001b[32m 3838\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 3839\u001b[39m \u001b[38;5;66;03m# Load from URL or cache if already cached\u001b[39;00m\n\u001b[32m 3840\u001b[39m cached_file_kwargs = {\n\u001b[32m 3841\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mcache_dir\u001b[39m\u001b[33m\"\u001b[39m: cache_dir,\n\u001b[32m 3842\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mforce_download\u001b[39m\u001b[33m\"\u001b[39m: force_download,\n\u001b[32m (...)\u001b[39m\u001b[32m 3852\u001b[39m \u001b[33m\"\u001b[39m\u001b[33m_commit_hash\u001b[39m\u001b[33m\"\u001b[39m: commit_hash,\n\u001b[32m 3853\u001b[39m }\n\u001b[32m-> \u001b[39m\u001b[32m3854\u001b[39m resolved_archive_file = \u001b[43mcached_file\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mcached_file_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 3856\u001b[39m \u001b[38;5;66;03m# Since we set _raise_exceptions_for_missing_entries=False, we don't get an exception but a None\u001b[39;00m\n\u001b[32m 3857\u001b[39m \u001b[38;5;66;03m# result when internet is up, the repo and revision exist, but the file does not.\u001b[39;00m\n\u001b[32m 3858\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m resolved_archive_file \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m filename == _add_variant(SAFE_WEIGHTS_NAME, variant):\n\u001b[32m 3859\u001b[39m \u001b[38;5;66;03m# Maybe the checkpoint is sharded, we try to grab the index name in this case.\u001b[39;00m\n",
172
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\utils\\hub.py:342\u001b[39m, in \u001b[36mcached_file\u001b[39m\u001b[34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[39m\n\u001b[32m 339\u001b[39m user_agent = http_user_agent(user_agent)\n\u001b[32m 340\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 341\u001b[39m \u001b[38;5;66;03m# Load from URL or cache if already cached\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m342\u001b[39m resolved_file = \u001b[43mhf_hub_download\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 343\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_or_repo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 344\u001b[39m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 345\u001b[39m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[43m==\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 346\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 347\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 348\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 349\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 350\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 351\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 352\u001b[39m \u001b[43m \u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 353\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 354\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 355\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 356\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m GatedRepoError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 357\u001b[39m resolved_file = _get_cache_file_to_return(path_or_repo_id, full_filename, cache_dir, revision)\n",
173
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[39m, in \u001b[36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 111\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[32m 112\u001b[39m kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.\u001b[34m__name__\u001b[39m, has_token=has_token, kwargs=kwargs)\n\u001b[32m--> \u001b[39m\u001b[32m114\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
174
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\file_download.py:862\u001b[39m, in \u001b[36mhf_hub_download\u001b[39m\u001b[34m(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, resume_download, force_filename, local_dir_use_symlinks)\u001b[39m\n\u001b[32m 842\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m _hf_hub_download_to_local_dir(\n\u001b[32m 843\u001b[39m \u001b[38;5;66;03m# Destination\u001b[39;00m\n\u001b[32m 844\u001b[39m local_dir=local_dir,\n\u001b[32m (...)\u001b[39m\u001b[32m 859\u001b[39m local_files_only=local_files_only,\n\u001b[32m 860\u001b[39m )\n\u001b[32m 861\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m862\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_hf_hub_download_to_cache_dir\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 863\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Destination\u001b[39;49;00m\n\u001b[32m 864\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 865\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# File info\u001b[39;49;00m\n\u001b[32m 866\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 867\u001b[39m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 868\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 869\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 870\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# HTTP info\u001b[39;49;00m\n\u001b[32m 871\u001b[39m \u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[43m=\u001b[49m\u001b[43mendpoint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 872\u001b[39m \u001b[43m \u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 873\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mhf_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 874\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 875\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 876\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Additional options\u001b[39;49;00m\n\u001b[32m 877\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 878\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 879\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
175
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\file_download.py:1011\u001b[39m, in \u001b[36m_hf_hub_download_to_cache_dir\u001b[39m\u001b[34m(cache_dir, repo_id, filename, repo_type, revision, endpoint, etag_timeout, headers, proxies, token, local_files_only, force_download)\u001b[39m\n\u001b[32m 1009\u001b[39m Path(lock_path).parent.mkdir(parents=\u001b[38;5;28;01mTrue\u001b[39;00m, exist_ok=\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[32m 1010\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m WeakFileLock(lock_path):\n\u001b[32m-> \u001b[39m\u001b[32m1011\u001b[39m \u001b[43m_download_to_tmp_and_move\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1012\u001b[39m \u001b[43m \u001b[49m\u001b[43mincomplete_path\u001b[49m\u001b[43m=\u001b[49m\u001b[43mPath\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblob_path\u001b[49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m.incomplete\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1013\u001b[39m \u001b[43m \u001b[49m\u001b[43mdestination_path\u001b[49m\u001b[43m=\u001b[49m\u001b[43mPath\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblob_path\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1014\u001b[39m \u001b[43m \u001b[49m\u001b[43murl_to_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43murl_to_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1015\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1016\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1017\u001b[39m \u001b[43m \u001b[49m\u001b[43mexpected_size\u001b[49m\u001b[43m=\u001b[49m\u001b[43mexpected_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1018\u001b[39m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1019\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1020\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1021\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os.path.exists(pointer_path):\n\u001b[32m 1022\u001b[39m _create_symlink(blob_path, pointer_path, new_blob=\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
176
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\file_download.py:1547\u001b[39m, in \u001b[36m_download_to_tmp_and_move\u001b[39m\u001b[34m(incomplete_path, destination_path, url_to_download, proxies, headers, expected_size, filename, force_download)\u001b[39m\n\u001b[32m 1544\u001b[39m _check_disk_space(expected_size, incomplete_path.parent)\n\u001b[32m 1545\u001b[39m _check_disk_space(expected_size, destination_path.parent)\n\u001b[32m-> \u001b[39m\u001b[32m1547\u001b[39m \u001b[43mhttp_get\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1548\u001b[39m \u001b[43m \u001b[49m\u001b[43murl_to_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1549\u001b[39m \u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1550\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1551\u001b[39m \u001b[43m \u001b[49m\u001b[43mresume_size\u001b[49m\u001b[43m=\u001b[49m\u001b[43mresume_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1552\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1553\u001b[39m \u001b[43m \u001b[49m\u001b[43mexpected_size\u001b[49m\u001b[43m=\u001b[49m\u001b[43mexpected_size\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1554\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1556\u001b[39m logger.info(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mDownload complete. Moving file to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdestination_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n\u001b[32m 1557\u001b[39m _chmod_and_move(incomplete_path, destination_path)\n",
177
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\huggingface_hub\\file_download.py:454\u001b[39m, in \u001b[36mhttp_get\u001b[39m\u001b[34m(url, temp_file, proxies, resume_size, headers, expected_size, displayed_filename, _nb_retries, _tqdm_bar)\u001b[39m\n\u001b[32m 452\u001b[39m new_resume_size = resume_size\n\u001b[32m 453\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m454\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mr\u001b[49m\u001b[43m.\u001b[49m\u001b[43miter_content\u001b[49m\u001b[43m(\u001b[49m\u001b[43mchunk_size\u001b[49m\u001b[43m=\u001b[49m\u001b[43mconstants\u001b[49m\u001b[43m.\u001b[49m\u001b[43mDOWNLOAD_CHUNK_SIZE\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[32m 455\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# filter out keep-alive new chunks\u001b[39;49;00m\n\u001b[32m 456\u001b[39m \u001b[43m \u001b[49m\u001b[43mprogress\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupdate\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
178
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\requests\\models.py:820\u001b[39m, in \u001b[36mResponse.iter_content.<locals>.generate\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 818\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(\u001b[38;5;28mself\u001b[39m.raw, \u001b[33m\"\u001b[39m\u001b[33mstream\u001b[39m\u001b[33m\"\u001b[39m):\n\u001b[32m 819\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m820\u001b[39m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m.raw.stream(chunk_size, decode_content=\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[32m 821\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m ProtocolError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 822\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ChunkedEncodingError(e)\n",
179
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\urllib3\\response.py:1066\u001b[39m, in \u001b[36mHTTPResponse.stream\u001b[39m\u001b[34m(self, amt, decode_content)\u001b[39m\n\u001b[32m 1064\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 1065\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m is_fp_closed(\u001b[38;5;28mself\u001b[39m._fp) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m._decoded_buffer) > \u001b[32m0\u001b[39m:\n\u001b[32m-> \u001b[39m\u001b[32m1066\u001b[39m data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43mamt\u001b[49m\u001b[43m=\u001b[49m\u001b[43mamt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdecode_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43mdecode_content\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1068\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m data:\n\u001b[32m 1069\u001b[39m \u001b[38;5;28;01myield\u001b[39;00m data\n",
180
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\urllib3\\response.py:955\u001b[39m, in \u001b[36mHTTPResponse.read\u001b[39m\u001b[34m(self, amt, decode_content, cache_content)\u001b[39m\n\u001b[32m 952\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m._decoded_buffer) >= amt:\n\u001b[32m 953\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._decoded_buffer.get(amt)\n\u001b[32m--> \u001b[39m\u001b[32m955\u001b[39m data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_raw_read\u001b[49m\u001b[43m(\u001b[49m\u001b[43mamt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 957\u001b[39m flush_decoder = amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m (amt != \u001b[32m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data)\n\u001b[32m 959\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m._decoded_buffer) == \u001b[32m0\u001b[39m:\n",
181
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\urllib3\\response.py:879\u001b[39m, in \u001b[36mHTTPResponse._raw_read\u001b[39m\u001b[34m(self, amt, read1)\u001b[39m\n\u001b[32m 876\u001b[39m fp_closed = \u001b[38;5;28mgetattr\u001b[39m(\u001b[38;5;28mself\u001b[39m._fp, \u001b[33m\"\u001b[39m\u001b[33mclosed\u001b[39m\u001b[33m\"\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[32m 878\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m._error_catcher():\n\u001b[32m--> \u001b[39m\u001b[32m879\u001b[39m data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_fp_read\u001b[49m\u001b[43m(\u001b[49m\u001b[43mamt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mread1\u001b[49m\u001b[43m=\u001b[49m\u001b[43mread1\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m fp_closed \u001b[38;5;28;01melse\u001b[39;00m \u001b[33mb\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 880\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m amt != \u001b[32m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data:\n\u001b[32m 881\u001b[39m \u001b[38;5;66;03m# Platform-specific: Buggy versions of Python.\u001b[39;00m\n\u001b[32m 882\u001b[39m \u001b[38;5;66;03m# Close the connection when no data is returned\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 887\u001b[39m \u001b[38;5;66;03m# not properly close the connection in all cases. There is\u001b[39;00m\n\u001b[32m 888\u001b[39m \u001b[38;5;66;03m# no harm in redundantly calling close.\u001b[39;00m\n\u001b[32m 889\u001b[39m \u001b[38;5;28mself\u001b[39m._fp.close()\n",
182
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\urllib3\\response.py:862\u001b[39m, in \u001b[36mHTTPResponse._fp_read\u001b[39m\u001b[34m(self, amt, read1)\u001b[39m\n\u001b[32m 859\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._fp.read1(amt) \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m._fp.read1()\n\u001b[32m 860\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 861\u001b[39m \u001b[38;5;66;03m# StringIO doesn't like amt=None\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m862\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_fp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43mamt\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m._fp.read()\n",
183
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\http\\client.py:473\u001b[39m, in \u001b[36mHTTPResponse.read\u001b[39m\u001b[34m(self, amt)\u001b[39m\n\u001b[32m 470\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.length \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m amt > \u001b[38;5;28mself\u001b[39m.length:\n\u001b[32m 471\u001b[39m \u001b[38;5;66;03m# clip the read to the \"end of response\"\u001b[39;00m\n\u001b[32m 472\u001b[39m amt = \u001b[38;5;28mself\u001b[39m.length\n\u001b[32m--> \u001b[39m\u001b[32m473\u001b[39m s = \u001b[38;5;28mself\u001b[39m.fp.read(amt)\n\u001b[32m 474\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m s \u001b[38;5;129;01mand\u001b[39;00m amt:\n\u001b[32m 475\u001b[39m \u001b[38;5;66;03m# Ideally, we would raise IncompleteRead if the content-length\u001b[39;00m\n\u001b[32m 476\u001b[39m \u001b[38;5;66;03m# wasn't satisfied, but it might break compatibility.\u001b[39;00m\n\u001b[32m 477\u001b[39m \u001b[38;5;28mself\u001b[39m._close_conn()\n",
184
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\socket.py:718\u001b[39m, in \u001b[36mSocketIO.readinto\u001b[39m\u001b[34m(self, b)\u001b[39m\n\u001b[32m 716\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[32m 717\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m718\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_sock\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrecv_into\u001b[49m\u001b[43m(\u001b[49m\u001b[43mb\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 719\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m timeout:\n\u001b[32m 720\u001b[39m \u001b[38;5;28mself\u001b[39m._timeout_occurred = \u001b[38;5;28;01mTrue\u001b[39;00m\n",
185
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\ssl.py:1314\u001b[39m, in \u001b[36mSSLSocket.recv_into\u001b[39m\u001b[34m(self, buffer, nbytes, flags)\u001b[39m\n\u001b[32m 1310\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m flags != \u001b[32m0\u001b[39m:\n\u001b[32m 1311\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 1312\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mnon-zero flags not allowed in calls to recv_into() on \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m %\n\u001b[32m 1313\u001b[39m \u001b[38;5;28mself\u001b[39m.\u001b[34m__class__\u001b[39m)\n\u001b[32m-> \u001b[39m\u001b[32m1314\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnbytes\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbuffer\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1315\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 1316\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msuper\u001b[39m().recv_into(buffer, nbytes, flags)\n",
186
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\ssl.py:1166\u001b[39m, in \u001b[36mSSLSocket.read\u001b[39m\u001b[34m(self, len, buffer)\u001b[39m\n\u001b[32m 1164\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 1165\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m buffer \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1166\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_sslobj\u001b[49m\u001b[43m.\u001b[49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbuffer\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1167\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 1168\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._sslobj.read(\u001b[38;5;28mlen\u001b[39m)\n",
187
+ "\u001b[31mKeyboardInterrupt\u001b[39m: "
188
+ ]
189
+ }
190
+ ],
191
+ "source": [
192
+ "from transformers import pipeline\n",
193
+ "\n",
194
+ "# Load the Whisper v2 model pipeline\n",
195
+ "pipe = pipeline(\n",
196
+ " task=\"automatic-speech-recognition\",\n",
197
+ " model=\"openai/whisper-large-v2\"\n",
198
+ ")\n",
199
+ "\n",
200
+ "# Transcribe your audio file (WAV, MP3, FLAC etc.)\n",
201
+ "result = pipe(\"phone_20250226-104954__19042343028.mp3\")\n",
202
+ "print(result[\"text\"])"
203
+ ]
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "execution_count": 18,
208
+ "id": "a01114da-96b7-4371-b87d-c885f8f06a5e",
209
+ "metadata": {
210
+ "scrolled": true
211
+ },
212
+ "outputs": [
213
+ {
214
+ "ename": "FileNotFoundError",
215
+ "evalue": "[WinError 2] The system cannot find the file specified",
216
+ "output_type": "error",
217
+ "traceback": [
218
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
219
+ "\u001b[31mFileNotFoundError\u001b[39m Traceback (most recent call last)",
220
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[18]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m model = whisper.load_model(\u001b[33m\"\u001b[39m\u001b[33msmall\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m result = \u001b[43mmodel\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtranscribe\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mdenver_extract.mp3\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[38;5;28mprint\u001b[39m(result[\u001b[33m\"\u001b[39m\u001b[33mtext\u001b[39m\u001b[33m\"\u001b[39m])\n",
221
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\whisper\\transcribe.py:133\u001b[39m, in \u001b[36mtranscribe\u001b[39m\u001b[34m(model, audio, verbose, temperature, compression_ratio_threshold, logprob_threshold, no_speech_threshold, condition_on_previous_text, initial_prompt, word_timestamps, prepend_punctuations, append_punctuations, clip_timestamps, hallucination_silence_threshold, **decode_options)\u001b[39m\n\u001b[32m 130\u001b[39m decode_options[\u001b[33m\"\u001b[39m\u001b[33mfp16\u001b[39m\u001b[33m\"\u001b[39m] = \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[32m 132\u001b[39m \u001b[38;5;66;03m# Pad 30-seconds of silence to the input audio, for slicing\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m133\u001b[39m mel = \u001b[43mlog_mel_spectrogram\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m.\u001b[49m\u001b[43mdims\u001b[49m\u001b[43m.\u001b[49m\u001b[43mn_mels\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpadding\u001b[49m\u001b[43m=\u001b[49m\u001b[43mN_SAMPLES\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 134\u001b[39m content_frames = mel.shape[-\u001b[32m1\u001b[39m] - N_FRAMES\n\u001b[32m 135\u001b[39m content_duration = \u001b[38;5;28mfloat\u001b[39m(content_frames * HOP_LENGTH / SAMPLE_RATE)\n",
222
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\whisper\\audio.py:140\u001b[39m, in \u001b[36mlog_mel_spectrogram\u001b[39m\u001b[34m(audio, n_mels, padding, device)\u001b[39m\n\u001b[32m 138\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m torch.is_tensor(audio):\n\u001b[32m 139\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(audio, \u001b[38;5;28mstr\u001b[39m):\n\u001b[32m--> \u001b[39m\u001b[32m140\u001b[39m audio = \u001b[43mload_audio\u001b[49m\u001b[43m(\u001b[49m\u001b[43maudio\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 141\u001b[39m audio = torch.from_numpy(audio)\n\u001b[32m 143\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m device \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
223
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\site-packages\\whisper\\audio.py:58\u001b[39m, in \u001b[36mload_audio\u001b[39m\u001b[34m(file, sr)\u001b[39m\n\u001b[32m 56\u001b[39m \u001b[38;5;66;03m# fmt: on\u001b[39;00m\n\u001b[32m 57\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m58\u001b[39m out = \u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcmd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcapture_output\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcheck\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m.stdout\n\u001b[32m 59\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m CalledProcessError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 60\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mFailed to load audio: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00me.stderr.decode()\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n",
224
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\subprocess.py:548\u001b[39m, in \u001b[36mrun\u001b[39m\u001b[34m(input, capture_output, timeout, check, *popenargs, **kwargs)\u001b[39m\n\u001b[32m 545\u001b[39m kwargs[\u001b[33m'\u001b[39m\u001b[33mstdout\u001b[39m\u001b[33m'\u001b[39m] = PIPE\n\u001b[32m 546\u001b[39m kwargs[\u001b[33m'\u001b[39m\u001b[33mstderr\u001b[39m\u001b[33m'\u001b[39m] = PIPE\n\u001b[32m--> \u001b[39m\u001b[32m548\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mPopen\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43mpopenargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m process:\n\u001b[32m 549\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 550\u001b[39m stdout, stderr = process.communicate(\u001b[38;5;28minput\u001b[39m, timeout=timeout)\n",
225
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\subprocess.py:1026\u001b[39m, in \u001b[36mPopen.__init__\u001b[39m\u001b[34m(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)\u001b[39m\n\u001b[32m 1022\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.text_mode:\n\u001b[32m 1023\u001b[39m \u001b[38;5;28mself\u001b[39m.stderr = io.TextIOWrapper(\u001b[38;5;28mself\u001b[39m.stderr,\n\u001b[32m 1024\u001b[39m encoding=encoding, errors=errors)\n\u001b[32m-> \u001b[39m\u001b[32m1026\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_execute_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexecutable\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpreexec_fn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mclose_fds\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1027\u001b[39m \u001b[43m \u001b[49m\u001b[43mpass_fds\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcwd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43menv\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1028\u001b[39m \u001b[43m \u001b[49m\u001b[43mstartupinfo\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcreationflags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mshell\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1029\u001b[39m \u001b[43m \u001b[49m\u001b[43mp2cread\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mp2cwrite\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1030\u001b[39m \u001b[43m \u001b[49m\u001b[43mc2pread\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc2pwrite\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1031\u001b[39m \u001b[43m \u001b[49m\u001b[43merrread\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merrwrite\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1032\u001b[39m \u001b[43m \u001b[49m\u001b[43mrestore_signals\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1033\u001b[39m \u001b[43m \u001b[49m\u001b[43mgid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mumask\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1034\u001b[39m \u001b[43m \u001b[49m\u001b[43mstart_new_session\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprocess_group\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1035\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m:\n\u001b[32m 1036\u001b[39m \u001b[38;5;66;03m# Cleanup if the child failed starting.\u001b[39;00m\n\u001b[32m 1037\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m f \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mfilter\u001b[39m(\u001b[38;5;28;01mNone\u001b[39;00m, (\u001b[38;5;28mself\u001b[39m.stdin, \u001b[38;5;28mself\u001b[39m.stdout, \u001b[38;5;28mself\u001b[39m.stderr)):\n",
226
+ "\u001b[36mFile \u001b[39m\u001b[32m~\\anaconda3\\envs\\app\\Lib\\subprocess.py:1538\u001b[39m, in \u001b[36mPopen._execute_child\u001b[39m\u001b[34m(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)\u001b[39m\n\u001b[32m 1536\u001b[39m \u001b[38;5;66;03m# Start the process\u001b[39;00m\n\u001b[32m 1537\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1538\u001b[39m hp, ht, pid, tid = _winapi.CreateProcess(executable, args,\n\u001b[32m 1539\u001b[39m \u001b[38;5;66;03m# no special security\u001b[39;00m\n\u001b[32m 1540\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 1541\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;129;01mnot\u001b[39;00m close_fds),\n\u001b[32m 1542\u001b[39m creationflags,\n\u001b[32m 1543\u001b[39m env,\n\u001b[32m 1544\u001b[39m cwd,\n\u001b[32m 1545\u001b[39m startupinfo)\n\u001b[32m 1546\u001b[39m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[32m 1547\u001b[39m \u001b[38;5;66;03m# Child is launched. Close the parent's copy of those pipe\u001b[39;00m\n\u001b[32m 1548\u001b[39m \u001b[38;5;66;03m# handles that only the child should have open. You need\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 1551\u001b[39m \u001b[38;5;66;03m# pipe will not close when the child process exits and the\u001b[39;00m\n\u001b[32m 1552\u001b[39m \u001b[38;5;66;03m# ReadFile will hang.\u001b[39;00m\n\u001b[32m 1553\u001b[39m \u001b[38;5;28mself\u001b[39m._close_pipe_fds(p2cread, p2cwrite,\n\u001b[32m 1554\u001b[39m c2pread, c2pwrite,\n\u001b[32m 1555\u001b[39m errread, errwrite)\n",
227
+ "\u001b[31mFileNotFoundError\u001b[39m: [WinError 2] The system cannot find the file specified"
228
+ ]
229
+ }
230
+ ],
231
+ "source": [
232
+ "model = whisper.load_model(\"small\")\n",
233
+ "result = model.transcribe(\"denver_extract.mp3\")\n",
234
+ "print(result[\"text\"])"
235
+ ]
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "execution_count": null,
240
+ "id": "316eab55-7e15-4e34-b763-6f87491d4753",
241
+ "metadata": {
242
+ "scrolled": true
243
+ },
244
+ "outputs": [],
245
+ "source": [
246
+ "# audio_file = open(audio_filename, \"rb\")\n",
247
+ "# transcription = openai.audio.transcriptions.create(model=AUDIO_MODEL, file=audio_file, response_format=\"text\")\n",
248
+ "# print(transcription)"
249
+ ]
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "execution_count": 9,
254
+ "id": "d25e500f-94f5-4f7e-b1da-84a8ceece4f0",
255
+ "metadata": {},
256
+ "outputs": [],
257
+ "source": [
258
+ "system_message = \"You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
259
+ "user_prompt = f\"Below is an extract transcript of a a phone call between Tal and friend Gilor. Please write minutes in markdown, including a summary with attendees, location and date; discussion points; takeaways; and action items with owners.\\n{transcription}\"\n",
260
+ "\n",
261
+ "messages = [\n",
262
+ " {\"role\": \"system\", \"content\": system_message},\n",
263
+ " {\"role\": \"user\", \"content\": user_prompt}\n",
264
+ " ]"
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "execution_count": 10,
270
+ "id": "408b4f33-062f-4c02-b6f8-1eaf7c042dc7",
271
+ "metadata": {},
272
+ "outputs": [],
273
+ "source": [
274
+ "quant_config = BitsAndBytesConfig(\n",
275
+ " load_in_4bit=True,\n",
276
+ " bnb_4bit_use_double_quant=True,\n",
277
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
278
+ " bnb_4bit_quant_type=\"nf4\"\n",
279
+ ")"
280
+ ]
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "execution_count": 11,
285
+ "id": "9ee9c04a-ac4e-406c-b428-b27637ba800a",
286
+ "metadata": {
287
+ "scrolled": true
288
+ },
289
+ "outputs": [
290
+ {
291
+ "data": {
292
+ "application/vnd.jupyter.widget-view+json": {
293
+ "model_id": "61836dfeff334b0285746ce8361a53e9",
294
+ "version_major": 2,
295
+ "version_minor": 0
296
+ },
297
+ "text/plain": [
298
+ "Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]"
299
+ ]
300
+ },
301
+ "metadata": {},
302
+ "output_type": "display_data"
303
+ },
304
+ {
305
+ "name": "stderr",
306
+ "output_type": "stream",
307
+ "text": [
308
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
309
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n",
310
+ "The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
311
+ ]
312
+ },
313
+ {
314
+ "name": "stdout",
315
+ "output_type": "stream",
316
+ "text": [
317
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
318
+ "\n",
319
+ "Cutting Knowledge Date: December 2023\n",
320
+ "Today Date: 26 Jul 2024\n",
321
+ "\n",
322
+ "You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
323
+ "\n",
324
+ "Below is an extract transcript of a a phone call between Tal and friend Gilor. Please write minutes in markdown, including a summary with attendees, location and date; discussion points; takeaways; and action items with owners.\n",
325
+ "Bye.<|eot_id|><|start_header_id|>assistant<|end_header_id|>t bad, man. Thanks for calling me. I appreciate it. Yeah. How did it go yesterday? What did you find out? So I went there and I tried to figure out, first of all, the estimated time and if there is a way I can try to expedite the process. To expedite the process, there's like five reasons that you have to submit, one of the five reasons, and I'm not qualified for any of them. It's like, you don't have money, like bankruptcy, or like you work in the government, or some five things that I don't have any connection to them, or I have like an emergency situation in my life. Unfortunately, I'm not qualified for any of those things. It's like a very severe situation, and thank God I don't have it. So I'm not qualified, eligible for expedition. Try to get some estimated time, the estimated time for the process is six months, which is crazy. But I started that back in December. So I guess June, but I talked to some friends who also received it, and one of them got it in three weeks, one of them got it in three months. I've passed experience one month, one month and a half maybe. So I mean, it's already been almost two months. So I'm hoping to get it in the next few weeks, really hope before the 18th of next month without doing some crazy things in HR and asking some fables, you know. So that's the situation right now. Yeah, and I probably have experience in some hard delays, and yeah, I don't know, it sucks. So that's all it is, is just the US government is now way slower. Yeah, yeah, they just have to, yeah. And what you're waiting on from them is approval to extend your work visa? Yeah. Your student visa, or did you switch from a student to a work? No, I'm not, I don't think I can switch to work yet because I lost a lottery. That's the lottery that I lost in Citi, the H1B. So I try to extend it more a bit. I think the total is like one year, maybe one year and a half, I can extend that to maximum. And it's right now it's pending, and they give me more information also on the website that I can check the case status, it's pending. So I'm checking every day the case, the status, it's pending, waiting for decision, you know. And once there is a decision approved, they like put me in the car and send me to my address, which I can quickly take a picture of it and send to Josh. Okay, and then he can validate you right now? Yeah, he'd be there, like no, you know, like directly go to the Citi HR team, and they directly do it manually, which is like save like a few days, save, it's pretty good. Yeah, so really, everybody will like helpful. So I just have to wait a bit. I didn't have time to update Dave, and I like to try to like log into my... Yeah, don't log in to anything now. Okay, yeah, yeah. Like that'll be, don't do that. I'll call Dave and let him know. And if you want to talk to him, just call his cell phone. Yeah, yeah, I actually have his number, I can talk to him. Yeah, yeah, I wasn't sure if I should. Yeah, exactly. So I didn't have time to talk to Josh a bit, and you, and that's it. And I wanted to like log in later that day, but I forgot about it. And now it's already 19. Yeah, that's all right, man. So your HR called me yesterday. And so you're on, you're on leave right now. Uh-huh. And they reiterated like a hundred times, like, you can't work. I was like, all right, guys, I got it. Yeah, yeah. Stop telling me. You can't work. You're on leave. And they'll, yeah, I mean, just keep, I'll check in with you. Keep me posted on what you hear from immigration or from DHS or whatever the department is that's doing it. Checking in with you. Yeah. Yeah, we'll hold that until you get your extension. Yeah. And I guess, I mean, next time around, like, you don't, like, just go ahead and submit it without waiting for the H-1B, right? Put it in in, like, June. Yeah, I didn't do it because I, from past experience, it's like one month taken. So I thought, like, December is, like, pretty good. Like, I have, like, until February 18. It's like, you have twice the time you need. Yeah. Because I don't want, like, to, I didn't want it to affect the H-1B or something. Maybe it would decline or something. So, also, it does cost some money to submit it. So I was waiting for the H-1B first. Yeah. No, no. But, yeah, I didn't expect it to happen like that. Listen, I'm still waiting to get approved. I hope they approve it. I mean, I can tell you once on the show they wouldn't approve it. But I think they would because I don't see a reason why not. And that's it. I'm just waiting. It's still pending. That's the status name. It's, like, pending for decision. And, I mean, that's the name of the status. And, yeah, man, I will just keep you updated. Let me know what is needed. Call me. We can talk. And I will try to help what I can over the phone or something. The MCA is almost ready. All the calculations are ready there. I'm not sure if they will get approved, actually. I was thinking about it. Since we removed the ML, so there's no... It's a big component from the AI. It's an AI component and we removed it. Now it's not an AI anymore. It's a chatbot. Got it. Yeah. Yeah. I might have... Well, I don't know. I'll talk to Vikash and go over it. I'll call you if I... Yeah, you can try to, like, submit it. I mean, see what's happening. But I think the worst case, just, you know, deploy the bot, how we intended that. I don't think it's a big deal. I don't think it will affect anything. You will still have all the patterns, only a few ML autoances and it's fine. I mean, it's an option. Just think about it. I don't think it's a big deal. Yeah. Hopefully I will come back soon and try to work things out. Yeah. I hope so too, buddy. Keep my fingers crossed that way. In the meantime, I guess, I mean, being on unpaid leave stinks. Hopefully it's not too long and hopefully you're covered and okay in that regard. I did save some money. It's not free to live in New York. No, no. I saved some money for a rainy day. But, yeah. I hope it will move fast soon. And, you know, again, as we talk, I won't be offended if you open the position. We're going to hold off on that for at least a little while. Okay. Sounds fair. Cool, man. That's enough. Anything I can help? I'll be available. All right, brother. Thank you, Dal. Thanks for the update, man. I just wanted to connect with you. Yeah, yeah. Thank you. Thank you. Yeah. Okay. Sounds good. Thank you. \n",
326
+ "\n",
327
+ "**Minutes of Phone Call**\n",
328
+ "=========================\n",
329
+ "\n",
330
+ "**Summary**\n",
331
+ "-----------\n",
332
+ "\n",
333
+ "* Attendees: Tal and Gilor\n",
334
+ "* Location: Remote\n",
335
+ "* Date: [Current Date]\n",
336
+ "\n",
337
+ "**Discussion Points**\n",
338
+ "-------------------\n",
339
+ "\n",
340
+ "* Gilor's situation with the US government regarding his work visa extension\n",
341
+ "* Estimated time for the process, which is six months\n",
342
+ "* Gilor's experience with delays and his hope to get the extension before the 18th of next month\n",
343
+ "* Discussion about not working while on leave and keeping Gilor posted on updates from immigration or DHS\n",
344
+ "* Gilor's decision to submit the extension without waiting for the H-1B and the potential consequences\n",
345
+ "* Update on the MCA project and the removal of the ML component, which affects the project's status as an AI\n",
346
+ "\n",
347
+ "**Takeaways**\n",
348
+ "------------\n",
349
+ "\n",
350
+ "* Gilor's work visa extension is pending and he is waiting for a decision\n",
351
+ "* Gilor is on unpaid leave and is hoping to get his extension approved soon\n",
352
+ "* The MCA project may be affected by the removal of the ML component\n",
353
+ "\n",
354
+ "**Action Items**\n",
355
+ "----------------\n",
356
+ "\n",
357
+ "* Gilor will keep Tal updated on the status of his work visa extension\n",
358
+ "* Tal will keep Gilor posted on updates from immigration or DHS\n",
359
+ "* Gilor will talk to Vikash about the MCA project and consider submitting it without the ML component\n",
360
+ "* Tal will consider opening the position for the MCA project if Gilor is unable to return to work soon\n",
361
+ "\n",
362
+ "**Owners**\n",
363
+ "----------\n",
364
+ "\n",
365
+ "* Gilor: Work visa extension, MCA project\n",
366
+ "* Tal: Keeping Gilor posted on updates from immigration or DHS, considering opening the position for the MCA project<|eot_id|>\n"
367
+ ]
368
+ }
369
+ ],
370
+ "source": [
371
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
372
+ "tokenizer.pad_token = tokenizer.eos_token\n",
373
+ "inputs = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
374
+ "streamer = TextStreamer(tokenizer)\n",
375
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"auto\", quantization_config=quant_config)\n",
376
+ "outputs = model.generate(inputs, max_new_tokens=2000, streamer=streamer)"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "execution_count": 12,
382
+ "id": "affcfec9-9e06-44f0-937b-17527922144a",
383
+ "metadata": {},
384
+ "outputs": [],
385
+ "source": [
386
+ "response = tokenizer.decode(outputs[0])"
387
+ ]
388
+ },
389
+ {
390
+ "cell_type": "code",
391
+ "execution_count": 13,
392
+ "id": "bca5e33b-9546-4717-9fba-449c11b7f45e",
393
+ "metadata": {
394
+ "scrolled": true
395
+ },
396
+ "outputs": [
397
+ {
398
+ "data": {
399
+ "text/markdown": [
400
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
401
+ "\n",
402
+ "Cutting Knowledge Date: December 2023\n",
403
+ "Today Date: 26 Jul 2024\n",
404
+ "\n",
405
+ "You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
406
+ "\n",
407
+ "Below is an extract transcript of a a phone call between Tal and friend Gilor. Please write minutes in markdown, including a summary with attendees, location and date; discussion points; takeaways; and action items with owners.\n",
408
+ "Hey brother, how are you doing? Good. How are you doing? Not bad, man. Thanks for calling me. I appreciate it. Yeah. How did it go yesterday? What did you find out? So I went there and I tried to figure out, first of all, the estimated time and if there is a way I can try to expedite the process. To expedite the process, there's like five reasons that you have to submit, one of the five reasons, and I'm not qualified for any of them. It's like, you don't have money, like bankruptcy, or like you work in the government, or some five things that I don't have any connection to them, or I have like an emergency situation in my life. Unfortunately, I'm not qualified for any of those things. It's like a very severe situation, and thank God I don't have it. So I'm not qualified, eligible for expedition. Try to get some estimated time, the estimated time for the process is six months, which is crazy. But I started that back in December. So I guess June, but I talked to some friends who also received it, and one of them got it in three weeks, one of them got it in three months. I've passed experience one month, one month and a half maybe. So I mean, it's already been almost two months. So I'm hoping to get it in the next few weeks, really hope before the 18th of next month without doing some crazy things in HR and asking some fables, you know. So that's the situation right now. Yeah, and I probably have experience in some hard delays, and yeah, I don't know, it sucks. So that's all it is, is just the US government is now way slower. Yeah, yeah, they just have to, yeah. And what you're waiting on from them is approval to extend your work visa? Yeah. Your student visa, or did you switch from a student to a work? No, I'm not, I don't think I can switch to work yet because I lost a lottery. That's the lottery that I lost in Citi, the H1B. So I try to extend it more a bit. I think the total is like one year, maybe one year and a half, I can extend that to maximum. And it's right now it's pending, and they give me more information also on the website that I can check the case status, it's pending. So I'm checking every day the case, the status, it's pending, waiting for decision, you know. And once there is a decision approved, they like put me in the car and send me to my address, which I can quickly take a picture of it and send to Josh. Okay, and then he can validate you right now? Yeah, he'd be there, like no, you know, like directly go to the Citi HR team, and they directly do it manually, which is like save like a few days, save, it's pretty good. Yeah, so really, everybody will like helpful. So I just have to wait a bit. I didn't have time to update Dave, and I like to try to like log into my... Yeah, don't log in to anything now. Okay, yeah, yeah. Like that'll be, don't do that. I'll call Dave and let him know. And if you want to talk to him, just call his cell phone. Yeah, yeah, I actually have his number, I can talk to him. Yeah, yeah, I wasn't sure if I should. Yeah, exactly. So I didn't have time to talk to Josh a bit, and you, and that's it. And I wanted to like log in later that day, but I forgot about it. And now it's already 19. Yeah, that's all right, man. So your HR called me yesterday. And so you're on, you're on leave right now. Uh-huh. And they reiterated like a hundred times, like, you can't work. I was like, all right, guys, I got it. Yeah, yeah. Stop telling me. You can't work. You're on leave. And they'll, yeah, I mean, just keep, I'll check in with you. Keep me posted on what you hear from immigration or from DHS or whatever the department is that's doing it. Checking in with you. Yeah. Yeah, we'll hold that until you get your extension. Yeah. And I guess, I mean, next time around, like, you don't, like, just go ahead and submit it without waiting for the H-1B, right? Put it in in, like, June. Yeah, I didn't do it because I, from past experience, it's like one month taken. So I thought, like, December is, like, pretty good. Like, I have, like, until February 18. It's like, you have twice the time you need. Yeah. Because I don't want, like, to, I didn't want it to affect the H-1B or something. Maybe it would decline or something. So, also, it does cost some money to submit it. So I was waiting for the H-1B first. Yeah. No, no. But, yeah, I didn't expect it to happen like that. Listen, I'm still waiting to get approved. I hope they approve it. I mean, I can tell you once on the show they wouldn't approve it. But I think they would because I don't see a reason why not. And that's it. I'm just waiting. It's still pending. That's the status name. It's, like, pending for decision. And, I mean, that's the name of the status. And, yeah, man, I will just keep you updated. Let me know what is needed. Call me. We can talk. And I will try to help what I can over the phone or something. The MCA is almost ready. All the calculations are ready there. I'm not sure if they will get approved, actually. I was thinking about it. Since we removed the ML, so there's no... It's a big component from the AI. It's an AI component and we removed it. Now it's not an AI anymore. It's a chatbot. Got it. Yeah. Yeah. I might have... Well, I don't know. I'll talk to Vikash and go over it. I'll call you if I... Yeah, you can try to, like, submit it. I mean, see what's happening. But I think the worst case, just, you know, deploy the bot, how we intended that. I don't think it's a big deal. I don't think it will affect anything. You will still have all the patterns, only a few ML autoances and it's fine. I mean, it's an option. Just think about it. I don't think it's a big deal. Yeah. Hopefully I will come back soon and try to work things out. Yeah. I hope so too, buddy. Keep my fingers crossed that way. In the meantime, I guess, I mean, being on unpaid leave stinks. Hopefully it's not too long and hopefully you're covered and okay in that regard. I did save some money. It's not free to live in New York. No, no. I saved some money for a rainy day. But, yeah. I hope it will move fast soon. And, you know, again, as we talk, I won't be offended if you open the position. We're going to hold off on that for at least a little while. Okay. Sounds fair. Cool, man. That's enough. Anything I can help? I'll be available. All right, brother. Thank you, Dal. Thanks for the update, man. I just wanted to connect with you. Yeah, yeah. Thank you. Thank you. Yeah. Okay. Sounds good. Thank you. Bye.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
409
+ "\n",
410
+ "**Minutes of Phone Call**\n",
411
+ "=========================\n",
412
+ "\n",
413
+ "**Summary**\n",
414
+ "-----------\n",
415
+ "\n",
416
+ "* Attendees: Tal and Gilor\n",
417
+ "* Location: Remote\n",
418
+ "* Date: [Current Date]\n",
419
+ "\n",
420
+ "**Discussion Points**\n",
421
+ "-------------------\n",
422
+ "\n",
423
+ "* Gilor's situation with the US government regarding his work visa extension\n",
424
+ "* Estimated time for the process, which is six months\n",
425
+ "* Gilor's experience with delays and his hope to get the extension before the 18th of next month\n",
426
+ "* Discussion about not working while on leave and keeping Gilor posted on updates from immigration or DHS\n",
427
+ "* Gilor's decision to submit the extension without waiting for the H-1B and the potential consequences\n",
428
+ "* Update on the MCA project and the removal of the ML component, which affects the project's status as an AI\n",
429
+ "\n",
430
+ "**Takeaways**\n",
431
+ "------------\n",
432
+ "\n",
433
+ "* Gilor's work visa extension is pending and he is waiting for a decision\n",
434
+ "* Gilor is on unpaid leave and is hoping to get his extension approved soon\n",
435
+ "* The MCA project may be affected by the removal of the ML component\n",
436
+ "\n",
437
+ "**Action Items**\n",
438
+ "----------------\n",
439
+ "\n",
440
+ "* Gilor will keep Tal updated on the status of his work visa extension\n",
441
+ "* Tal will keep Gilor posted on updates from immigration or DHS\n",
442
+ "* Gilor will talk to Vikash about the MCA project and consider submitting it without the ML component\n",
443
+ "* Tal will consider opening the position for the MCA project if Gilor is unable to return to work soon\n",
444
+ "\n",
445
+ "**Owners**\n",
446
+ "----------\n",
447
+ "\n",
448
+ "* Gilor: Work visa extension, MCA project\n",
449
+ "* Tal: Keeping Gilor posted on updates from immigration or DHS, considering opening the position for the MCA project<|eot_id|>"
450
+ ],
451
+ "text/plain": [
452
+ "<IPython.core.display.Markdown object>"
453
+ ]
454
+ },
455
+ "metadata": {},
456
+ "output_type": "display_data"
457
+ }
458
+ ],
459
+ "source": [
460
+ "display(Markdown(response))"
461
+ ]
462
+ }
463
+ ],
464
+ "metadata": {
465
+ "kernelspec": {
466
+ "display_name": "Python 3 (ipykernel)",
467
+ "language": "python",
468
+ "name": "python3"
469
+ },
470
+ "language_info": {
471
+ "codemirror_mode": {
472
+ "name": "ipython",
473
+ "version": 3
474
+ },
475
+ "file_extension": ".py",
476
+ "mimetype": "text/x-python",
477
+ "name": "python",
478
+ "nbconvert_exporter": "python",
479
+ "pygments_lexer": "ipython3",
480
+ "version": "3.11.11"
481
+ }
482
+ },
483
+ "nbformat": 4,
484
+ "nbformat_minor": 5
485
+ }
.ipynb_checkpoints/Audio_Summarizer-checkpoint.ipynb ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "f52d28db-f259-4c69-b5cf-5ae7abd53db6",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import torch\n",
20
+ "from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, BitsAndBytesConfig, AutoProcessor, AutoModelForSpeechSeq2Seq\n",
21
+ "import gradio as gr"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 2,
27
+ "id": "ce0248ea-ff88-451f-a979-79fdf0568d9b",
28
+ "metadata": {
29
+ "scrolled": true
30
+ },
31
+ "outputs": [],
32
+ "source": [
33
+ "quant_config = BitsAndBytesConfig(\n",
34
+ " load_in_4bit=True,\n",
35
+ " bnb_4bit_use_double_quant=True,\n",
36
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
37
+ " bnb_4bit_quant_type=\"nf4\"\n",
38
+ ")"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": 3,
44
+ "id": "6995d1d2-524b-4c14-ac4f-432262b7b1f8",
45
+ "metadata": {
46
+ "scrolled": true
47
+ },
48
+ "outputs": [
49
+ {
50
+ "name": "stderr",
51
+ "output_type": "stream",
52
+ "text": [
53
+ "Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:36<00:00, 9.13s/it]\n"
54
+ ]
55
+ }
56
+ ],
57
+ "source": [
58
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
59
+ "device = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n",
60
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
61
+ "tokenizer.pad_token = tokenizer.eos_token\n",
62
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"cuda:0\", quantization_config=quant_config)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 4,
68
+ "id": "e5b240f5-88a0-4ecf-8659-3a7eb8447307",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "def transcript_audio(audio_file):\n",
73
+ " torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32\n",
74
+ " \n",
75
+ " model_id = \"openai/whisper-large-v3-turbo\"\n",
76
+ " \n",
77
+ " model = AutoModelForSpeechSeq2Seq.from_pretrained(\n",
78
+ " model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True\n",
79
+ " )\n",
80
+ " model.to(device)\n",
81
+ " \n",
82
+ " processor = AutoProcessor.from_pretrained(model_id)\n",
83
+ " \n",
84
+ " pipe = pipeline(\n",
85
+ " \"automatic-speech-recognition\",\n",
86
+ " model=model,\n",
87
+ " tokenizer=processor.tokenizer,\n",
88
+ " feature_extractor=processor.feature_extractor,\n",
89
+ " torch_dtype=torch_dtype,\n",
90
+ " device=device,\n",
91
+ " )\n",
92
+ " \n",
93
+ " result = pipe(audio_file, return_timestamps=True)\n",
94
+ " return result"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 5,
100
+ "id": "c8301e0d-ec49-45a6-8d2e-7247c91c8b80",
101
+ "metadata": {},
102
+ "outputs": [],
103
+ "source": [
104
+ "def summarize_with_llama(transcript, context=\"Phone Call\"):\n",
105
+ " if context == \"Phone Call\":\n",
106
+ " system_message = (\n",
107
+ " \"You are an assistant that produces minutes of phone call from transcripts, \"\n",
108
+ " \"with summary and key discussion points, in markdown.\"\n",
109
+ " )\n",
110
+ " user_prompt = (\n",
111
+ " \"Below is an extract transcript of a phone call. \"\n",
112
+ " \"Please write minutes in markdown, including a summary, location and discussion points.\"\n",
113
+ " )\n",
114
+ " elif context == \"Meeting\":\n",
115
+ " system_message = (\n",
116
+ " \"You are an assistant that produces minutes of meetings from transcripts, \"\n",
117
+ " \"with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
118
+ " )\n",
119
+ " user_prompt = (\n",
120
+ " \"Below is an extract transcript of a Denver council meeting. \"\n",
121
+ " \"Please write minutes in markdown, including a summary with attendees, location and date; \"\n",
122
+ " \"discussion points; takeaways; and action items with owners.\"\n",
123
+ " )\n",
124
+ " else:\n",
125
+ " raise ValueError(f\"Unknown context: {context}\")\n",
126
+ "\n",
127
+ " messages = [\n",
128
+ " {\"role\": \"system\", \"content\": system_message},\n",
129
+ " {\"role\": \"user\", \"content\": f\"{user_prompt}\\n\\n{transcript}\"}\n",
130
+ " ]\n",
131
+ "\n",
132
+ " input_features = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
133
+ " output_ids = model.generate(input_features, max_new_tokens=2000)\n",
134
+ " summary = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()\n",
135
+ " return summary"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "execution_count": 6,
141
+ "id": "a54ee711-97d3-4f18-8006-ef02812b125a",
142
+ "metadata": {},
143
+ "outputs": [],
144
+ "source": [
145
+ "def transcribe_and_summarize(audio, choices):\n",
146
+ " try:\n",
147
+ " result = transcript_audio(audio)\n",
148
+ " transcript = result[\"text\"]\n",
149
+ " return summarize_with_llama(transcript, context=choices)\n",
150
+ " except Exception as e:\n",
151
+ " return f\"**Error:** {str(e)}\""
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "execution_count": 12,
157
+ "id": "5e7b676e-93c5-4744-8fa9-9f779ffe7ab6",
158
+ "metadata": {},
159
+ "outputs": [
160
+ {
161
+ "name": "stdout",
162
+ "output_type": "stream",
163
+ "text": [
164
+ "* Running on local URL: http://127.0.0.1:7863\n",
165
+ "\n",
166
+ "To create a public link, set `share=True` in `launch()`.\n"
167
+ ]
168
+ },
169
+ {
170
+ "data": {
171
+ "text/html": [
172
+ "<div><iframe src=\"http://127.0.0.1:7863/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
173
+ ],
174
+ "text/plain": [
175
+ "<IPython.core.display.HTML object>"
176
+ ]
177
+ },
178
+ "metadata": {},
179
+ "output_type": "display_data"
180
+ },
181
+ {
182
+ "data": {
183
+ "text/plain": []
184
+ },
185
+ "execution_count": 12,
186
+ "metadata": {},
187
+ "output_type": "execute_result"
188
+ },
189
+ {
190
+ "name": "stderr",
191
+ "output_type": "stream",
192
+ "text": [
193
+ "Device set to use cuda:0\n",
194
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
195
+ " warnings.warn(\n",
196
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
197
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
198
+ ]
199
+ }
200
+ ],
201
+ "source": [
202
+ "gr.Interface(\n",
203
+ " fn=transcribe_and_summarize,\n",
204
+ " inputs=[\n",
205
+ " gr.Audio(type=\"filepath\", label=\"Upload Audio\"),\n",
206
+ " gr.Radio([\"Phone Call\", \"Meeting\"], label=\"Select Audio Type\")\n",
207
+ " ],\n",
208
+ " outputs=gr.Markdown(height=1000),\n",
209
+ " title=\"Audio Summarizer\"\n",
210
+ ").launch()"
211
+ ]
212
+ }
213
+ ],
214
+ "metadata": {
215
+ "kernelspec": {
216
+ "display_name": "Python 3 (ipykernel)",
217
+ "language": "python",
218
+ "name": "python3"
219
+ },
220
+ "language_info": {
221
+ "codemirror_mode": {
222
+ "name": "ipython",
223
+ "version": 3
224
+ },
225
+ "file_extension": ".py",
226
+ "mimetype": "text/x-python",
227
+ "name": "python",
228
+ "nbconvert_exporter": "python",
229
+ "pygments_lexer": "ipython3",
230
+ "version": "3.11.11"
231
+ }
232
+ },
233
+ "nbformat": 4,
234
+ "nbformat_minor": 5
235
+ }
.ipynb_checkpoints/environment-checkpoint.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: app
2
+ channels:
3
+ - defaults
4
+ - conda-forge
5
+ dependencies:
6
+ - python=3.11
7
+ - pip
8
+ - pytorch
9
+ - datasets
10
+ - transformers
11
+ - tqdm
12
+ - bitsandbytes
13
+ - gradio
14
+ - scikit-learn
15
+ - matplotlib
16
+ - dotenv
17
+ - notebook
18
+ - numpy
19
+ - pip:
20
+ - openai-whisper
21
+ - torch==2.2.1+cu126
22
+ - torchvision==0.17.1+cu126
23
+ - torchaudio==2.2.1+cu126
24
+ - --extra-index-url https://download.pytorch.org/whl/cu126
.ipynb_checkpoints/pipeline-backup-checkpoint.ipynb ADDED
@@ -0,0 +1,460 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "f52d28db-f259-4c69-b5cf-5ae7abd53db6",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import torch\n",
20
+ "from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, TextStreamer, BitsAndBytesConfig\n",
21
+ "import gradio as gr"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 3,
27
+ "id": "b650ef06-b522-4abf-a458-fc8a70042654",
28
+ "metadata": {},
29
+ "outputs": [
30
+ {
31
+ "name": "stdout",
32
+ "output_type": "stream",
33
+ "text": [
34
+ "CUDA Available: True\n",
35
+ "Number of GPUs: 1\n",
36
+ "Current CUDA Device: NVIDIA GeForce RTX 4060 Laptop GPU\n"
37
+ ]
38
+ }
39
+ ],
40
+ "source": [
41
+ "# Check if CUDA is available\n",
42
+ "print(\"CUDA Available: \", torch.cuda.is_available())\n",
43
+ "\n",
44
+ "# List available GPUs\n",
45
+ "print(\"Number of GPUs: \", torch.cuda.device_count())\n",
46
+ "\n",
47
+ "# Get the name of the current device\n",
48
+ "print(\"Current CUDA Device: \", torch.cuda.get_device_name(torch.cuda.current_device()))"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": 4,
54
+ "id": "5d474901-bc98-4f48-9cd4-016cd39d8726",
55
+ "metadata": {},
56
+ "outputs": [
57
+ {
58
+ "name": "stderr",
59
+ "output_type": "stream",
60
+ "text": [
61
+ "Device set to use cuda:0\n"
62
+ ]
63
+ }
64
+ ],
65
+ "source": [
66
+ "asr_pipeline = pipeline(\"automatic-speech-recognition\", model=\"openai/whisper-large-v2\")"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 5,
72
+ "id": "ce0248ea-ff88-451f-a979-79fdf0568d9b",
73
+ "metadata": {
74
+ "scrolled": true
75
+ },
76
+ "outputs": [],
77
+ "source": [
78
+ "quant_config = BitsAndBytesConfig(\n",
79
+ " load_in_4bit=True,\n",
80
+ " bnb_4bit_use_double_quant=True,\n",
81
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
82
+ " bnb_4bit_quant_type=\"nf4\"\n",
83
+ ")"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "execution_count": 6,
89
+ "id": "6995d1d2-524b-4c14-ac4f-432262b7b1f8",
90
+ "metadata": {},
91
+ "outputs": [
92
+ {
93
+ "name": "stderr",
94
+ "output_type": "stream",
95
+ "text": [
96
+ "Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:50<00:00, 12.56s/it]\n"
97
+ ]
98
+ }
99
+ ],
100
+ "source": [
101
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
102
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
103
+ "tokenizer.pad_token = tokenizer.eos_token\n",
104
+ "streamer = TextStreamer(tokenizer)\n",
105
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"cuda:0\", quantization_config=quant_config, low_cpu_mem_usage=True)"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": 10,
111
+ "id": "992e5543-0cab-4669-be4a-4a88d5677d5d",
112
+ "metadata": {},
113
+ "outputs": [],
114
+ "source": [
115
+ "def summarize_with_llama(transcript):\n",
116
+ " system_message = \"You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
117
+ " user_prompt = f\"Below is an extract transcript of a a phone call. Please write minutes in markdown, including a summary, location and date; discussion points; takeaways; and action items with owners.\\n\\n{transcript}\"\n",
118
+ "\n",
119
+ "\n",
120
+ " messages = [\n",
121
+ " {\"role\": \"system\", \"content\": system_message},\n",
122
+ " {\"role\": \"user\", \"content\": user_prompt}\n",
123
+ " ]\n",
124
+ "\n",
125
+ " inputs = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
126
+ " outputs = model.generate(inputs, max_new_tokens=2000, streamer=streamer)\n",
127
+ "\n",
128
+ " summary = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
129
+ " return summary"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 8,
135
+ "id": "dbe7e485-e197-4631-895f-42f8b457ec04",
136
+ "metadata": {},
137
+ "outputs": [],
138
+ "source": [
139
+ "def summarize_audio(audio_file):\n",
140
+ " # Whisper pipeline automatically handles MP3, WAV, etc.\n",
141
+ " result = asr_pipeline(audio_file, return_timestamps=True)\n",
142
+ " return result # {'text': 'transcribed text here'}"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": 9,
148
+ "id": "ec8c7220-0b3f-4943-a49b-7adacf1290d9",
149
+ "metadata": {},
150
+ "outputs": [
151
+ {
152
+ "name": "stderr",
153
+ "output_type": "stream",
154
+ "text": [
155
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
156
+ " warnings.warn(\n",
157
+ "Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`.\n"
158
+ ]
159
+ },
160
+ {
161
+ "data": {
162
+ "text/plain": [
163
+ "{'text': \" Hello? Hi, my name is Tal. Two months ago, I was even more in December, I went to you for a test for the issue that I submit everything to the government for the green card, but they told me there was an issue with the documents and I need to get a new one. Is there a chance you can provide me the same document like last time? in your system? Yes, come tomorrow. I'm not in New York. There is a way to do it. I can pay you, I can send you my credit card or something, but is there a chance to do it when I'm not in New York? Like to get the same? No, because you have to be an original. You have to be in person. Yeah, but… When will you be back in New York? When are you? You're in Israel? Yes, I'm in Israel, yes. I'm not sure when I'm going to be back. I'm not sure when I'm going to be back. I'm not sure when I'm going to be back. I'm not sure when I'm going to be back. I'm not sure when I'm going to be back. I'm not sure when I'm going to be back. I'm not sure when I'll be back, but my question is, is the same result that I got from you in December, is there a way you can print them again? Yes, we can, but the problem is they don't take copies. So maybe I can send someone to take it? When would you be back in New York? I'm not sure. I'm not sure. things in the military, back in the military reserve. So I'm not sure when I'll be back. Maybe I can send one of my friends, also from Israel, he can pay you or anything, he can come tomorrow maybe? The problem is... What's the problem? The problem is, why don't you send me a copy of the letter that you received? OK, I will send you a copy of the letter. Do you have an email or something? The email is D as in Doctor, B as in David, R as in Robert, J as in John, T as in Peter, Simon, S-I-M-O-N-A-J-O-L dot com. OK, I will email you what they tell me, told me and then call me back so we can look. OK, thank you very much. OK, thank you. Thank you. Bye.\",\n",
164
+ " 'chunks': [{'timestamp': (0.0, 7.0), 'text': ' Hello?'},\n",
165
+ " {'timestamp': (7.0, 24.44), 'text': ' Hi, my name is Tal.'},\n",
166
+ " {'timestamp': (24.44, 0.0), 'text': ''},\n",
167
+ " {'timestamp': (11.64, 15.56),\n",
168
+ " 'text': ' Two months ago, I was even more in December, I went to you for a test for the issue that I submit everything to the government for the green card, but they told me there was'},\n",
169
+ " {'timestamp': (15.56, 22.4),\n",
170
+ " 'text': ' an issue with the documents and I need to get a new one.'},\n",
171
+ " {'timestamp': (22.4, 27.16),\n",
172
+ " 'text': ' Is there a chance you can provide me the same document like last time?'},\n",
173
+ " {'timestamp': (27.16, 0.0), 'text': ''},\n",
174
+ " {'timestamp': (1.0, 2.0), 'text': ' in your system? Yes, come tomorrow.'},\n",
175
+ " {'timestamp': (2.0, 3.0), 'text': \" I'm not in New York.\"},\n",
176
+ " {'timestamp': (3.0, 7.0), 'text': ' There is a way to do it.'},\n",
177
+ " {'timestamp': (7.0, 12.8),\n",
178
+ " 'text': ' I can pay you, I can send you my credit card or something, but is there a chance to do'},\n",
179
+ " {'timestamp': (12.8, 15.24), 'text': \" it when I'm not in New York?\"},\n",
180
+ " {'timestamp': (15.24, 16.24), 'text': ' Like to get the same?'},\n",
181
+ " {'timestamp': (16.24, 17.24),\n",
182
+ " 'text': ' No, because you have to be an original.'},\n",
183
+ " {'timestamp': (17.24, 18.24), 'text': ' You have to be in person.'},\n",
184
+ " {'timestamp': (18.24, 19.24), 'text': ' Yeah, but…'},\n",
185
+ " {'timestamp': (19.24, 20.24), 'text': ' When will you be back in New York?'},\n",
186
+ " {'timestamp': (20.24, 21.24), 'text': ' When are you?'},\n",
187
+ " {'timestamp': (21.24, 22.24), 'text': \" You're in Israel?\"},\n",
188
+ " {'timestamp': (22.24, 23.24), 'text': \" Yes, I'm in Israel, yes.\"},\n",
189
+ " {'timestamp': (23.24, 24.24),\n",
190
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
191
+ " {'timestamp': (24.24, 25.24),\n",
192
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
193
+ " {'timestamp': (25.24, 26.24),\n",
194
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
195
+ " {'timestamp': (26.24, 27.24),\n",
196
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
197
+ " {'timestamp': (27.24, 28.24),\n",
198
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
199
+ " {'timestamp': (28.24, 29.24),\n",
200
+ " 'text': \" I'm not sure when I'm going to be back.\"},\n",
201
+ " {'timestamp': (29.24, 0.0), 'text': ''},\n",
202
+ " {'timestamp': (5.76, 8.96),\n",
203
+ " 'text': \" I'm not sure when I'll be back, but my question is, is the same result that I got from you in December, is there a way you can print them again?\"},\n",
204
+ " {'timestamp': (8.96, 14.92),\n",
205
+ " 'text': \" Yes, we can, but the problem is they don't take copies.\"},\n",
206
+ " {'timestamp': (14.92, 19.0),\n",
207
+ " 'text': ' So maybe I can send someone to take it?'},\n",
208
+ " {'timestamp': (19.0, 24.8), 'text': ' When would you be back in New York?'},\n",
209
+ " {'timestamp': (24.8, 25.8), 'text': \" I'm not sure.\"},\n",
210
+ " {'timestamp': (25.8, 26.8), 'text': \" I'm not sure.\"},\n",
211
+ " {'timestamp': (26.8, 0.0), 'text': ''},\n",
212
+ " {'timestamp': (5.92, 10.7),\n",
213
+ " 'text': \" things in the military, back in the military reserve. So I'm not sure when I'll be back.\"},\n",
214
+ " {'timestamp': (10.7, 15.74),\n",
215
+ " 'text': ' Maybe I can send one of my friends, also from Israel, he can pay you or anything, he can'},\n",
216
+ " {'timestamp': (15.74, 17.74), 'text': ' come tomorrow maybe?'},\n",
217
+ " {'timestamp': (17.74, 18.74), 'text': ' The problem is...'},\n",
218
+ " {'timestamp': (18.74, 19.74), 'text': \" What's the problem?\"},\n",
219
+ " {'timestamp': (19.74, 28.14),\n",
220
+ " 'text': \" The problem is, why don't you send me a copy of the letter that you received?\"},\n",
221
+ " {'timestamp': (28.14, 0.0), 'text': ''},\n",
222
+ " {'timestamp': (2.2, 3.72),\n",
223
+ " 'text': ' OK, I will send you a copy of the letter. Do you have an email or something?'},\n",
224
+ " {'timestamp': (3.72, 12.8),\n",
225
+ " 'text': ' The email is D as in Doctor, B as in David, R as in Robert, J as in John, T as in Peter,'},\n",
226
+ " {'timestamp': (12.8, 15.4), 'text': ' Simon, S-I-M-O-N-A-J-O-L dot com.'},\n",
227
+ " {'timestamp': (16.32, 22.04),\n",
228
+ " 'text': ' OK, I will email you what they tell me, told me and then call me back so we can look.'},\n",
229
+ " {'timestamp': (22.56, 23.76), 'text': ' OK, thank you very much.'},\n",
230
+ " {'timestamp': (25.04, 26.12), 'text': ' OK, thank you.'},\n",
231
+ " {'timestamp': (26.16, 26.76), 'text': ' Thank you. Bye.'}]}"
232
+ ]
233
+ },
234
+ "execution_count": 9,
235
+ "metadata": {},
236
+ "output_type": "execute_result"
237
+ }
238
+ ],
239
+ "source": [
240
+ "summarize_audio(\"phone_20250318-180750__16468561121.amr\")"
241
+ ]
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "execution_count": 9,
246
+ "id": "6e6c8b1f-20d1-4eb1-99be-3a3ba4a13b83",
247
+ "metadata": {},
248
+ "outputs": [],
249
+ "source": [
250
+ "def transcribe_and_summarize(audio):\n",
251
+ " result = summarize_audio(audio) # Run Whisper ASR\n",
252
+ " transcript = result[\"text\"] # Extract transcript\n",
253
+ " summary = summarize_with_llama(transcript) # Run LLaMA summarizer (already returns string)\n",
254
+ " return summary"
255
+ ]
256
+ },
257
+ {
258
+ "cell_type": "code",
259
+ "execution_count": 12,
260
+ "id": "aa678fda-395a-4509-8580-c885aa86b052",
261
+ "metadata": {
262
+ "scrolled": true
263
+ },
264
+ "outputs": [
265
+ {
266
+ "name": "stdout",
267
+ "output_type": "stream",
268
+ "text": [
269
+ "* Running on local URL: http://127.0.0.1:7861\n",
270
+ "\n",
271
+ "To create a public link, set `share=True` in `launch()`.\n"
272
+ ]
273
+ },
274
+ {
275
+ "data": {
276
+ "text/html": [
277
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
278
+ ],
279
+ "text/plain": [
280
+ "<IPython.core.display.HTML object>"
281
+ ]
282
+ },
283
+ "metadata": {},
284
+ "output_type": "display_data"
285
+ },
286
+ {
287
+ "data": {
288
+ "text/plain": []
289
+ },
290
+ "execution_count": 12,
291
+ "metadata": {},
292
+ "output_type": "execute_result"
293
+ },
294
+ {
295
+ "name": "stderr",
296
+ "output_type": "stream",
297
+ "text": [
298
+ "ERROR: Exception in ASGI application\n",
299
+ "Traceback (most recent call last):\n",
300
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 403, in run_asgi\n",
301
+ " result = await app( # type: ignore[func-returns-value]\n",
302
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
303
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\middleware\\proxy_headers.py\", line 60, in __call__\n",
304
+ " return await self.app(scope, receive, send)\n",
305
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
306
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\fastapi\\applications.py\", line 1054, in __call__\n",
307
+ " await super().__call__(scope, receive, send)\n",
308
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\applications.py\", line 112, in __call__\n",
309
+ " await self.middleware_stack(scope, receive, send)\n",
310
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 187, in __call__\n",
311
+ " raise exc\n",
312
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 165, in __call__\n",
313
+ " await self.app(scope, receive, _send)\n",
314
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\gradio\\route_utils.py\", line 829, in __call__\n",
315
+ " await self.app(scope, receive, send)\n",
316
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\exceptions.py\", line 62, in __call__\n",
317
+ " await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)\n",
318
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
319
+ " raise exc\n",
320
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
321
+ " await app(scope, receive, sender)\n",
322
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 714, in __call__\n",
323
+ " await self.middleware_stack(scope, receive, send)\n",
324
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 734, in app\n",
325
+ " await route.handle(scope, receive, send)\n",
326
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 288, in handle\n",
327
+ " await self.app(scope, receive, send)\n",
328
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 76, in app\n",
329
+ " await wrap_app_handling_exceptions(app, request)(scope, receive, send)\n",
330
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
331
+ " raise exc\n",
332
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
333
+ " await app(scope, receive, sender)\n",
334
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 74, in app\n",
335
+ " await response(scope, receive, send)\n",
336
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 359, in __call__\n",
337
+ " await self._handle_simple(send, send_header_only)\n",
338
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 388, in _handle_simple\n",
339
+ " await send({\"type\": \"http.response.body\", \"body\": chunk, \"more_body\": more_body})\n",
340
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
341
+ " await send(message)\n",
342
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
343
+ " await send(message)\n",
344
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 162, in _send\n",
345
+ " await send(message)\n",
346
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 507, in send\n",
347
+ " output = self.conn.send(event=h11.EndOfMessage())\n",
348
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
349
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 512, in send\n",
350
+ " data_list = self.send_with_data_passthrough(event)\n",
351
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
352
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 545, in send_with_data_passthrough\n",
353
+ " writer(event, data_list.append)\n",
354
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 67, in __call__\n",
355
+ " self.send_eom(event.headers, write)\n",
356
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 96, in send_eom\n",
357
+ " raise LocalProtocolError(\"Too little data for declared Content-Length\")\n",
358
+ "h11._util.LocalProtocolError: Too little data for declared Content-Length\n",
359
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
360
+ " warnings.warn(\n",
361
+ "Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`.\n",
362
+ "Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.\n",
363
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
364
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n",
365
+ "The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
366
+ ]
367
+ },
368
+ {
369
+ "name": "stdout",
370
+ "output_type": "stream",
371
+ "text": [
372
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
373
+ "\n",
374
+ "Cutting Knowledge Date: December 2023\n",
375
+ "Today Date: 26 Jul 2024\n",
376
+ "\n",
377
+ "You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
378
+ "\n",
379
+ "Below is an extract transcript of a a phone call. Please write minutes in markdown, including a summary, location and date; discussion points; takeaways; and action items with owners.\n",
380
+ "\n",
381
+ " How are you? All good. I'm in Israel right now, visiting the family. You're where? In Israel, visiting the family. So can you take international calls without... I do actually. Actually, two cities have the AT&T program, so with the extra fee I can have available. And I did it on purpose so we can talk in case there's something. I don't want it to affect that I just went to visit the situation. So I'm available at any time. OK. Well, I just have this. This is actually, I don't know. So yesterday my boss sent an email to, or sent an IM to my peers and I, right? He said, this is his question, did any of you or anyone on your team get an email stating they are required to take mandatory absence? Right? And everyone said no. And I said, well, I don't know. Tyle may have gotten that email, but I'm not sure. I don't think I got one that was that. And I know you can't log in to email, but before you left, did you see an email that said you are required to take mandatory absence? No, I don't remember having any email of those. The only email related was to update my work authorization. Nothing about mandatory. I mean, the term that Josh uses is leave, But he mentioned me that. I didn't see any email saying the word leave or mandatory absence. I don't. So Josh mentioned something like that? The only, when I asked Josh, I mean, I asked the other guy, Jonathan, the guy under him, what's the status, what's gonna happen after February 18 if I don't have my work authorization? He told me, IME, that I'm gonna be on leave leave. It didn't even say the word mandatory, just a leave. And Josh elaborated about it more to us, but that's it. I didn't have any email. Maybe I got one after, but I didn't see an email. And you would have. I'm going to ask Josh if there was one like that. Yeah, maybe it's like automatic something, but I don't remember anything. I did receive some automatic messages about updating my work authorization. Maybe, maybe in the bottom of the email, there was saying, in case of no updating on time, you will require to be on absent. I don't know. I don't remember anything like that. All I received was automatic messages about updating my work authorization before the 18th. Nothing about mandatory absence. Yeah. OK. OK. When are you going to be back in New York? Yeah. When are you going to be back? Ah, when? I'm not sure. I'm about to one way for now. I'm not sure. I'm checking every day. Whenever I get it, I'm going to fly the same day. I'm going to send it to Josh and my work authorization will fly the same day back. So I'm kind of flexible if that's okay on your side. But yeah, I mean, just, you know, whenever I get it, I'm gonna send it right away to Josh and he's going to process it to HR and I'm gonna fly the same night already. Yeah. Yeah. Jeremiah and I posted with what's going on, but I did want to touch base with you and see. I don't know why he's asking this, but it would seem like it would probably be something that was raised up with respect to your situation. I mean, I would... It makes sense, yeah. Yeah, it does make sense to me. Or it's awfully ironic. All of your employees are probably legal to work, so kind of maybe mean, but I don't remember anything like that. What's the issue? What's the issue? You think there's a problem here or something? I don't think it's a problem. I think it probably went to his boss, and his boss asked about it. So he's wanted to verify. But he knows the situation, because I've told him. Well, it's good that the big boss knows me, right? I didn't expect him to know me like that, but it's better than nothing. Yeah. Yeah. Yeah. Sorry about it, but I guess let's wait a bit more, see what's happening. I told Jeremiah you can call me anytime if there's some question or something like that to work that I could help and I wish I could I wish I could log in but you know I could help but I won't I know it's it's it's a problem so I won't do that of course. Okay okay well I appreciate it. If I have anything I'll let you know. Yeah yeah feel free to message me whatever you want. I'm available. Okay, cool. Thank you. Thank you. Okay, talk to you later. Bye.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
382
+ "\n",
383
+ "**Minutes of Phone Call**\n",
384
+ "==========================\n",
385
+ "\n",
386
+ "**Location:** Israel\n",
387
+ "**Date:** Today (26 Jul 2024)\n",
388
+ "\n",
389
+ "**Summary**\n",
390
+ "-----------\n",
391
+ "\n",
392
+ "This phone call was a discussion regarding a situation with an employee's work authorization and potential mandatory absence. The employee was unavailable to log in to their email, and the caller was seeking verification on whether the employee received an email stating they were required to take mandatory absence.\n",
393
+ "\n",
394
+ "**Discussion Points**\n",
395
+ "--------------------\n",
396
+ "\n",
397
+ "* The employee's work authorization was due to be updated, and there was a concern about whether they received an email stating they were required to take mandatory absence.\n",
398
+ "* The employee did not recall receiving such an email, but they did receive automatic messages about updating their work authorization.\n",
399
+ "* The employee's manager, Josh, was mentioned as having discussed the situation with the employee, but the details were not clear.\n",
400
+ "* The employee offered to send their work authorization to Josh as soon as they received it, to facilitate the processing of their paperwork.\n",
401
+ "\n",
402
+ "**Takeaways**\n",
403
+ "------------\n",
404
+ "\n",
405
+ "* The employee's work authorization was due to be updated, and there was a concern about whether they received an email stating they were required to take mandatory absence.\n",
406
+ "* The employee did not recall receiving such an email, but they did receive automatic messages about updating their work authorization.\n",
407
+ "\n",
408
+ "**Action Items**\n",
409
+ "----------------\n",
410
+ "\n",
411
+ "* **Owner:** Employee\n",
412
+ "\t+ Send work authorization to Josh as soon as received.\n",
413
+ "* **Owner:** Josh\n",
414
+ "\t+ Verify with the employee whether they received an email stating they were required to take mandatory absence.\n",
415
+ "\t+ Process the employee's paperwork once they receive their work authorization.\n",
416
+ "* **Owner:** Caller\n",
417
+ "\t+ Follow up with Josh to verify the situation and ensure the employee's paperwork is processed.<|eot_id|>\n"
418
+ ]
419
+ }
420
+ ],
421
+ "source": [
422
+ "gr.Interface(\n",
423
+ " fn=transcribe_and_summarize,\n",
424
+ " inputs=gr.Audio(type=\"filepath\"),\n",
425
+ " outputs=\"text\",\n",
426
+ " title=\"Audio Summarizer\"\n",
427
+ ").launch()"
428
+ ]
429
+ },
430
+ {
431
+ "cell_type": "code",
432
+ "execution_count": null,
433
+ "id": "606fce2d-6dcd-4395-af7d-9d60520be943",
434
+ "metadata": {},
435
+ "outputs": [],
436
+ "source": []
437
+ }
438
+ ],
439
+ "metadata": {
440
+ "kernelspec": {
441
+ "display_name": "Python 3 (ipykernel)",
442
+ "language": "python",
443
+ "name": "python3"
444
+ },
445
+ "language_info": {
446
+ "codemirror_mode": {
447
+ "name": "ipython",
448
+ "version": 3
449
+ },
450
+ "file_extension": ".py",
451
+ "mimetype": "text/x-python",
452
+ "name": "python",
453
+ "nbconvert_exporter": "python",
454
+ "pygments_lexer": "ipython3",
455
+ "version": "3.11.11"
456
+ }
457
+ },
458
+ "nbformat": 4,
459
+ "nbformat_minor": 5
460
+ }
.ipynb_checkpoints/pipeline-checkpoint.ipynb ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "f52d28db-f259-4c69-b5cf-5ae7abd53db6",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import torch\n",
11
+ "from transformers import \n",
12
+ "from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, TextStreamer, BitsAndBytesConfig\n",
13
+ "import gradio as gr"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 3,
19
+ "id": "b650ef06-b522-4abf-a458-fc8a70042654",
20
+ "metadata": {},
21
+ "outputs": [
22
+ {
23
+ "name": "stdout",
24
+ "output_type": "stream",
25
+ "text": [
26
+ "CUDA Available: True\n",
27
+ "Number of GPUs: 1\n",
28
+ "Current CUDA Device: NVIDIA GeForce RTX 4060 Laptop GPU\n"
29
+ ]
30
+ }
31
+ ],
32
+ "source": [
33
+ "# Check if CUDA is available\n",
34
+ "print(\"CUDA Available: \", torch.cuda.is_available())\n",
35
+ "\n",
36
+ "# List available GPUs\n",
37
+ "print(\"Number of GPUs: \", torch.cuda.device_count())\n",
38
+ "\n",
39
+ "# Get the name of the current device\n",
40
+ "print(\"Current CUDA Device: \", torch.cuda.get_device_name(torch.cuda.current_device()))"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": 4,
46
+ "id": "5d474901-bc98-4f48-9cd4-016cd39d8726",
47
+ "metadata": {},
48
+ "outputs": [
49
+ {
50
+ "name": "stderr",
51
+ "output_type": "stream",
52
+ "text": [
53
+ "Device set to use cuda:0\n"
54
+ ]
55
+ }
56
+ ],
57
+ "source": [
58
+ "asr_pipeline = pipeline(\"automatic-speech-recognition\", model=\"openai/whisper-large-v2\")"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": 5,
64
+ "id": "ce0248ea-ff88-451f-a979-79fdf0568d9b",
65
+ "metadata": {
66
+ "scrolled": true
67
+ },
68
+ "outputs": [],
69
+ "source": [
70
+ "quant_config = BitsAndBytesConfig(\n",
71
+ " load_in_4bit=True,\n",
72
+ " bnb_4bit_use_double_quant=True,\n",
73
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
74
+ " bnb_4bit_quant_type=\"nf4\"\n",
75
+ ")"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 6,
81
+ "id": "6995d1d2-524b-4c14-ac4f-432262b7b1f8",
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "name": "stderr",
86
+ "output_type": "stream",
87
+ "text": [
88
+ "Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:38<00:00, 9.70s/it]\n"
89
+ ]
90
+ }
91
+ ],
92
+ "source": [
93
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
94
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
95
+ "tokenizer.pad_token = tokenizer.eos_token\n",
96
+ "streamer = TextStreamer(tokenizer)\n",
97
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"cuda:0\", quantization_config=quant_config, low_cpu_mem_usage=True)"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": 7,
103
+ "id": "992e5543-0cab-4669-be4a-4a88d5677d5d",
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "def summarize_with_llama(transcript):\n",
108
+ " system_message = \"You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
109
+ " user_prompt = f\"Below is an extract transcript of a a phone call. Please write minutes in markdown, including a summary, location and date; discussion points; takeaways; and action items with owners.\\n\\n{transcript}\"\n",
110
+ "\n",
111
+ "\n",
112
+ " messages = [\n",
113
+ " {\"role\": \"system\", \"content\": system_message},\n",
114
+ " {\"role\": \"user\", \"content\": user_prompt}\n",
115
+ " ]\n",
116
+ "\n",
117
+ " inputs = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
118
+ " outputs = model.generate(inputs, max_new_tokens=2000, streamer=streamer)\n",
119
+ "\n",
120
+ " summary = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
121
+ " return summary"
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "execution_count": 11,
127
+ "id": "dbe7e485-e197-4631-895f-42f8b457ec04",
128
+ "metadata": {},
129
+ "outputs": [],
130
+ "source": [
131
+ "def summarize_audio(audio_file):\n",
132
+ " # Whisper pipeline automatically handles MP3, WAV, etc.\n",
133
+ " result = asr_pipeline(audio_file, return_timestamps=True)\n",
134
+ " return result # {'text': 'transcribed text here'}"
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": 9,
140
+ "id": "6e6c8b1f-20d1-4eb1-99be-3a3ba4a13b83",
141
+ "metadata": {},
142
+ "outputs": [],
143
+ "source": [
144
+ "def transcribe_and_summarize(audio):\n",
145
+ " result = summarize_audio(audio) # Run Whisper ASR\n",
146
+ " transcript = result[\"text\"] # Extract transcript\n",
147
+ " summary = summarize_with_llama(transcript) # Run LLaMA summarizer (already returns string)\n",
148
+ " return summary"
149
+ ]
150
+ },
151
+ {
152
+ "cell_type": "code",
153
+ "execution_count": 12,
154
+ "id": "aa678fda-395a-4509-8580-c885aa86b052",
155
+ "metadata": {
156
+ "scrolled": true
157
+ },
158
+ "outputs": [
159
+ {
160
+ "name": "stdout",
161
+ "output_type": "stream",
162
+ "text": [
163
+ "* Running on local URL: http://127.0.0.1:7861\n",
164
+ "\n",
165
+ "To create a public link, set `share=True` in `launch()`.\n"
166
+ ]
167
+ },
168
+ {
169
+ "data": {
170
+ "text/html": [
171
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
172
+ ],
173
+ "text/plain": [
174
+ "<IPython.core.display.HTML object>"
175
+ ]
176
+ },
177
+ "metadata": {},
178
+ "output_type": "display_data"
179
+ },
180
+ {
181
+ "data": {
182
+ "text/plain": []
183
+ },
184
+ "execution_count": 12,
185
+ "metadata": {},
186
+ "output_type": "execute_result"
187
+ },
188
+ {
189
+ "name": "stderr",
190
+ "output_type": "stream",
191
+ "text": [
192
+ "ERROR: Exception in ASGI application\n",
193
+ "Traceback (most recent call last):\n",
194
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 403, in run_asgi\n",
195
+ " result = await app( # type: ignore[func-returns-value]\n",
196
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
197
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\middleware\\proxy_headers.py\", line 60, in __call__\n",
198
+ " return await self.app(scope, receive, send)\n",
199
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
200
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\fastapi\\applications.py\", line 1054, in __call__\n",
201
+ " await super().__call__(scope, receive, send)\n",
202
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\applications.py\", line 112, in __call__\n",
203
+ " await self.middleware_stack(scope, receive, send)\n",
204
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 187, in __call__\n",
205
+ " raise exc\n",
206
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 165, in __call__\n",
207
+ " await self.app(scope, receive, _send)\n",
208
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\gradio\\route_utils.py\", line 829, in __call__\n",
209
+ " await self.app(scope, receive, send)\n",
210
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\exceptions.py\", line 62, in __call__\n",
211
+ " await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)\n",
212
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
213
+ " raise exc\n",
214
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
215
+ " await app(scope, receive, sender)\n",
216
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 714, in __call__\n",
217
+ " await self.middleware_stack(scope, receive, send)\n",
218
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 734, in app\n",
219
+ " await route.handle(scope, receive, send)\n",
220
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 288, in handle\n",
221
+ " await self.app(scope, receive, send)\n",
222
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 76, in app\n",
223
+ " await wrap_app_handling_exceptions(app, request)(scope, receive, send)\n",
224
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
225
+ " raise exc\n",
226
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
227
+ " await app(scope, receive, sender)\n",
228
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 74, in app\n",
229
+ " await response(scope, receive, send)\n",
230
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 359, in __call__\n",
231
+ " await self._handle_simple(send, send_header_only)\n",
232
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 388, in _handle_simple\n",
233
+ " await send({\"type\": \"http.response.body\", \"body\": chunk, \"more_body\": more_body})\n",
234
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
235
+ " await send(message)\n",
236
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
237
+ " await send(message)\n",
238
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 162, in _send\n",
239
+ " await send(message)\n",
240
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 507, in send\n",
241
+ " output = self.conn.send(event=h11.EndOfMessage())\n",
242
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
243
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 512, in send\n",
244
+ " data_list = self.send_with_data_passthrough(event)\n",
245
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
246
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 545, in send_with_data_passthrough\n",
247
+ " writer(event, data_list.append)\n",
248
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 67, in __call__\n",
249
+ " self.send_eom(event.headers, write)\n",
250
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 96, in send_eom\n",
251
+ " raise LocalProtocolError(\"Too little data for declared Content-Length\")\n",
252
+ "h11._util.LocalProtocolError: Too little data for declared Content-Length\n",
253
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
254
+ " warnings.warn(\n",
255
+ "Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`.\n",
256
+ "Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.\n",
257
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
258
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n",
259
+ "The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
260
+ ]
261
+ },
262
+ {
263
+ "name": "stdout",
264
+ "output_type": "stream",
265
+ "text": [
266
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
267
+ "\n",
268
+ "Cutting Knowledge Date: December 2023\n",
269
+ "Today Date: 26 Jul 2024\n",
270
+ "\n",
271
+ "You are an assistant that produces minutes of phone call from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown.<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
272
+ "\n",
273
+ "Below is an extract transcript of a a phone call. Please write minutes in markdown, including a summary, location and date; discussion points; takeaways; and action items with owners.\n",
274
+ "\n",
275
+ " How are you? All good. I'm in Israel right now, visiting the family. You're where? In Israel, visiting the family. So can you take international calls without... I do actually. Actually, two cities have the AT&T program, so with the extra fee I can have available. And I did it on purpose so we can talk in case there's something. I don't want it to affect that I just went to visit the situation. So I'm available at any time. OK. Well, I just have this. This is actually, I don't know. So yesterday my boss sent an email to, or sent an IM to my peers and I, right? He said, this is his question, did any of you or anyone on your team get an email stating they are required to take mandatory absence? Right? And everyone said no. And I said, well, I don't know. Tyle may have gotten that email, but I'm not sure. I don't think I got one that was that. And I know you can't log in to email, but before you left, did you see an email that said you are required to take mandatory absence? No, I don't remember having any email of those. The only email related was to update my work authorization. Nothing about mandatory. I mean, the term that Josh uses is leave, But he mentioned me that. I didn't see any email saying the word leave or mandatory absence. I don't. So Josh mentioned something like that? The only, when I asked Josh, I mean, I asked the other guy, Jonathan, the guy under him, what's the status, what's gonna happen after February 18 if I don't have my work authorization? He told me, IME, that I'm gonna be on leave leave. It didn't even say the word mandatory, just a leave. And Josh elaborated about it more to us, but that's it. I didn't have any email. Maybe I got one after, but I didn't see an email. And you would have. I'm going to ask Josh if there was one like that. Yeah, maybe it's like automatic something, but I don't remember anything. I did receive some automatic messages about updating my work authorization. Maybe, maybe in the bottom of the email, there was saying, in case of no updating on time, you will require to be on absent. I don't know. I don't remember anything like that. All I received was automatic messages about updating my work authorization before the 18th. Nothing about mandatory absence. Yeah. OK. OK. When are you going to be back in New York? Yeah. When are you going to be back? Ah, when? I'm not sure. I'm about to one way for now. I'm not sure. I'm checking every day. Whenever I get it, I'm going to fly the same day. I'm going to send it to Josh and my work authorization will fly the same day back. So I'm kind of flexible if that's okay on your side. But yeah, I mean, just, you know, whenever I get it, I'm gonna send it right away to Josh and he's going to process it to HR and I'm gonna fly the same night already. Yeah. Yeah. Jeremiah and I posted with what's going on, but I did want to touch base with you and see. I don't know why he's asking this, but it would seem like it would probably be something that was raised up with respect to your situation. I mean, I would... It makes sense, yeah. Yeah, it does make sense to me. Or it's awfully ironic. All of your employees are probably legal to work, so kind of maybe mean, but I don't remember anything like that. What's the issue? What's the issue? You think there's a problem here or something? I don't think it's a problem. I think it probably went to his boss, and his boss asked about it. So he's wanted to verify. But he knows the situation, because I've told him. Well, it's good that the big boss knows me, right? I didn't expect him to know me like that, but it's better than nothing. Yeah. Yeah. Yeah. Sorry about it, but I guess let's wait a bit more, see what's happening. I told Jeremiah you can call me anytime if there's some question or something like that to work that I could help and I wish I could I wish I could log in but you know I could help but I won't I know it's it's it's a problem so I won't do that of course. Okay okay well I appreciate it. If I have anything I'll let you know. Yeah yeah feel free to message me whatever you want. I'm available. Okay, cool. Thank you. Thank you. Okay, talk to you later. Bye.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
276
+ "\n",
277
+ "**Minutes of Phone Call**\n",
278
+ "==========================\n",
279
+ "\n",
280
+ "**Location:** Israel\n",
281
+ "**Date:** Today (26 Jul 2024)\n",
282
+ "\n",
283
+ "**Summary**\n",
284
+ "-----------\n",
285
+ "\n",
286
+ "This phone call was a discussion regarding a situation with an employee's work authorization and potential mandatory absence. The employee was unavailable to log in to their email, and the caller was seeking verification on whether the employee received an email stating they were required to take mandatory absence.\n",
287
+ "\n",
288
+ "**Discussion Points**\n",
289
+ "--------------------\n",
290
+ "\n",
291
+ "* The employee's work authorization was due to be updated, and there was a concern about whether they received an email stating they were required to take mandatory absence.\n",
292
+ "* The employee did not recall receiving such an email, but they did receive automatic messages about updating their work authorization.\n",
293
+ "* The employee's manager, Josh, was mentioned as having discussed the situation with the employee, but the details were not clear.\n",
294
+ "* The employee offered to send their work authorization to Josh as soon as they received it, to facilitate the processing of their paperwork.\n",
295
+ "\n",
296
+ "**Takeaways**\n",
297
+ "------------\n",
298
+ "\n",
299
+ "* The employee's work authorization was due to be updated, and there was a concern about whether they received an email stating they were required to take mandatory absence.\n",
300
+ "* The employee did not recall receiving such an email, but they did receive automatic messages about updating their work authorization.\n",
301
+ "\n",
302
+ "**Action Items**\n",
303
+ "----------------\n",
304
+ "\n",
305
+ "* **Owner:** Employee\n",
306
+ "\t+ Send work authorization to Josh as soon as received.\n",
307
+ "* **Owner:** Josh\n",
308
+ "\t+ Verify with the employee whether they received an email stating they were required to take mandatory absence.\n",
309
+ "\t+ Process the employee's paperwork once they receive their work authorization.\n",
310
+ "* **Owner:** Caller\n",
311
+ "\t+ Follow up with Josh to verify the situation and ensure the employee's paperwork is processed.<|eot_id|>\n"
312
+ ]
313
+ }
314
+ ],
315
+ "source": [
316
+ "gr.Interface(\n",
317
+ " fn=transcribe_and_summarize,\n",
318
+ " inputs=gr.Audio(type=\"filepath\"),\n",
319
+ " outputs=\"text\",\n",
320
+ " title=\"Audio Summarizer\"\n",
321
+ ").launch()"
322
+ ]
323
+ },
324
+ {
325
+ "cell_type": "code",
326
+ "execution_count": null,
327
+ "id": "606fce2d-6dcd-4395-af7d-9d60520be943",
328
+ "metadata": {},
329
+ "outputs": [],
330
+ "source": []
331
+ }
332
+ ],
333
+ "metadata": {
334
+ "kernelspec": {
335
+ "display_name": "Python 3 (ipykernel)",
336
+ "language": "python",
337
+ "name": "python3"
338
+ },
339
+ "language_info": {
340
+ "codemirror_mode": {
341
+ "name": "ipython",
342
+ "version": 3
343
+ },
344
+ "file_extension": ".py",
345
+ "mimetype": "text/x-python",
346
+ "name": "python",
347
+ "nbconvert_exporter": "python",
348
+ "pygments_lexer": "ipython3",
349
+ "version": "3.11.11"
350
+ }
351
+ },
352
+ "nbformat": 4,
353
+ "nbformat_minor": 5
354
+ }
.ipynb_checkpoints/transformers-checkpoint.ipynb ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "f52d28db-f259-4c69-b5cf-5ae7abd53db6",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import torch\n",
20
+ "from transformers import WhisperProcessor, WhisperForConditionalGeneration, AutoTokenizer, AutoModelForCausalLM, TextStreamer, BitsAndBytesConfig\n",
21
+ "from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, pipeline\n",
22
+ "import torchaudio\n",
23
+ "from IPython.display import Markdown, display\n",
24
+ "import gradio as gr"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 2,
30
+ "id": "b650ef06-b522-4abf-a458-fc8a70042654",
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stdout",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "CUDA Available: True\n",
38
+ "Number of GPUs: 1\n",
39
+ "Current CUDA Device: NVIDIA GeForce RTX 4060 Laptop GPU\n"
40
+ ]
41
+ }
42
+ ],
43
+ "source": [
44
+ "# Check if CUDA is available\n",
45
+ "print(\"CUDA Available: \", torch.cuda.is_available())\n",
46
+ "\n",
47
+ "# List available GPUs\n",
48
+ "print(\"Number of GPUs: \", torch.cuda.device_count())\n",
49
+ "\n",
50
+ "# Get the name of the current device\n",
51
+ "print(\"Current CUDA Device: \", torch.cuda.get_device_name(torch.cuda.current_device()))"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 3,
57
+ "id": "ce0248ea-ff88-451f-a979-79fdf0568d9b",
58
+ "metadata": {
59
+ "scrolled": true
60
+ },
61
+ "outputs": [],
62
+ "source": [
63
+ "quant_config = BitsAndBytesConfig(\n",
64
+ " load_in_4bit=True,\n",
65
+ " bnb_4bit_use_double_quant=True,\n",
66
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
67
+ " bnb_4bit_quant_type=\"nf4\"\n",
68
+ ")"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": 4,
74
+ "id": "6995d1d2-524b-4c14-ac4f-432262b7b1f8",
75
+ "metadata": {
76
+ "scrolled": true
77
+ },
78
+ "outputs": [
79
+ {
80
+ "name": "stderr",
81
+ "output_type": "stream",
82
+ "text": [
83
+ "Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:26<00:00, 6.51s/it]\n"
84
+ ]
85
+ }
86
+ ],
87
+ "source": [
88
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
89
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
90
+ "tokenizer.pad_token = tokenizer.eos_token\n",
91
+ "streamer = TextStreamer(tokenizer)\n",
92
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"cuda:0\", quantization_config=quant_config)"
93
+ ]
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "execution_count": 41,
98
+ "id": "e5b240f5-88a0-4ecf-8659-3a7eb8447307",
99
+ "metadata": {},
100
+ "outputs": [],
101
+ "source": [
102
+ "def transcript_audio(audio_file):\n",
103
+ " device = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n",
104
+ " torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32\n",
105
+ " \n",
106
+ " model_id = \"openai/whisper-large-v3-turbo\"\n",
107
+ " \n",
108
+ " model = AutoModelForSpeechSeq2Seq.from_pretrained(\n",
109
+ " model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True\n",
110
+ " )\n",
111
+ " model.to(device)\n",
112
+ " \n",
113
+ " processor = AutoProcessor.from_pretrained(model_id)\n",
114
+ " \n",
115
+ " pipe = pipeline(\n",
116
+ " \"automatic-speech-recognition\",\n",
117
+ " model=model,\n",
118
+ " tokenizer=processor.tokenizer,\n",
119
+ " feature_extractor=processor.feature_extractor,\n",
120
+ " torch_dtype=torch_dtype,\n",
121
+ " device=device,\n",
122
+ " )\n",
123
+ " \n",
124
+ " result = pipe(audio_file, return_timestamps=True)\n",
125
+ " return result"
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": 42,
131
+ "id": "c8301e0d-ec49-45a6-8d2e-7247c91c8b80",
132
+ "metadata": {},
133
+ "outputs": [],
134
+ "source": [
135
+ "def summarize_with_llama(transcript, context=\"Phone Call\"):\n",
136
+ " if context == \"Phone Call\":\n",
137
+ " system_message = (\n",
138
+ " \"You are an assistant that produces minutes of phone call from transcripts, \"\n",
139
+ " \"with summary and key discussion points, in markdown.\"\n",
140
+ " )\n",
141
+ " user_prompt = (\n",
142
+ " \"Below is an extract transcript of a phone call. \"\n",
143
+ " \"Please write minutes in markdown, including a summary, location and discussion points.\"\n",
144
+ " )\n",
145
+ " elif context == \"Meeting\":\n",
146
+ " system_message = (\n",
147
+ " \"You are an assistant that produces minutes of meetings from transcripts, \"\n",
148
+ " \"with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
149
+ " )\n",
150
+ " user_prompt = (\n",
151
+ " \"Below is an extract transcript of a Denver council meeting. \"\n",
152
+ " \"Please write minutes in markdown, including a summary with attendees, location and date; \"\n",
153
+ " \"discussion points; takeaways; and action items with owners.\"\n",
154
+ " )\n",
155
+ " else:\n",
156
+ " raise ValueError(f\"Unknown context: {context}\")\n",
157
+ "\n",
158
+ " messages = [\n",
159
+ " {\"role\": \"system\", \"content\": system_message},\n",
160
+ " {\"role\": \"user\", \"content\": f\"{user_prompt}\\n\\n{transcript}\"}\n",
161
+ " ]\n",
162
+ "\n",
163
+ " input_features = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
164
+ " output_ids = model.generate(input_features, max_new_tokens=2000, streamer=streamer)\n",
165
+ " summary = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()\n",
166
+ " return summary"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": 43,
172
+ "id": "6e6c8b1f-20d1-4eb1-99be-3a3ba4a13b83",
173
+ "metadata": {},
174
+ "outputs": [],
175
+ "source": [
176
+ "def transcribe_and_summarize(audio, choices):\n",
177
+ " result = transcript_audio(audio)\n",
178
+ " transcript = result[\"text\"]\n",
179
+ " yield summarize_with_llama(transcript, context=choices)"
180
+ ]
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "execution_count": 45,
185
+ "id": "5e7b676e-93c5-4744-8fa9-9f779ffe7ab6",
186
+ "metadata": {
187
+ "scrolled": true
188
+ },
189
+ "outputs": [
190
+ {
191
+ "name": "stdout",
192
+ "output_type": "stream",
193
+ "text": [
194
+ "* Running on local URL: http://127.0.0.1:7874\n",
195
+ "\n",
196
+ "To create a public link, set `share=True` in `launch()`.\n"
197
+ ]
198
+ },
199
+ {
200
+ "data": {
201
+ "text/html": [
202
+ "<div><iframe src=\"http://127.0.0.1:7874/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
203
+ ],
204
+ "text/plain": [
205
+ "<IPython.core.display.HTML object>"
206
+ ]
207
+ },
208
+ "metadata": {},
209
+ "output_type": "display_data"
210
+ },
211
+ {
212
+ "data": {
213
+ "text/plain": []
214
+ },
215
+ "execution_count": 45,
216
+ "metadata": {},
217
+ "output_type": "execute_result"
218
+ },
219
+ {
220
+ "name": "stderr",
221
+ "output_type": "stream",
222
+ "text": [
223
+ "ERROR: Exception in ASGI application\n",
224
+ "Traceback (most recent call last):\n",
225
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 403, in run_asgi\n",
226
+ " result = await app( # type: ignore[func-returns-value]\n",
227
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
228
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\middleware\\proxy_headers.py\", line 60, in __call__\n",
229
+ " return await self.app(scope, receive, send)\n",
230
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
231
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\fastapi\\applications.py\", line 1054, in __call__\n",
232
+ " await super().__call__(scope, receive, send)\n",
233
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\applications.py\", line 112, in __call__\n",
234
+ " await self.middleware_stack(scope, receive, send)\n",
235
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 187, in __call__\n",
236
+ " raise exc\n",
237
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 165, in __call__\n",
238
+ " await self.app(scope, receive, _send)\n",
239
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\gradio\\route_utils.py\", line 829, in __call__\n",
240
+ " await self.app(scope, receive, send)\n",
241
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\exceptions.py\", line 62, in __call__\n",
242
+ " await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)\n",
243
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
244
+ " raise exc\n",
245
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
246
+ " await app(scope, receive, sender)\n",
247
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 714, in __call__\n",
248
+ " await self.middleware_stack(scope, receive, send)\n",
249
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 734, in app\n",
250
+ " await route.handle(scope, receive, send)\n",
251
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 288, in handle\n",
252
+ " await self.app(scope, receive, send)\n",
253
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 76, in app\n",
254
+ " await wrap_app_handling_exceptions(app, request)(scope, receive, send)\n",
255
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 53, in wrapped_app\n",
256
+ " raise exc\n",
257
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 42, in wrapped_app\n",
258
+ " await app(scope, receive, sender)\n",
259
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\routing.py\", line 74, in app\n",
260
+ " await response(scope, receive, send)\n",
261
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 359, in __call__\n",
262
+ " await self._handle_simple(send, send_header_only)\n",
263
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\responses.py\", line 388, in _handle_simple\n",
264
+ " await send({\"type\": \"http.response.body\", \"body\": chunk, \"more_body\": more_body})\n",
265
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
266
+ " await send(message)\n",
267
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\_exception_handler.py\", line 39, in sender\n",
268
+ " await send(message)\n",
269
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\starlette\\middleware\\errors.py\", line 162, in _send\n",
270
+ " await send(message)\n",
271
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\uvicorn\\protocols\\http\\h11_impl.py\", line 507, in send\n",
272
+ " output = self.conn.send(event=h11.EndOfMessage())\n",
273
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
274
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 512, in send\n",
275
+ " data_list = self.send_with_data_passthrough(event)\n",
276
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
277
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_connection.py\", line 545, in send_with_data_passthrough\n",
278
+ " writer(event, data_list.append)\n",
279
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 67, in __call__\n",
280
+ " self.send_eom(event.headers, write)\n",
281
+ " File \"C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\h11\\_writers.py\", line 96, in send_eom\n",
282
+ " raise LocalProtocolError(\"Too little data for declared Content-Length\")\n",
283
+ "h11._util.LocalProtocolError: Too little data for declared Content-Length\n",
284
+ "Device set to use cuda:0\n",
285
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
286
+ " warnings.warn(\n",
287
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
288
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
289
+ ]
290
+ },
291
+ {
292
+ "name": "stdout",
293
+ "output_type": "stream",
294
+ "text": [
295
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n",
296
+ "\n",
297
+ "Cutting Knowledge Date: December 2023\n",
298
+ "Today Date: 26 Jul 2024\n",
299
+ "\n",
300
+ "You are an assistant that produces minutes of phone call from transcripts, with summary and key discussion points, in markdown.<|eot_id|><|start_header_id|>user<|end_header_id|>\n",
301
+ "\n",
302
+ "Below is an extract transcript of a phone call. Please write minutes in markdown, including a summary, location and discussion points.\n",
303
+ "\n",
304
+ " Everything's okay. Yep, I was just calling it a prescription for information. Yeah, yeah. So just talking about the second announcement. Yeah, not as soon. We want to do that part first. Maybe your wife told you or not, I do have a bit of an issue of the process because I cannot go visit this time. So this is the tough part for me because I used to go every three, four months to visit. And now it's a bit of uncertainty when it's going to be over. It can be between seven months to 15 months. It's uncertain, yeah. So this is the tough part for me. I think Minina will get over this part at some point. but I'm giving it a bit more time and then I will hopefully do the second announcement. By the way, your mother knows, right? Yeah, of course. She congratulates me, Rena. She's aware of that. Uh-huh. Yeah. Okay. That's good. You're already a fly? Is your fly? I talked to the lawyer. He did the first step and he's on it. I talked to the lawyer one hour after we arrived back. yeah right right so we're moving forward but I'm giving it a bit more time just to process some things and hopefully soon it will be a second and of course I will Amen thank you thank you very much good it's like having a baby right that's what you say yes it'll come it'll come when it's time it's due yeah I believe everything will come at the right time and the right place and yes we do things hopefully correctly we have a plan oh yeah I want to add you to the I'm adding you to no I won't I can't do that yet no don I your wife mentioned that yeah yeah your wife say not a good idea. No worries. Don't worry. Okay. Hope every time in his place. All right. Well, we would read it. Yes. Hope. Yes. But for now, Shabbat Shalom. Shabbat Shalom. Goodbye. Goodbye.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n",
305
+ "\n",
306
+ "**Minutes of Phone Call**\n",
307
+ "==========================\n",
308
+ "\n",
309
+ "**Location:** [Not specified]\n",
310
+ "**Date:** [Not specified]\n",
311
+ "**Summary:**\n",
312
+ "The phone call was about discussing a personal issue and future plans. The speaker shared their uncertainty about a process that may take 7-15 months to complete. They mentioned their intention to make a second announcement in the future and discussed their progress with a lawyer.\n",
313
+ "\n",
314
+ "**Key Discussion Points:**\n",
315
+ "\n",
316
+ "* The speaker is going through a challenging time due to an uncertain process that may take 7-15 months to complete.\n",
317
+ "* They plan to make a second announcement in the future, but want to give themselves more time to process things.\n",
318
+ "* They have spoken to a lawyer who is working on the first step.\n",
319
+ "* They mentioned their mother's awareness of their situation and received congratulations.\n",
320
+ "* The speaker's wife advised against adding someone to a list or plan, and they agreed to follow her advice.\n",
321
+ "* The call ended with a discussion about timing and the importance of patience, with a mention of the phrase \"Shabbat Shalom\".<|eot_id|>\n"
322
+ ]
323
+ }
324
+ ],
325
+ "source": [
326
+ "gr.Interface(\n",
327
+ " fn=transcribe_and_summarize,\n",
328
+ " inputs=[\n",
329
+ " gr.Audio(type=\"filepath\", label=\"Upload Audio\"),\n",
330
+ " gr.Radio([\"Phone Call\", \"Meeting\"], label=\"Select Audio Type\")\n",
331
+ " ],\n",
332
+ " outputs=gr.Textbox(label=\"Summary\", lines=20),\n",
333
+ " title=\"Audio Summarizer\"\n",
334
+ ").launch()"
335
+ ]
336
+ }
337
+ ],
338
+ "metadata": {
339
+ "kernelspec": {
340
+ "display_name": "Python 3 (ipykernel)",
341
+ "language": "python",
342
+ "name": "python3"
343
+ },
344
+ "language_info": {
345
+ "codemirror_mode": {
346
+ "name": "ipython",
347
+ "version": 3
348
+ },
349
+ "file_extension": ".py",
350
+ "mimetype": "text/x-python",
351
+ "name": "python",
352
+ "nbconvert_exporter": "python",
353
+ "pygments_lexer": "ipython3",
354
+ "version": "3.11.11"
355
+ }
356
+ },
357
+ "nbformat": 4,
358
+ "nbformat_minor": 5
359
+ }
.ipynb_checkpoints/try-checkpoint.ipynb ADDED
@@ -0,0 +1,501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "1d41fad6-3422-4f62-9320-523293c60cca",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\copyleaks\\Lib\\site-packages\\torch\\utils\\_pytree.py:185: FutureWarning: optree is installed but the version is too old to support PyTorch Dynamo in C++ pytree. C++ pytree support is disabled. Please consider upgrading optree using `python3 -m pip install --upgrade 'optree>=0.13.0'`.\n",
14
+ " warnings.warn(\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "from datasets import load_dataset\n",
20
+ "import torch\n",
21
+ "from torch.utils.data import Dataset\n",
22
+ "\n",
23
+ "import torch\n",
24
+ "import torch.nn as nn\n",
25
+ "import torch.optim as optim\n",
26
+ "\n",
27
+ "from torch.utils.data import DataLoader"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 2,
33
+ "id": "118d4018-7605-4ebc-a677-6c9a5f4d6193",
34
+ "metadata": {},
35
+ "outputs": [
36
+ {
37
+ "name": "stdout",
38
+ "output_type": "stream",
39
+ "text": [
40
+ "CUDA Available: True\n",
41
+ "Number of GPUs: 1\n",
42
+ "Current CUDA Device: NVIDIA GeForce RTX 4060 Laptop GPU\n"
43
+ ]
44
+ }
45
+ ],
46
+ "source": [
47
+ "# Check if CUDA is available\n",
48
+ "print(\"CUDA Available: \", torch.cuda.is_available())\n",
49
+ "\n",
50
+ "# List available GPUs\n",
51
+ "print(\"Number of GPUs: \", torch.cuda.device_count())\n",
52
+ "\n",
53
+ "# Get the name of the current device\n",
54
+ "print(\"Current CUDA Device: \", torch.cuda.get_device_name(torch.cuda.current_device()))"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 3,
60
+ "id": "487d32bc-8ebc-4cec-bfa1-4f425788ac22",
61
+ "metadata": {
62
+ "scrolled": true
63
+ },
64
+ "outputs": [],
65
+ "source": [
66
+ "# Load the dataset\n",
67
+ "ds = load_dataset(\"tner/conll2003\")\n",
68
+ "\n",
69
+ "# Sample token and tag data (from the dataset)\n",
70
+ "train_tokens = ds['train']['tokens']\n",
71
+ "train_tags = ds['train']['tags']"
72
+ ]
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "execution_count": 4,
77
+ "id": "32fbb149-fc8d-418c-be15-66129156606b",
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": [
81
+ "# Define a simple token-to-index mapping (in practice, you'd use a tokenizer)\n",
82
+ "# Let's assume a basic vocabulary that includes all the words\n",
83
+ "vocab = {}\n",
84
+ "for sentence in train_tokens:\n",
85
+ " for word in sentence:\n",
86
+ " if word not in vocab:\n",
87
+ " vocab[word] = len(vocab) # Assign unique index for each word"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 5,
93
+ "id": "4f193d10-9b64-4ba7-aac7-423ad71ed3c9",
94
+ "metadata": {},
95
+ "outputs": [],
96
+ "source": [
97
+ "# Map tokens to indices\n",
98
+ "train_token_ids = [[vocab[word] for word in sentence] for sentence in train_tokens]\n",
99
+ "train_labels = train_tags # Assuming tags are already in numerical format\n",
100
+ "\n",
101
+ "# Define padding length\n",
102
+ "max_len = max(len(sentence) for sentence in train_token_ids)"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": 6,
108
+ "id": "2e859b94-9391-4a59-a1c8-df6c6fd5ca35",
109
+ "metadata": {},
110
+ "outputs": [],
111
+ "source": [
112
+ "# Padding function\n",
113
+ "def pad_sequence(sequence, max_len, padding_value=9):\n",
114
+ " return sequence + [padding_value] * (max_len - len(sequence))"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 7,
120
+ "id": "e148d91a-f451-4d83-8600-dc8868767a1e",
121
+ "metadata": {},
122
+ "outputs": [
123
+ {
124
+ "name": "stdout",
125
+ "output_type": "stream",
126
+ "text": [
127
+ "(tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
128
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
129
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
130
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
131
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]), tensor([1, 0, 2, 0, 0, 0, 2, 0, 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
132
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
133
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
134
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,\n",
135
+ " 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]))\n"
136
+ ]
137
+ }
138
+ ],
139
+ "source": [
140
+ "# Pad sentences and labels\n",
141
+ "padded_tokens = [pad_sequence(sentence, max_len) for sentence in train_token_ids]\n",
142
+ "padded_tags = [pad_sequence(tags, max_len) for tags in train_labels]\n",
143
+ "\n",
144
+ "# Define a Dataset class\n",
145
+ "class NERDataset(Dataset):\n",
146
+ " def __init__(self, sentences, labels):\n",
147
+ " self.sentences = sentences\n",
148
+ " self.labels = labels\n",
149
+ " \n",
150
+ " def __len__(self):\n",
151
+ " return len(self.sentences)\n",
152
+ " \n",
153
+ " def __getitem__(self, idx):\n",
154
+ " return torch.tensor(self.sentences[idx]), torch.tensor(self.labels[idx])\n",
155
+ "\n",
156
+ "# Create Dataset object for training\n",
157
+ "dataset = NERDataset(padded_tokens, padded_tags)\n",
158
+ "\n",
159
+ "# Check a sample item\n",
160
+ "print(dataset[0])"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 8,
166
+ "id": "13134c8b-a412-4ee1-beb2-53fd10ad8b8a",
167
+ "metadata": {},
168
+ "outputs": [],
169
+ "source": [
170
+ "# LSTM-based NER Model\n",
171
+ "class LSTM_NER(nn.Module):\n",
172
+ " def __init__(self, vocab_size, embedding_dim, hidden_dim, num_classes, dropout=0.5):\n",
173
+ " super(LSTM_NER, self).__init__()\n",
174
+ " \n",
175
+ " # Embedding layer to convert tokens to embeddings\n",
176
+ " self.embedding = nn.Embedding(vocab_size, embedding_dim)\n",
177
+ " \n",
178
+ " # LSTM layer\n",
179
+ " self.lstm = nn.LSTM(embedding_dim, hidden_dim, batch_first=True, bidirectional=True)\n",
180
+ " \n",
181
+ " # Dropout layer to prevent overfitting\n",
182
+ " self.dropout = nn.Dropout(dropout)\n",
183
+ " \n",
184
+ " # Fully connected layer to map LSTM output to tag space\n",
185
+ " self.fc = nn.Linear(hidden_dim * 2, num_classes) # Bidirectional LSTM (hidden_dim * 2)\n",
186
+ " \n",
187
+ " def forward(self, x):\n",
188
+ " # Embed the input tokens\n",
189
+ " x = self.embedding(x)\n",
190
+ " \n",
191
+ " # Pass through LSTM\n",
192
+ " lstm_out, _ = self.lstm(x)\n",
193
+ " \n",
194
+ " # Apply dropout\n",
195
+ " lstm_out = self.dropout(lstm_out)\n",
196
+ " \n",
197
+ " # Pass through the fully connected layer to get tag scores\n",
198
+ " output = self.fc(lstm_out)\n",
199
+ " \n",
200
+ " return output"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "code",
205
+ "execution_count": 9,
206
+ "id": "00a0be3a-75ca-4201-9ed5-7ad57c444c03",
207
+ "metadata": {},
208
+ "outputs": [],
209
+ "source": [
210
+ "# Hyperparameters (example values, you can adjust as needed)\n",
211
+ "embedding_dim = 100 # Size of word embeddings\n",
212
+ "hidden_dim = 128 # Number of hidden units in the LSTM\n",
213
+ "num_classes = len(set(tag for sublist in train_tags for tag in sublist)) # Number of NER tags\n",
214
+ "dropout = 0.5\n",
215
+ "max_len = max(len(sentence) for sentence in padded_tokens) # Maximum sequence length\n",
216
+ "\n",
217
+ "# Create the model\n",
218
+ "model = LSTM_NER(\n",
219
+ " vocab_size=len(vocab), # Vocabulary size from the tokenization step\n",
220
+ " embedding_dim=embedding_dim,\n",
221
+ " hidden_dim=hidden_dim,\n",
222
+ " num_classes=num_classes,\n",
223
+ " dropout=dropout\n",
224
+ ")"
225
+ ]
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "execution_count": 10,
230
+ "id": "60865c95-a7ab-4fba-af3a-871e8dad0a3b",
231
+ "metadata": {},
232
+ "outputs": [],
233
+ "source": [
234
+ "# Loss function and optimizer\n",
235
+ "loss_function = nn.CrossEntropyLoss(ignore_index=9) # Ignore padding token in loss calculation\n",
236
+ "optimizer = optim.Adam(model.parameters(), lr=0.001)"
237
+ ]
238
+ },
239
+ {
240
+ "cell_type": "code",
241
+ "execution_count": 11,
242
+ "id": "172b1e88-92a1-4036-89e2-c686b2438f21",
243
+ "metadata": {
244
+ "scrolled": true
245
+ },
246
+ "outputs": [],
247
+ "source": [
248
+ "# Sample input\n",
249
+ "sample_input = torch.tensor(padded_tokens[0]) # Use the first sentence as a sample\n",
250
+ "output = model(sample_input.unsqueeze(0)) # Add batch dimension (unsqueeze(0))"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "execution_count": 12,
256
+ "id": "d8207479-684d-414b-b247-ddbd2971ad15",
257
+ "metadata": {},
258
+ "outputs": [
259
+ {
260
+ "name": "stdout",
261
+ "output_type": "stream",
262
+ "text": [
263
+ "Output shape: torch.Size([1, 113, 9])\n"
264
+ ]
265
+ }
266
+ ],
267
+ "source": [
268
+ "# Check the output shape\n",
269
+ "print(f\"Output shape: {output.shape}\")"
270
+ ]
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "execution_count": 13,
275
+ "id": "402456fb-7969-4c85-add1-3b96dbf6370b",
276
+ "metadata": {},
277
+ "outputs": [],
278
+ "source": [
279
+ "# Create DataLoader for batching the dataset\n",
280
+ "train_loader = DataLoader(dataset, batch_size=32, shuffle=True)"
281
+ ]
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "execution_count": 14,
286
+ "id": "6e56123b-b1c1-469c-a0b8-7a7af614e250",
287
+ "metadata": {},
288
+ "outputs": [
289
+ {
290
+ "name": "stdout",
291
+ "output_type": "stream",
292
+ "text": [
293
+ "Epoch 1/5, Loss: 0.6101920610136757\n",
294
+ "Epoch 2/5, Loss: 0.31584523417955107\n",
295
+ "Epoch 3/5, Loss: 0.20123767959704975\n",
296
+ "Epoch 4/5, Loss: 0.13604617730665586\n",
297
+ "Epoch 5/5, Loss: 0.09354495681856244\n"
298
+ ]
299
+ }
300
+ ],
301
+ "source": [
302
+ "# Training loop\n",
303
+ "num_epochs = 5 # Example number of epochs\n",
304
+ "for epoch in range(num_epochs):\n",
305
+ " model.train() # Set model to training mode\n",
306
+ " total_loss = 0\n",
307
+ " for input_ids, labels in train_loader:\n",
308
+ " optimizer.zero_grad() # Zero gradients\n",
309
+ " \n",
310
+ " # Forward pass\n",
311
+ " output = model(input_ids) # Get predictions from the model\n",
312
+ " \n",
313
+ " # Compute loss\n",
314
+ " loss = loss_function(output.view(-1, num_classes), labels.view(-1))\n",
315
+ " \n",
316
+ " # Backward pass and optimization\n",
317
+ " loss.backward()\n",
318
+ " optimizer.step()\n",
319
+ " \n",
320
+ " total_loss += loss.item() # Accumulate loss\n",
321
+ "\n",
322
+ " # Print the loss for the epoch\n",
323
+ " print(f\"Epoch {epoch+1}/{num_epochs}, Loss: {total_loss / len(train_loader)}\")"
324
+ ]
325
+ },
326
+ {
327
+ "cell_type": "code",
328
+ "execution_count": 15,
329
+ "id": "7b3d7105-65ed-467f-8bb0-cb3fc068f7e6",
330
+ "metadata": {
331
+ "scrolled": true
332
+ },
333
+ "outputs": [],
334
+ "source": [
335
+ "# Load validation and test data (if you haven't already)\n",
336
+ "val_tokens = ds['validation']['tokens']\n",
337
+ "val_tags = ds['validation']['tags']\n",
338
+ "\n",
339
+ "test_tokens = ds['test']['tokens']\n",
340
+ "test_tags = ds['test']['tags']"
341
+ ]
342
+ },
343
+ {
344
+ "cell_type": "code",
345
+ "execution_count": 16,
346
+ "id": "76ad6885-a9ad-4d1a-aa6b-57c30bd0caf3",
347
+ "metadata": {},
348
+ "outputs": [],
349
+ "source": [
350
+ "# Token to index mapping (same as for training data)\n",
351
+ "# Make sure all tokens from validation and test data are included\n",
352
+ "for sentence in val_tokens + test_tokens:\n",
353
+ " for word in sentence:\n",
354
+ " if word not in vocab:\n",
355
+ " vocab[word] = len(vocab)"
356
+ ]
357
+ },
358
+ {
359
+ "cell_type": "code",
360
+ "execution_count": 17,
361
+ "id": "b608f62d-2286-405d-99b5-e48d240d9e66",
362
+ "metadata": {},
363
+ "outputs": [],
364
+ "source": [
365
+ "# Tokenize and pad the validation and test data\n",
366
+ "val_token_ids = [[vocab[word] for word in sentence] for sentence in val_tokens]\n",
367
+ "test_token_ids = [[vocab[word] for word in sentence] for sentence in test_tokens]"
368
+ ]
369
+ },
370
+ {
371
+ "cell_type": "code",
372
+ "execution_count": 18,
373
+ "id": "53837490-2ba6-455f-8044-c634110131c9",
374
+ "metadata": {},
375
+ "outputs": [],
376
+ "source": [
377
+ "# Change validation and test tags to include 9 as padding token\n",
378
+ "def update_tags_for_padding(tags, max_len):\n",
379
+ " # Add 9 for padding (if necessary)\n",
380
+ " return tags + [9] * (max_len - len(tags))"
381
+ ]
382
+ },
383
+ {
384
+ "cell_type": "code",
385
+ "execution_count": 20,
386
+ "id": "17f020ae-e474-4b22-93fe-eb750e3bfb55",
387
+ "metadata": {},
388
+ "outputs": [],
389
+ "source": [
390
+ "# Padding sequences for validation and test\n",
391
+ "padded_val_tokens = [update_tags_for_padding(sentence, max_len) for sentence in val_token_ids]\n",
392
+ "padded_test_tokens = [update_tags_for_padding(sentence, max_len) for sentence in test_token_ids]\n",
393
+ "\n",
394
+ "# Padding the tags\n",
395
+ "padded_val_tags = [pad_sequence(tags, max_len) for tags in val_tags]\n",
396
+ "padded_test_tags = [pad_sequence(tags, max_len) for tags in test_tags]\n",
397
+ "\n",
398
+ "# Create Dataset objects for validation and test\n",
399
+ "val_dataset = NERDataset(padded_val_tokens, padded_val_tags)\n",
400
+ "test_dataset = NERDataset(padded_test_tokens, padded_test_tags)\n",
401
+ "\n",
402
+ "# Create DataLoader for batching\n",
403
+ "val_loader = DataLoader(val_dataset, batch_size=32, shuffle=False)\n",
404
+ "test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)"
405
+ ]
406
+ },
407
+ {
408
+ "cell_type": "code",
409
+ "execution_count": 21,
410
+ "id": "c8aa137d-f675-4287-ad70-12a06699d8a6",
411
+ "metadata": {},
412
+ "outputs": [
413
+ {
414
+ "data": {
415
+ "text/plain": [
416
+ "LSTM_NER(\n",
417
+ " (embedding): Embedding(23622, 100)\n",
418
+ " (lstm): LSTM(100, 128, batch_first=True, bidirectional=True)\n",
419
+ " (dropout): Dropout(p=0.5, inplace=False)\n",
420
+ " (fc): Linear(in_features=256, out_features=9, bias=True)\n",
421
+ ")"
422
+ ]
423
+ },
424
+ "execution_count": 21,
425
+ "metadata": {},
426
+ "output_type": "execute_result"
427
+ }
428
+ ],
429
+ "source": [
430
+ "# Set model to evaluation mode\n",
431
+ "model.eval()"
432
+ ]
433
+ },
434
+ {
435
+ "cell_type": "code",
436
+ "execution_count": 22,
437
+ "id": "c341760a-ec32-4b7e-bfdf-2bd7e4003d0b",
438
+ "metadata": {},
439
+ "outputs": [
440
+ {
441
+ "data": {
442
+ "text/plain": [
443
+ "9"
444
+ ]
445
+ },
446
+ "execution_count": 22,
447
+ "metadata": {},
448
+ "output_type": "execute_result"
449
+ }
450
+ ],
451
+ "source": [
452
+ "len(set(tag for sublist in test_tags for tag in sublist)) # Number of NER tags"
453
+ ]
454
+ },
455
+ {
456
+ "cell_type": "code",
457
+ "execution_count": 23,
458
+ "id": "c858f674-8ea6-4143-bc03-05d09a3bb1fc",
459
+ "metadata": {},
460
+ "outputs": [
461
+ {
462
+ "name": "stdout",
463
+ "output_type": "stream",
464
+ "text": [
465
+ "Min tag value in test_tags: 0\n",
466
+ "Max tag value in test_tags: 9\n"
467
+ ]
468
+ }
469
+ ],
470
+ "source": [
471
+ "# Check the minimum and maximum values in test_tags\n",
472
+ "min_tag = min([min(tags) for tags in padded_tags])\n",
473
+ "max_tag = max([max(tags) for tags in padded_tags])\n",
474
+ "\n",
475
+ "print(f\"Min tag value in test_tags: {min_tag}\")\n",
476
+ "print(f\"Max tag value in test_tags: {max_tag}\")"
477
+ ]
478
+ }
479
+ ],
480
+ "metadata": {
481
+ "kernelspec": {
482
+ "display_name": "Python 3 (ipykernel)",
483
+ "language": "python",
484
+ "name": "python3"
485
+ },
486
+ "language_info": {
487
+ "codemirror_mode": {
488
+ "name": "ipython",
489
+ "version": 3
490
+ },
491
+ "file_extension": ".py",
492
+ "mimetype": "text/x-python",
493
+ "name": "python",
494
+ "nbconvert_exporter": "python",
495
+ "pygments_lexer": "ipython3",
496
+ "version": "3.11.11"
497
+ }
498
+ },
499
+ "nbformat": 4,
500
+ "nbformat_minor": 5
501
+ }
Audio_Summarizer.ipynb ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "f52d28db-f259-4c69-b5cf-5ae7abd53db6",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import torch\n",
20
+ "from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, BitsAndBytesConfig, AutoProcessor, AutoModelForSpeechSeq2Seq\n",
21
+ "import gradio as gr"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 2,
27
+ "id": "ce0248ea-ff88-451f-a979-79fdf0568d9b",
28
+ "metadata": {
29
+ "scrolled": true
30
+ },
31
+ "outputs": [],
32
+ "source": [
33
+ "quant_config = BitsAndBytesConfig(\n",
34
+ " load_in_4bit=True,\n",
35
+ " bnb_4bit_use_double_quant=True,\n",
36
+ " bnb_4bit_compute_dtype=torch.bfloat16,\n",
37
+ " bnb_4bit_quant_type=\"nf4\"\n",
38
+ ")"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": 3,
44
+ "id": "6995d1d2-524b-4c14-ac4f-432262b7b1f8",
45
+ "metadata": {
46
+ "scrolled": true
47
+ },
48
+ "outputs": [
49
+ {
50
+ "name": "stderr",
51
+ "output_type": "stream",
52
+ "text": [
53
+ "Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:36<00:00, 9.13s/it]\n"
54
+ ]
55
+ }
56
+ ],
57
+ "source": [
58
+ "LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
59
+ "device = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n",
60
+ "tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
61
+ "tokenizer.pad_token = tokenizer.eos_token\n",
62
+ "model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map=\"cuda:0\", quantization_config=quant_config)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 4,
68
+ "id": "e5b240f5-88a0-4ecf-8659-3a7eb8447307",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "def transcript_audio(audio_file):\n",
73
+ " torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32\n",
74
+ " \n",
75
+ " model_id = \"openai/whisper-large-v3-turbo\"\n",
76
+ " \n",
77
+ " model = AutoModelForSpeechSeq2Seq.from_pretrained(\n",
78
+ " model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True\n",
79
+ " )\n",
80
+ " model.to(device)\n",
81
+ " \n",
82
+ " processor = AutoProcessor.from_pretrained(model_id)\n",
83
+ " \n",
84
+ " pipe = pipeline(\n",
85
+ " \"automatic-speech-recognition\",\n",
86
+ " model=model,\n",
87
+ " tokenizer=processor.tokenizer,\n",
88
+ " feature_extractor=processor.feature_extractor,\n",
89
+ " torch_dtype=torch_dtype,\n",
90
+ " device=device,\n",
91
+ " )\n",
92
+ " \n",
93
+ " result = pipe(audio_file, return_timestamps=True)\n",
94
+ " return result"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 5,
100
+ "id": "c8301e0d-ec49-45a6-8d2e-7247c91c8b80",
101
+ "metadata": {},
102
+ "outputs": [],
103
+ "source": [
104
+ "def summarize_with_llama(transcript, context=\"Phone Call\"):\n",
105
+ " if context == \"Phone Call\":\n",
106
+ " system_message = (\n",
107
+ " \"You are an assistant that produces minutes of phone call from transcripts, \"\n",
108
+ " \"with summary and key discussion points, in markdown.\"\n",
109
+ " )\n",
110
+ " user_prompt = (\n",
111
+ " \"Below is an extract transcript of a phone call. \"\n",
112
+ " \"Please write minutes in markdown, including a summary, location and discussion points.\"\n",
113
+ " )\n",
114
+ " elif context == \"Meeting\":\n",
115
+ " system_message = (\n",
116
+ " \"You are an assistant that produces minutes of meetings from transcripts, \"\n",
117
+ " \"with summary, key discussion points, takeaways and action items with owners, in markdown.\"\n",
118
+ " )\n",
119
+ " user_prompt = (\n",
120
+ " \"Below is an extract transcript of a Denver council meeting. \"\n",
121
+ " \"Please write minutes in markdown, including a summary with attendees, location and date; \"\n",
122
+ " \"discussion points; takeaways; and action items with owners.\"\n",
123
+ " )\n",
124
+ " else:\n",
125
+ " raise ValueError(f\"Unknown context: {context}\")\n",
126
+ "\n",
127
+ " messages = [\n",
128
+ " {\"role\": \"system\", \"content\": system_message},\n",
129
+ " {\"role\": \"user\", \"content\": f\"{user_prompt}\\n\\n{transcript}\"}\n",
130
+ " ]\n",
131
+ "\n",
132
+ " input_features = tokenizer.apply_chat_template(messages, return_tensors=\"pt\").to(\"cuda\")\n",
133
+ " output_ids = model.generate(input_features, max_new_tokens=2000)\n",
134
+ " summary = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()\n",
135
+ " return summary"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "execution_count": 6,
141
+ "id": "a54ee711-97d3-4f18-8006-ef02812b125a",
142
+ "metadata": {},
143
+ "outputs": [],
144
+ "source": [
145
+ "def transcribe_and_summarize(audio, choices):\n",
146
+ " try:\n",
147
+ " result = transcript_audio(audio)\n",
148
+ " transcript = result[\"text\"]\n",
149
+ " return summarize_with_llama(transcript, context=choices)\n",
150
+ " except Exception as e:\n",
151
+ " return f\"**Error:** {str(e)}\""
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "execution_count": 12,
157
+ "id": "5e7b676e-93c5-4744-8fa9-9f779ffe7ab6",
158
+ "metadata": {},
159
+ "outputs": [
160
+ {
161
+ "name": "stdout",
162
+ "output_type": "stream",
163
+ "text": [
164
+ "* Running on local URL: http://127.0.0.1:7863\n",
165
+ "\n",
166
+ "To create a public link, set `share=True` in `launch()`.\n"
167
+ ]
168
+ },
169
+ {
170
+ "data": {
171
+ "text/html": [
172
+ "<div><iframe src=\"http://127.0.0.1:7863/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
173
+ ],
174
+ "text/plain": [
175
+ "<IPython.core.display.HTML object>"
176
+ ]
177
+ },
178
+ "metadata": {},
179
+ "output_type": "display_data"
180
+ },
181
+ {
182
+ "data": {
183
+ "text/plain": []
184
+ },
185
+ "execution_count": 12,
186
+ "metadata": {},
187
+ "output_type": "execute_result"
188
+ },
189
+ {
190
+ "name": "stderr",
191
+ "output_type": "stream",
192
+ "text": [
193
+ "Device set to use cuda:0\n",
194
+ "C:\\Users\\Tal-Jacobi\\anaconda3\\envs\\app\\Lib\\site-packages\\transformers\\models\\whisper\\generation_whisper.py:573: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
195
+ " warnings.warn(\n",
196
+ "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n",
197
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
198
+ ]
199
+ }
200
+ ],
201
+ "source": [
202
+ "gr.Interface(\n",
203
+ " fn=transcribe_and_summarize,\n",
204
+ " inputs=[\n",
205
+ " gr.Audio(type=\"filepath\", label=\"Upload Audio\"),\n",
206
+ " gr.Radio([\"Phone Call\", \"Meeting\"], label=\"Select Audio Type\")\n",
207
+ " ],\n",
208
+ " outputs=gr.Markdown(height=1000),\n",
209
+ " title=\"Audio Summarizer\"\n",
210
+ ").launch()"
211
+ ]
212
+ }
213
+ ],
214
+ "metadata": {
215
+ "kernelspec": {
216
+ "display_name": "Python 3 (ipykernel)",
217
+ "language": "python",
218
+ "name": "python3"
219
+ },
220
+ "language_info": {
221
+ "codemirror_mode": {
222
+ "name": "ipython",
223
+ "version": 3
224
+ },
225
+ "file_extension": ".py",
226
+ "mimetype": "text/x-python",
227
+ "name": "python",
228
+ "nbconvert_exporter": "python",
229
+ "pygments_lexer": "ipython3",
230
+ "version": "3.11.11"
231
+ }
232
+ },
233
+ "nbformat": 4,
234
+ "nbformat_minor": 5
235
+ }
README.md DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- title: Audio Summarizer
3
- emoji: 💻
4
- colorFrom: purple
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.24.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Summarize Recording of phone calls or meetings
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
environment.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio
4
+ accelerate
5
+ sentencepiece
6
+ bitsandbytes
7
+ ffmpeg
ner-model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:131682cd0a93e34df809b10146bc9fa6024b42a0ad0135430957b90f902f642c
3
+ size 20870614