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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "537645d1",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"!pip install -q requests torch bitsandbytes transformers sentencepiece accelerate gradio httpx==0.27.2"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": null,
|
| 16 |
+
"id": "49b928f5",
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [],
|
| 19 |
+
"source": [
|
| 20 |
+
"from huggingface_hub import login\n",
|
| 21 |
+
"from google.colab import userdata\n",
|
| 22 |
+
"import torch\n",
|
| 23 |
+
"import gradio as gr\n",
|
| 24 |
+
"import re\n",
|
| 25 |
+
"from transformers import (\n",
|
| 26 |
+
" AutoTokenizer,\n",
|
| 27 |
+
" AutoModelForCausalLM,\n",
|
| 28 |
+
" AutoModelForSpeechSeq2Seq,\n",
|
| 29 |
+
" AutoProcessor,\n",
|
| 30 |
+
" pipeline,\n",
|
| 31 |
+
" BitsAndBytesConfig\n",
|
| 32 |
+
")"
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"cell_type": "code",
|
| 37 |
+
"execution_count": null,
|
| 38 |
+
"id": "4e332f0e",
|
| 39 |
+
"metadata": {},
|
| 40 |
+
"outputs": [],
|
| 41 |
+
"source": [
|
| 42 |
+
"hf_token = userdata.get('HF_TOKEN')\n",
|
| 43 |
+
"login(hf_token, add_to_git_credential=True)"
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"cell_type": "code",
|
| 48 |
+
"execution_count": null,
|
| 49 |
+
"id": "f752fe77",
|
| 50 |
+
"metadata": {},
|
| 51 |
+
"outputs": [],
|
| 52 |
+
"source": [
|
| 53 |
+
"class CustomTextStreamer:\n",
|
| 54 |
+
" \"\"\"Custom text streamer to handle generated text from the model\"\"\"\n",
|
| 55 |
+
" def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):\n",
|
| 56 |
+
" self.tokenizer = tokenizer\n",
|
| 57 |
+
" self.skip_prompt = skip_prompt\n",
|
| 58 |
+
" self.skip_special_tokens = skip_special_tokens\n",
|
| 59 |
+
" self.buffer = \"\"\n",
|
| 60 |
+
" self.started = False\n",
|
| 61 |
+
"\n",
|
| 62 |
+
" def put(self, value):\n",
|
| 63 |
+
" # Handle both tensor and list inputs\n",
|
| 64 |
+
" if isinstance(value, torch.Tensor):\n",
|
| 65 |
+
" value = value.tolist()\n",
|
| 66 |
+
"\n",
|
| 67 |
+
" # Make sure value is a list of lists (batched tokens)\n",
|
| 68 |
+
" if not isinstance(value[0], list):\n",
|
| 69 |
+
" value = [value]\n",
|
| 70 |
+
"\n",
|
| 71 |
+
" for token_ids in value:\n",
|
| 72 |
+
" text = self.tokenizer.decode(token_ids, skip_special_tokens=self.skip_special_tokens)\n",
|
| 73 |
+
" if not self.started and '# ' in text:\n",
|
| 74 |
+
" self.started = True\n",
|
| 75 |
+
" text = text[text.index('# '):]\n",
|
| 76 |
+
" self.buffer += text\n",
|
| 77 |
+
"\n",
|
| 78 |
+
" def end(self):\n",
|
| 79 |
+
" return self.buffer"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"cell_type": "code",
|
| 84 |
+
"execution_count": null,
|
| 85 |
+
"id": "fcb3d8c5",
|
| 86 |
+
"metadata": {},
|
| 87 |
+
"outputs": [],
|
| 88 |
+
"source": [
|
| 89 |
+
"def transcribe_audio(audio_path):\n",
|
| 90 |
+
" \"\"\"Transcribe audio using Whisper model\"\"\"\n",
|
| 91 |
+
" torch.cuda.empty_cache()\n",
|
| 92 |
+
" AUDIO_MODEL = \"openai/whisper-large-v3\"\n",
|
| 93 |
+
" device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
|
| 94 |
+
"\n",
|
| 95 |
+
" # Load model and processor\n",
|
| 96 |
+
" speech_model = AutoModelForSpeechSeq2Seq.from_pretrained(\n",
|
| 97 |
+
" AUDIO_MODEL,\n",
|
| 98 |
+
" torch_dtype=torch.float16 if device == \"cuda\" else torch.float32,\n",
|
| 99 |
+
" low_cpu_mem_usage=True,\n",
|
| 100 |
+
" use_safetensors=True,\n",
|
| 101 |
+
" device_map=\"auto\"\n",
|
| 102 |
+
" )\n",
|
| 103 |
+
"\n",
|
| 104 |
+
" processor = AutoProcessor.from_pretrained(AUDIO_MODEL)\n",
|
| 105 |
+
"\n",
|
| 106 |
+
" # Create ASR pipeline\n",
|
| 107 |
+
" pipe = pipeline(\n",
|
| 108 |
+
" \"automatic-speech-recognition\",\n",
|
| 109 |
+
" model=speech_model,\n",
|
| 110 |
+
" tokenizer=processor.tokenizer,\n",
|
| 111 |
+
" feature_extractor=processor.feature_extractor,\n",
|
| 112 |
+
" torch_dtype=torch.float16 if device == \"cuda\" else torch.float32,\n",
|
| 113 |
+
" model_kwargs={\"use_flash_attention_2\": device == \"cuda\"}\n",
|
| 114 |
+
" )\n",
|
| 115 |
+
"\n",
|
| 116 |
+
" # Handle different input formats\n",
|
| 117 |
+
" actual_path = audio_path['path'] if isinstance(audio_path, dict) else audio_path\n",
|
| 118 |
+
"\n",
|
| 119 |
+
" # Transcribe the audio\n",
|
| 120 |
+
" result = pipe(actual_path, return_timestamps=True)\n",
|
| 121 |
+
" return result['text']\n"
|
| 122 |
+
]
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"cell_type": "code",
|
| 126 |
+
"execution_count": null,
|
| 127 |
+
"id": "bd1e45ac",
|
| 128 |
+
"metadata": {},
|
| 129 |
+
"outputs": [],
|
| 130 |
+
"source": [
|
| 131 |
+
"def clean_notes(raw_notes):\n",
|
| 132 |
+
" \"\"\"Clean up generated notes to follow the correct format\"\"\"\n",
|
| 133 |
+
" # Keep everything starting from \"# Topic\"\n",
|
| 134 |
+
" if '# Topic' in raw_notes:\n",
|
| 135 |
+
" cleaned = raw_notes[raw_notes.index('# Topic'):]\n",
|
| 136 |
+
" else:\n",
|
| 137 |
+
" cleaned = raw_notes\n",
|
| 138 |
+
"\n",
|
| 139 |
+
" # Remove any special tokens and formatting\n",
|
| 140 |
+
" cleaned = re.sub(r'<\\|.*?\\|>', '', cleaned)\n",
|
| 141 |
+
" cleaned = re.sub(r'(system|user|assistant):', '', cleaned, flags=re.IGNORECASE)\n",
|
| 142 |
+
" cleaned = re.sub(r'Today Date:.*?\\n', '', cleaned)\n",
|
| 143 |
+
"\n",
|
| 144 |
+
" # Normalize markdown headers\n",
|
| 145 |
+
" cleaned = cleaned.strip()\n",
|
| 146 |
+
" cleaned = re.sub(r'^#\\s+', '# ', cleaned, flags=re.MULTILINE)\n",
|
| 147 |
+
" cleaned = re.sub(r'^##\\s+', '## ', cleaned, flags=re.MULTILINE)\n",
|
| 148 |
+
"\n",
|
| 149 |
+
" return cleaned"
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"cell_type": "code",
|
| 154 |
+
"execution_count": null,
|
| 155 |
+
"id": "d7b84da7",
|
| 156 |
+
"metadata": {},
|
| 157 |
+
"outputs": [],
|
| 158 |
+
"source": [
|
| 159 |
+
"`def generate_notes(transcript):\n",
|
| 160 |
+
" \"\"\"Generate lecture notes from transcript using LLM\"\"\"\n",
|
| 161 |
+
" LLAMA = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
|
| 162 |
+
" system_prompt = (\n",
|
| 163 |
+
" \"Generate ONLY the lecture notes in markdown format with EXACTLY these sections:\\n\"\n",
|
| 164 |
+
" \"# Topic\\n\"\n",
|
| 165 |
+
" \"## Instructor\\n\"\n",
|
| 166 |
+
" \"## Summary\\n\"\n",
|
| 167 |
+
" \"## Key Concepts (bullet points)\\n\"\n",
|
| 168 |
+
" \"## Key Points (bullet points)\\n\"\n",
|
| 169 |
+
" \"## Takeaways (bullet points)\\n\\n\"\n",
|
| 170 |
+
" \"Do NOT include:\\n\"\n",
|
| 171 |
+
" \"- Any introductory text\\n\"\n",
|
| 172 |
+
" \"- The transcript\\n\"\n",
|
| 173 |
+
" \"- Any explanation about the format\\n\"\n",
|
| 174 |
+
" \"- Any text outside the specified sections\\n\"\n",
|
| 175 |
+
" \"The first line of your response MUST be '# Topic: [actual topic name]'\"\n",
|
| 176 |
+
" )\n",
|
| 177 |
+
"\n",
|
| 178 |
+
" user_prompt = f\"Please generate comprehensive notes from this lecture transcript:\\n\\n{transcript}\"\n",
|
| 179 |
+
"\n",
|
| 180 |
+
" messages = [\n",
|
| 181 |
+
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
| 182 |
+
" {\"role\": \"user\", \"content\": user_prompt}\n",
|
| 183 |
+
" ]\n",
|
| 184 |
+
"\n",
|
| 185 |
+
" # Configure model loading with quantization\n",
|
| 186 |
+
" quant_config = BitsAndBytesConfig(\n",
|
| 187 |
+
" load_in_4bit=True,\n",
|
| 188 |
+
" bnb_4bit_use_double_quant=True,\n",
|
| 189 |
+
" bnb_4bit_compute_dtype=torch.bfloat16,\n",
|
| 190 |
+
" bnb_4bit_quant_type=\"nf4\"\n",
|
| 191 |
+
" )\n",
|
| 192 |
+
"\n",
|
| 193 |
+
" # Load tokenizer and model\n",
|
| 194 |
+
" tokenizer = AutoTokenizer.from_pretrained(LLAMA)\n",
|
| 195 |
+
" if tokenizer.pad_token is None:\n",
|
| 196 |
+
" tokenizer.pad_token = tokenizer.eos_token\n",
|
| 197 |
+
"\n",
|
| 198 |
+
" model = AutoModelForCausalLM.from_pretrained(\n",
|
| 199 |
+
" LLAMA,\n",
|
| 200 |
+
" device_map='auto',\n",
|
| 201 |
+
" quantization_config=quant_config,\n",
|
| 202 |
+
" torch_dtype=torch.float16,\n",
|
| 203 |
+
" )\n",
|
| 204 |
+
"\n",
|
| 205 |
+
" # Prepare input\n",
|
| 206 |
+
" inputs = tokenizer.apply_chat_template(messages, return_tensors=\"pt\")\n",
|
| 207 |
+
" device = 'cuda' if torch.cuda.is_available() else 'cpu'\n",
|
| 208 |
+
" input_ids = inputs.to(device)\n",
|
| 209 |
+
"\n",
|
| 210 |
+
" # Generate text\n",
|
| 211 |
+
" with torch.no_grad():\n",
|
| 212 |
+
" try:\n",
|
| 213 |
+
" context_manager = torch.backends.cuda.sdp_kernel(enable_flash=True) if torch.cuda.is_available() else contextlib.nullcontext()\n",
|
| 214 |
+
" with context_manager:\n",
|
| 215 |
+
" output_ids = model.generate(\n",
|
| 216 |
+
" input_ids=input_ids,\n",
|
| 217 |
+
" max_new_tokens=2000,\n",
|
| 218 |
+
" do_sample=True,\n",
|
| 219 |
+
" temperature=0.7,\n",
|
| 220 |
+
" top_p=0.9,\n",
|
| 221 |
+
" eos_token_id=tokenizer.eos_token_id,\n",
|
| 222 |
+
" pad_token_id=tokenizer.pad_token_id,\n",
|
| 223 |
+
" )\n",
|
| 224 |
+
"\n",
|
| 225 |
+
" # Process the output directly\n",
|
| 226 |
+
" generated_text = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)\n",
|
| 227 |
+
"\n",
|
| 228 |
+
" # Find and extract the notes\n",
|
| 229 |
+
" if '# Topic' in generated_text:\n",
|
| 230 |
+
" generated_text = generated_text[generated_text.index('# Topic'):]\n",
|
| 231 |
+
" except Exception as e:\n",
|
| 232 |
+
" print(f\"Generation error with flash attention: {e}\")\n",
|
| 233 |
+
" # Fallback without flash attention\n",
|
| 234 |
+
" output_ids = model.generate(\n",
|
| 235 |
+
" input_ids=input_ids,\n",
|
| 236 |
+
" max_new_tokens=2000,\n",
|
| 237 |
+
" do_sample=True,\n",
|
| 238 |
+
" temperature=0.7,\n",
|
| 239 |
+
" top_p=0.9,\n",
|
| 240 |
+
" eos_token_id=tokenizer.eos_token_id,\n",
|
| 241 |
+
" pad_token_id=tokenizer.pad_token_id,\n",
|
| 242 |
+
" )\n",
|
| 243 |
+
"\n",
|
| 244 |
+
" # Process the output directly\n",
|
| 245 |
+
" generated_text = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)\n",
|
| 246 |
+
"\n",
|
| 247 |
+
" # Find and extract the notes\n",
|
| 248 |
+
" if '# Topic' in generated_text:\n",
|
| 249 |
+
" generated_text = generated_text[generated_text.index('# Topic'):]\n",
|
| 250 |
+
"\n",
|
| 251 |
+
" # Clean up notes and ensure topic has a name\n",
|
| 252 |
+
" notes = clean_notes(generated_text)\n",
|
| 253 |
+
"\n",
|
| 254 |
+
" # Check if the topic has no name and try to extract it from the transcript\n",
|
| 255 |
+
" if notes.startswith(\"# Topic\\n\"):\n",
|
| 256 |
+
" # Try to identify a topic from the transcript\n",
|
| 257 |
+
" topic_candidates = [\"RAG\", \"Retrieval Augmented Generation\", \"LLM\", \"NLP\", \"Large Language Models\"]\n",
|
| 258 |
+
" for candidate in topic_candidates:\n",
|
| 259 |
+
" if candidate.lower() in transcript.lower():\n",
|
| 260 |
+
" notes = notes.replace(\"# Topic\\n\", f\"# Topic: {candidate}\\n\")\n",
|
| 261 |
+
" break\n",
|
| 262 |
+
"\n",
|
| 263 |
+
" # If no candidate found, use a generic topic\n",
|
| 264 |
+
" if notes.startswith(\"# Topic\\n\"):\n",
|
| 265 |
+
" notes = notes.replace(\"# Topic\\n\", \"# Topic: AI Lecture\\n\")\n",
|
| 266 |
+
"\n",
|
| 267 |
+
" return notes"
|
| 268 |
+
]
|
| 269 |
+
},
|
| 270 |
+
{
|
| 271 |
+
"cell_type": "code",
|
| 272 |
+
"execution_count": null,
|
| 273 |
+
"id": "fcd9cc3a",
|
| 274 |
+
"metadata": {},
|
| 275 |
+
"outputs": [],
|
| 276 |
+
"source": [
|
| 277 |
+
"def process_audio(audio_path, progress=gr.Progress()):\n",
|
| 278 |
+
" \"\"\"Main function to process audio and generate notes\"\"\"\n",
|
| 279 |
+
" try:\n",
|
| 280 |
+
" progress(0.2, desc=\"Transcribing audio...\")\n",
|
| 281 |
+
" transcript = transcribe_audio(audio_path)\n",
|
| 282 |
+
" if not transcript:\n",
|
| 283 |
+
" return \"Error: Could not transcribe audio\"\n",
|
| 284 |
+
"\n",
|
| 285 |
+
" progress(0.6, desc=\"Generating notes...\")\n",
|
| 286 |
+
" notes = generate_notes(transcript)\n",
|
| 287 |
+
" progress(1.0, desc=\"Done!\")\n",
|
| 288 |
+
" return notes\n",
|
| 289 |
+
" except Exception as e:\n",
|
| 290 |
+
" import traceback\n",
|
| 291 |
+
" return f\"Error: {str(e)}\\n\\n{traceback.format_exc()}\""
|
| 292 |
+
]
|
| 293 |
+
},
|
| 294 |
+
{
|
| 295 |
+
"cell_type": "code",
|
| 296 |
+
"execution_count": null,
|
| 297 |
+
"id": "1f2e170d",
|
| 298 |
+
"metadata": {},
|
| 299 |
+
"outputs": [],
|
| 300 |
+
"source": [
|
| 301 |
+
"def create_ui():\n",
|
| 302 |
+
" with gr.Blocks(theme=gr.themes.Soft()) as demo:\n",
|
| 303 |
+
" gr.Markdown(\"\"\"\n",
|
| 304 |
+
" # 📝 AI Lecture Notes Generator\n",
|
| 305 |
+
" Upload a lecture audio file to generate clean, structured notes.\n",
|
| 306 |
+
" \"\"\")\n",
|
| 307 |
+
"\n",
|
| 308 |
+
" with gr.Row():\n",
|
| 309 |
+
" with gr.Column():\n",
|
| 310 |
+
" audio_input = gr.Audio(\n",
|
| 311 |
+
" type=\"filepath\",\n",
|
| 312 |
+
" label=\"Upload Lecture Audio\",\n",
|
| 313 |
+
" elem_classes=[\"audio-input\"]\n",
|
| 314 |
+
" )\n",
|
| 315 |
+
" btn = gr.Button(\"Generate Notes\", variant=\"primary\")\n",
|
| 316 |
+
"\n",
|
| 317 |
+
" with gr.Column():\n",
|
| 318 |
+
" # Use Markdown component instead of Textbox for proper rendering\n",
|
| 319 |
+
" notes_output = gr.Markdown(\n",
|
| 320 |
+
" label=\"Generated Notes\",\n",
|
| 321 |
+
" elem_classes=[\"notes-output\"]\n",
|
| 322 |
+
" )\n",
|
| 323 |
+
"\n",
|
| 324 |
+
" btn.click(\n",
|
| 325 |
+
" fn=process_audio,\n",
|
| 326 |
+
" inputs=audio_input,\n",
|
| 327 |
+
" outputs=notes_output,\n",
|
| 328 |
+
" api_name=\"generate_notes\"\n",
|
| 329 |
+
" )\n",
|
| 330 |
+
"\n",
|
| 331 |
+
" demo.css = \"\"\"\n",
|
| 332 |
+
" .audio-input { min-height: 100px; }\n",
|
| 333 |
+
" .notes-output {\n",
|
| 334 |
+
" font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n",
|
| 335 |
+
" background: #f000000;\n",
|
| 336 |
+
" border-radius: 8px;\n",
|
| 337 |
+
" padding: 15px;\n",
|
| 338 |
+
" margin-top: 10px;\n",
|
| 339 |
+
" }\n",
|
| 340 |
+
" .notes-output h1 {\n",
|
| 341 |
+
" font-size: 1.8em;\n",
|
| 342 |
+
" margin-top: 0.5em;\n",
|
| 343 |
+
" margin-bottom: 0.5em;\n",
|
| 344 |
+
" }\n",
|
| 345 |
+
" .notes-output h2 {\n",
|
| 346 |
+
" font-size: 1.4em;\n",
|
| 347 |
+
" margin-top: 1em;\n",
|
| 348 |
+
" margin-bottom: 0.5em;\n",
|
| 349 |
+
" }\n",
|
| 350 |
+
" .notes-output ul {\n",
|
| 351 |
+
" margin-left: 1.5em;\n",
|
| 352 |
+
" }\n",
|
| 353 |
+
" \"\"\"\n",
|
| 354 |
+
" return demo"
|
| 355 |
+
]
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"cell_type": "code",
|
| 359 |
+
"execution_count": null,
|
| 360 |
+
"id": "c2bb8aef",
|
| 361 |
+
"metadata": {},
|
| 362 |
+
"outputs": [],
|
| 363 |
+
"source": [
|
| 364 |
+
"if __name__ == \"__main__\":\n",
|
| 365 |
+
" demo = create_ui()\n",
|
| 366 |
+
" demo.launch(debug=True)"
|
| 367 |
+
]
|
| 368 |
+
}
|
| 369 |
+
],
|
| 370 |
+
"metadata": {
|
| 371 |
+
"kernelspec": {
|
| 372 |
+
"display_name": "Python 3 (ipykernel)",
|
| 373 |
+
"language": "python",
|
| 374 |
+
"name": "python3"
|
| 375 |
+
},
|
| 376 |
+
"language_info": {
|
| 377 |
+
"codemirror_mode": {
|
| 378 |
+
"name": "ipython",
|
| 379 |
+
"version": 3
|
| 380 |
+
},
|
| 381 |
+
"file_extension": ".py",
|
| 382 |
+
"mimetype": "text/x-python",
|
| 383 |
+
"name": "python",
|
| 384 |
+
"nbconvert_exporter": "python",
|
| 385 |
+
"pygments_lexer": "ipython3",
|
| 386 |
+
"version": "3.11.7"
|
| 387 |
+
}
|
| 388 |
+
},
|
| 389 |
+
"nbformat": 4,
|
| 390 |
+
"nbformat_minor": 5
|
| 391 |
+
}
|