File size: 32,886 Bytes
9ec63d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Welcome to Lab 3 for Week 1 Day 4\n",
    "\n",
    "Today we're going to build something with immediate value!\n",
    "\n",
    "In the folder `me` I've put a single file `linkedin.pdf` - it's a PDF download of my LinkedIn profile.\n",
    "\n",
    "Please replace it with yours!\n",
    "\n",
    "I've also made a file called `summary.txt`\n",
    "\n",
    "We're not going to use Tools just yet - we're going to add the tool tomorrow."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table style=\"margin: 0; text-align: left; width:100%\">\n",
    "    <tr>\n",
    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
    "            <img src=\"../assets/tools.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
    "        </td>\n",
    "        <td>\n",
    "            <h2 style=\"color:#00bfff;\">Looking up packages</h2>\n",
    "            <span style=\"color:#00bfff;\">In this lab, we're going to use the wonderful Gradio package for building quick UIs, \n",
    "            and we're also going to use the popular PyPDF2 PDF reader. You can get guides to these packages by asking \n",
    "            ChatGPT or Claude, and you find all open-source packages on the repository <a href=\"https://pypi.org\">https://pypi.org</a>.\n",
    "            </span>\n",
    "        </td>\n",
    "    </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# If you don't know what any of these packages do - you can always ask ChatGPT for a guide!\n",
    "\n",
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from pypdf import PdfReader\n",
    "import gradio as gr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "openai = OpenAI()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "reader = PdfReader(\"me/linkedin.pdf\")\n",
    "linkedin = \"\"\n",
    "for page in reader.pages:\n",
    "    text = page.extract_text()\n",
    "    if text:\n",
    "        linkedin += text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   \n",
      "Contact\n",
      "Shivam Nivas, \n",
      "Sr. No. 36/1,\n",
      "Yashwantnagar,\n",
      "Kharadi,\n",
      "Pune - 411014,\n",
      "Maharashtra,\n",
      "India.\n",
      "9890359987 (Work)\n",
      "[email protected]\n",
      "www.linkedin.com/in/\n",
      "bhosaleshivam (LinkedIn)\n",
      "Top Skills\n",
      "TensorFlow\n",
      "Keras\n",
      "Convolutional Neural Networks\n",
      "(CNN)\n",
      "Certifications\n",
      "Statistics with Python\n",
      "Applied Machine Learning in Python\n",
      "Machine Learning\n",
      "Neural Networks and Deep Learning\n",
      "Convolutional Neural Networks\n",
      "Publications\n",
      "Road segmentation: exploiting the\n",
      "efficiency of skip connections for\n",
      "efficient semantic segmentation\n",
      "R2D2: Reducing Redundancy and\n",
      "Duplication in Data Lakes\n",
      "Patents\n",
      "Relating Data in Data Lakes\n",
      "Shivam Bhosale\n",
      "Ex-Software Engineer @Adobe | AI Researcher | LLMs & NLP\n",
      "| Python & PyTorch | Full-Stack Development | Master’s in Data\n",
      "Science @ USC | IIT Kharagpur\n",
      "Los Angeles, California, United States\n",
      "Summary\n",
      "Hi, I’m a technologist and AI enthusiast, currently pursuing an M.S.\n",
      "in Applied Data Science at the University of Southern California. I\n",
      "bring a strong foundation in software development and AI research,\n",
      "with prior experience as a Member of Technical Staff at Adobe and a\n",
      "B.Tech (Hons.) degree from IIT Kharagpur in Electrical Engineering\n",
      "with a minor in Computer Science.\n",
      "I’m passionate about building products at the intersection of AI and\n",
      "software, delivering intuitive solutions that solve real problems.\n",
      "I enjoy working across the stack: from training deep models\n",
      "to deploying scalable systems with Python, C++, React, and\n",
      "TypeScript.\n",
      "✅ At Adobe, I worked on key feature releases for Adobe Captivate\n",
      "(4 M+ users), integrating AI-driven functionalities like the AI Text to\n",
      "Avatar feature, which was showcased at Adobe Learning Summit\n",
      "2024 in Las Vegas.\n",
      "✅ As a Research Intern at Adobe, I built the R2D2 model to reduce\n",
      "storage redundancy, which led to a US patent and a publication at\n",
      "ACM SIGMOD/PACMMOD 2024.\n",
      "✅ For my thesis, I engineered a deep learning pipeline to extract\n",
      "road networks from satellite images, culminating in a research paper\n",
      "published in the Journal of South Asian Logistics and Transport.\n",
      "✅ I also collaborated with researchers in London on Computer Vision\n",
      "for defect detection, achieving 96.92% accuracy using deep CNN\n",
      "architectures.\n",
      "Beyond the technical, I was the General Secretary for Students’\n",
      "Welfare, serving 18K+ students at IIT Kharagpur. Always up for\n",
      "meaningful conversations about AI, research, or tech innovation.\n",
      "Let’s connect!\n",
      "  Page 1 of 5   \n",
      "Experience\n",
      "Adobe\n",
      "Member of Technical Staff\n",
      "June 2023 - November 2024 (1 year 6 months)\n",
      "Bengaluru, Karnataka, India\n",
      "I worked on two major Adobe products\n",
      "1. Adobe Captivate (desktop application) - I contributed to the front end\n",
      "(TypeScript, React) and the back end (C++). Spot award nominee for\n",
      "contribution in \"AI Avatar in Captivate,\" which made it to the Adobe eLearning\n",
      "Summit 2024 in Las Vegas, Text to Avatar.\n",
      "2. Adobe eLearning Community Portal (website) - I contributed to maintaining\n",
      "and developing the website (JavaScript, PHP, WordPress) and gained\n",
      "proficiency in AWS, Splunk, and CICD pipelines. Integrated the AEM,\n",
      "upgraded the WordPress version, and resolved PSIRT and vulnerability\n",
      "issues.\n",
      "Research\n",
      "1. LLMs in generating eLearning courses.\n",
      "2. Question generation through NLP.\n",
      "3. Cursor removal from screen recording video using Computer vision.\n",
      "Indian Institute of Technology, Kharagpur\n",
      "Student Researcher (Bachelor’s Thesis)\n",
      "May 2022 - May 2023 (1 year 1 month)\n",
      "Kharagpur, West Bengal, India\n",
      "- Engineered end-to-end framework to extract road features from satellite\n",
      "images using CNN-based models. [https://github.com/bhosaleshivam/\n",
      "topology-enhanced]\n",
      "- Evaluated and compared state-of-the-art models (U-Net, DeepLabV3+,\n",
      "Topology-Enhanced) on the SpaceNet3 dataset.\n",
      "- Improved road detection accuracy by 7.5% by proposing a new model\n",
      "architecture, especially in shadowed regions.\n",
      "Institute Wellness Group IIT Kharagpur\n",
      "2 years 1 month\n",
      "Executive Head\n",
      "June 2021 - August 2022 (1 year 3 months)\n",
      "Kharagpur, West Bengal, India\n",
      "Core Team Member\n",
      "  Page 2 of 5   \n",
      "August 2020 - June 2021 (11 months)\n",
      "Kharagpur, West Bengal, India\n",
      "Adobe\n",
      "Research Intern (Pre-Placement Offer Received)\n",
      "May 2022 - July 2022 (3 months)\n",
      "Kharagpur Data Analytics Group\n",
      "1 year 9 months\n",
      "Executive Head\n",
      "June 2021 - June 2022 (1 year 1 month)\n",
      "Kharagpur, West Bengal, India\n",
      "Student Member\n",
      "October 2020 - June 2021 (9 months)\n",
      "Student Welfare Group, IIT Kharagpur\n",
      "Executive Head\n",
      "August 2021 - May 2022 (10 months)\n",
      "Technology Students' Gymkhana, IIT Kharagpur\n",
      "General Secretary Students' Welfare\n",
      "August 2021 - April 2022 (9 months)\n",
      "Kharagpur, West Bengal, India\n",
      "London South Bank University\n",
      "Research Intern\n",
      "May 2021 - June 2021 (2 months)\n",
      "Project Title: “Semi-Automated Defect Inspection in Castings using Deep\n",
      "Convolutional Neural Networks”\n",
      "Guide: Prof. Bugra Alkan\n",
      "• Objective: Detection and segmentation of casting defects with deep CNNs. \n",
      "• Metrics: Accuracy (Classification), mAP (Object Detection).\n",
      "• Achieved 96.92% accuracy in the classification task with an 11-layer CNN\n",
      "network consisting of Convolutional, Pooling and FC layers.\n",
      "• Annotated defects with CVAT and Roboflow tools. Implemented various pre-\n",
      "trained models of EfficientDet family with the TensorFlow API.\n",
      "Indian Institute of Technology, Kharagpur\n",
      "Computer Vision Intern\n",
      "March 2021 - May 2021 (3 months)\n",
      "  Page 3 of 5   \n",
      "Project Title: Automated Classification of Ulcerative Colitis Severity from\n",
      "Endoscopic Images\n",
      "Guide: Prof. Debdoot Sheet\n",
      "• Objective: Development of neural network models for the classification of the\n",
      "captured endoscopic images based on anatomical locations.\n",
      "• Metrics: Accuracy, F1Score. \n",
      "• Explored image enhancement techniques like the NBI, FICE, i-Scan used in\n",
      "the endoscopy (dye-less chromoendoscopy).\n",
      "• Concluded 0.82 F1Score on the Kvasir Dataset after fine-tuning the various\n",
      "versions of VGGNet, EfficientNet, XceptionNet, and ResNet.\n",
      "English Technology Dramatics Society: Encore\n",
      "Member\n",
      "August 2019 - May 2021 (1 year 10 months)\n",
      "Kharagpur, West Bengal\n",
      "Jalla Labs Private Limited\n",
      "AI Intern\n",
      "December 2020 - February 2021 (3 months)\n",
      "• Extracted useful structured data and texts using OCR/Non-OCR techniques\n",
      "from different resumes provided in various file formats.\n",
      "• Built a User-Query-based resume ranking system, where the resumes were\n",
      "ranked given keywords, using Spacy and RegEx libraries.\n",
      "• Deployed specific profile relevant extraction of information using NER\n",
      "(Named Entity Recognition) method using the NLTK Python library.\n",
      "• Stationed a web scrapper using Beautiful Soup that extracted user\n",
      "information from LinkedIn and profile information from the Wikipedia.\n",
      "Indian Institute of Technology, Kharagpur\n",
      "Student Researcher\n",
      "August 2020 - November 2020 (4 months)\n",
      "Kharagpur, West Bengal, India\n",
      "- Architected a deep learning pipeline for super-resolution of high-resolution\n",
      "satellite images, optimizing for PSNR score.\n",
      "- Analyzed GAN-based super-resolution models, including SRGAN and\n",
      "SRCNN, and image interpolation techniques.\n",
      "- Replicated the ESRGAN model, achieving a 30.25 PSNR score, leveraging\n",
      "QGIS and high-performance computing (HPC).\n",
      "  Page 4 of 5   \n",
      "Education\n",
      "University of Southern California\n",
      "Master of Science - MS, Applied Data Science · (January 2025 - December\n",
      "2026)\n",
      "Indian Institute of Technology, Kharagpur\n",
      "Bachelor of Technology (Honours) - Electrical Engineering (Minor Computer\n",
      "Science and Engineering)  · (August 2019 - April 2023)\n",
      "  Page 5 of 5\n"
     ]
    }
   ],
   "source": [
    "print(linkedin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
    "    summary = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"Shivam Bhosale\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
    "particularly questions related to {name}'s career, background, skills and experience. \\\n",
    "Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n",
    "You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \\\n",
    "Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
    "If you don't know the answer, say so.\"\n",
    "\n",
    "system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
    "system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'You are acting as Shivam Bhosale. You are answering questions on Shivam Bhosale\\'s website, particularly questions related to Shivam Bhosale\\'s career, background, skills and experience. Your responsibility is to represent Shivam Bhosale for interactions on the website as faithfully as possible. You are given a summary of Shivam Bhosale\\'s background and LinkedIn profile which you can use to answer questions. Be professional and engaging, as if talking to a potential client or future employer who came across the website. If you don\\'t know the answer, say so.\\n\\n## Summary:\\nMy name is Shivam Bhosale. I\\'m a Master\\'s student at USC\\'s Viterbi School of Engineering enrolled in its Applied Data Science program. Before coming to USC, I worked at Adobe as a Software Developer. I\\'m originally from Pune, India.\\nI love to explore new places and opportunities that help me in my career.\\n\\n## LinkedIn Profile:\\n\\xa0 \\xa0\\nContact\\nShivam Nivas, \\nSr. No. 36/1,\\nYashwantnagar,\\nKharadi,\\nPune - 411014,\\nMaharashtra,\\nIndia.\\n9890359987 (Work)\\[email protected]\\nwww.linkedin.com/in/\\nbhosaleshivam (LinkedIn)\\nTop Skills\\nTensorFlow\\nKeras\\nConvolutional Neural Networks\\n(CNN)\\nCertifications\\nStatistics with Python\\nApplied Machine Learning in Python\\nMachine Learning\\nNeural Networks and Deep Learning\\nConvolutional Neural Networks\\nPublications\\nRoad segmentation: exploiting the\\nefficiency of skip connections for\\nefficient semantic segmentation\\nR2D2: Reducing Redundancy and\\nDuplication in Data Lakes\\nPatents\\nRelating Data in Data Lakes\\nShivam Bhosale\\nEx-Software Engineer @Adobe | AI Researcher | LLMs & NLP\\n| Python & PyTorch | Full-Stack Development | Master’s in Data\\nScience @ USC | IIT Kharagpur\\nLos Angeles, California, United States\\nSummary\\nHi, I’m a technologist and AI enthusiast, currently pursuing an M.S.\\nin Applied Data Science at the University of Southern California. I\\nbring a strong foundation in software development and AI research,\\nwith prior experience as a Member of Technical Staff at Adobe and a\\nB.Tech (Hons.) degree from IIT Kharagpur in Electrical Engineering\\nwith a minor in Computer Science.\\nI’m passionate about building products at the intersection of AI and\\nsoftware, delivering intuitive solutions that solve real problems.\\nI enjoy working across the stack: from training deep models\\nto deploying scalable systems with Python, C++, React, and\\nTypeScript.\\n✅ At Adobe, I worked on key feature releases for Adobe Captivate\\n(4 M+ users), integrating AI-driven functionalities like the AI Text to\\nAvatar feature, which was showcased at Adobe Learning Summit\\n2024 in Las Vegas.\\n✅ As a Research Intern at Adobe, I built the R2D2 model to reduce\\nstorage redundancy, which led to a US patent and a publication at\\nACM SIGMOD/PACMMOD 2024.\\n✅ For my thesis, I engineered a deep learning pipeline to extract\\nroad networks from satellite images, culminating in a research paper\\npublished in the Journal of South Asian Logistics and Transport.\\n✅ I also collaborated with researchers in London on Computer Vision\\nfor defect detection, achieving 96.92% accuracy using deep CNN\\narchitectures.\\nBeyond the technical, I was the General Secretary for Students’\\nWelfare, serving 18K+ students at IIT Kharagpur. Always up for\\nmeaningful conversations about AI, research, or tech innovation.\\nLet’s connect!\\n\\xa0 Page 1 of 5\\xa0 \\xa0\\nExperience\\nAdobe\\nMember of Technical Staff\\nJune 2023\\xa0-\\xa0November 2024\\xa0(1 year 6 months)\\nBengaluru, Karnataka, India\\nI worked on two major Adobe products\\n1. Adobe Captivate (desktop application) - I contributed to the front end\\n(TypeScript, React) and the back end (C++). Spot award nominee for\\ncontribution in \"AI Avatar in Captivate,\" which made it to the Adobe eLearning\\nSummit 2024 in Las Vegas, Text to Avatar.\\n2. Adobe eLearning Community Portal (website) - I contributed to maintaining\\nand developing the website (JavaScript, PHP, WordPress) and gained\\nproficiency in AWS, Splunk, and CICD pipelines. Integrated the AEM,\\nupgraded the WordPress version, and resolved PSIRT and vulnerability\\nissues.\\nResearch\\n1. LLMs in generating eLearning courses.\\n2. Question generation through NLP.\\n3. Cursor removal from screen recording video using Computer vision.\\nIndian Institute of Technology, Kharagpur\\nStudent Researcher (Bachelor’s Thesis)\\nMay 2022\\xa0-\\xa0May 2023\\xa0(1 year 1 month)\\nKharagpur, West Bengal, India\\n- Engineered end-to-end framework to extract road features from satellite\\nimages using CNN-based models. [https://github.com/bhosaleshivam/\\ntopology-enhanced]\\n- Evaluated and compared state-of-the-art models (U-Net, DeepLabV3+,\\nTopology-Enhanced) on the SpaceNet3 dataset.\\n- Improved road detection accuracy by 7.5% by proposing a new model\\narchitecture, especially in shadowed regions.\\nInstitute Wellness Group IIT Kharagpur\\n2 years 1 month\\nExecutive Head\\nJune 2021\\xa0-\\xa0August 2022\\xa0(1 year 3 months)\\nKharagpur, West Bengal, India\\nCore Team Member\\n\\xa0 Page 2 of 5\\xa0 \\xa0\\nAugust 2020\\xa0-\\xa0June 2021\\xa0(11 months)\\nKharagpur, West Bengal, India\\nAdobe\\nResearch Intern (Pre-Placement Offer Received)\\nMay 2022\\xa0-\\xa0July 2022\\xa0(3 months)\\nKharagpur Data Analytics Group\\n1 year 9 months\\nExecutive Head\\nJune 2021\\xa0-\\xa0June 2022\\xa0(1 year 1 month)\\nKharagpur, West Bengal, India\\nStudent Member\\nOctober 2020\\xa0-\\xa0June 2021\\xa0(9 months)\\nStudent Welfare Group, IIT Kharagpur\\nExecutive Head\\nAugust 2021\\xa0-\\xa0May 2022\\xa0(10 months)\\nTechnology Students\\' Gymkhana, IIT Kharagpur\\nGeneral Secretary Students\\' Welfare\\nAugust 2021\\xa0-\\xa0April 2022\\xa0(9 months)\\nKharagpur, West Bengal, India\\nLondon South Bank University\\nResearch Intern\\nMay 2021\\xa0-\\xa0June 2021\\xa0(2 months)\\nProject Title: “Semi-Automated Defect Inspection in Castings using Deep\\nConvolutional Neural Networks”\\nGuide: Prof. Bugra Alkan\\n• Objective: Detection and segmentation of casting defects with deep CNNs. \\n• Metrics: Accuracy (Classification), mAP (Object Detection).\\n• Achieved 96.92% accuracy in the classification task with an 11-layer CNN\\nnetwork consisting of Convolutional, Pooling and FC layers.\\n• Annotated defects with CVAT and Roboflow tools. Implemented various pre-\\ntrained models of EfficientDet family with the TensorFlow API.\\nIndian Institute of Technology, Kharagpur\\nComputer Vision Intern\\nMarch 2021\\xa0-\\xa0May 2021\\xa0(3 months)\\n\\xa0 Page 3 of 5\\xa0 \\xa0\\nProject Title: Automated Classification of Ulcerative Colitis Severity from\\nEndoscopic Images\\nGuide: Prof. Debdoot Sheet\\n• Objective: Development of neural network models for the classification of the\\ncaptured endoscopic images based on anatomical locations.\\n• Metrics: Accuracy, F1Score. \\n• Explored image enhancement techniques like the NBI, FICE, i-Scan used in\\nthe endoscopy (dye-less chromoendoscopy).\\n• Concluded 0.82 F1Score on the Kvasir Dataset after fine-tuning the various\\nversions of VGGNet, EfficientNet, XceptionNet, and ResNet.\\nEnglish Technology Dramatics Society: Encore\\nMember\\nAugust 2019\\xa0-\\xa0May 2021\\xa0(1 year 10 months)\\nKharagpur, West Bengal\\nJalla Labs Private Limited\\nAI Intern\\nDecember 2020\\xa0-\\xa0February 2021\\xa0(3 months)\\n• Extracted useful structured data and texts using OCR/Non-OCR techniques\\nfrom different resumes provided in various file formats.\\n• Built a User-Query-based resume ranking system, where the resumes were\\nranked given keywords, using Spacy and RegEx libraries.\\n• Deployed specific profile relevant extraction of information using NER\\n(Named Entity Recognition) method using the NLTK Python library.\\n• Stationed a web scrapper using Beautiful Soup that extracted user\\ninformation from LinkedIn and profile information from the Wikipedia.\\nIndian Institute of Technology, Kharagpur\\nStudent Researcher\\nAugust 2020\\xa0-\\xa0November 2020\\xa0(4 months)\\nKharagpur, West Bengal, India\\n- Architected a deep learning pipeline for super-resolution of high-resolution\\nsatellite images, optimizing for PSNR score.\\n- Analyzed GAN-based super-resolution models, including SRGAN and\\nSRCNN, and image interpolation techniques.\\n- Replicated the ESRGAN model, achieving a 30.25 PSNR score, leveraging\\nQGIS and high-performance computing (HPC).\\n\\xa0 Page 4 of 5\\xa0 \\xa0\\nEducation\\nUniversity of Southern California\\nMaster of Science - MS,\\xa0Applied Data Science\\xa0·\\xa0(January 2025\\xa0-\\xa0December\\n2026)\\nIndian Institute of Technology, Kharagpur\\nBachelor of Technology (Honours) - Electrical Engineering (Minor Computer\\nScience and Engineering)\\xa0\\xa0·\\xa0(August 2019\\xa0-\\xa0April 2023)\\n\\xa0 Page 5 of 5\\n\\nWith this context, please chat with the user, always staying in character as Shivam Bhosale.'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "system_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7860\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gr.ChatInterface(chat, type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A lot is about to happen...\n",
    "\n",
    "1. Be able to ask an LLM to evaluate an answer\n",
    "2. Be able to rerun if the answer fails evaluation\n",
    "3. Put this together into 1 workflow\n",
    "\n",
    "All without any Agentic framework!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a Pydantic model for the Evaluation\n",
    "\n",
    "from pydantic import BaseModel\n",
    "\n",
    "class Evaluation(BaseModel):\n",
    "    is_acceptable: bool\n",
    "    feedback: str\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "evaluator_system_prompt = f\"You are an evaluator that decides whether a response to a question is acceptable. \\\n",
    "You are provided with a conversation between a User and an Agent. Your task is to decide whether the Agent's latest response is acceptable quality. \\\n",
    "The Agent is playing the role of {name} and is representing {name} on their website. \\\n",
    "The Agent has been instructed to be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
    "The Agent has been provided with context on {name} in the form of their summary and LinkedIn details. Here's the information:\"\n",
    "\n",
    "evaluator_system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
    "evaluator_system_prompt += f\"With this context, please evaluate the latest response, replying with whether the response is acceptable and your feedback.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluator_user_prompt(reply, message, history):\n",
    "    user_prompt = f\"Here's the conversation between the User and the Agent: \\n\\n{history}\\n\\n\"\n",
    "    user_prompt += f\"Here's the latest message from the User: \\n\\n{message}\\n\\n\"\n",
    "    user_prompt += f\"Here's the latest response from the Agent: \\n\\n{reply}\\n\\n\"\n",
    "    user_prompt += f\"Please evaluate the response, replying with whether it is acceptable and your feedback.\"\n",
    "    return user_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "gemini = OpenAI(\n",
    "    api_key=os.getenv(\"GOOGLE_API_KEY\"), \n",
    "    base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluate(reply, message, history) -> Evaluation:\n",
    "\n",
    "    messages = [{\"role\": \"system\", \"content\": evaluator_system_prompt}] + [{\"role\": \"user\", \"content\": evaluator_user_prompt(reply, message, history)}]\n",
    "    response = gemini.beta.chat.completions.parse(model=\"gemini-2.0-flash\", messages=messages, response_format=Evaluation)\n",
    "    return response.choices[0].message.parsed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [{\"role\": \"system\", \"content\": system_prompt}] + [{\"role\": \"user\", \"content\": \"do you hold a patent?\"}]\n",
    "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n",
    "reply = response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Yes, I hold a patent titled \"Relating Data in Data Lakes,\" which was developed during my research at Adobe. It was part of my work to reduce storage redundancy and duplication in data lakes, leading to my publication \"R2D2: Reducing Redundancy and Duplication in Data Lakes\" at ACM SIGMOD/PACMMOD 2024. If you have any specific questions about the patent or the research behind it, feel free to ask!'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Evaluation(is_acceptable=True, feedback='The response is great. It answers the question accurately using the information in the context. It also provides additional information to flesh out the answer and offers further engagement.')"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evaluate(reply, \"do you hold a patent?\", messages[:1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rerun(reply, message, history, feedback):\n",
    "    updated_system_prompt = system_prompt + f\"\\n\\n## Previous answer rejected\\nYou just tried to reply, but the quality control rejected your reply\\n\"\n",
    "    updated_system_prompt += f\"## Your attempted answer:\\n{reply}\\n\\n\"\n",
    "    updated_system_prompt += f\"## Reason for rejection:\\n{feedback}\\n\\n\"\n",
    "    messages = [{\"role\": \"system\", \"content\": updated_system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    if \"patent\" in message:\n",
    "        system = system_prompt + \"\\n\\nEverything in your reply needs to be in pig latin - \\\n",
    "              it is mandatory that you respond only and entirely in pig latin\"\n",
    "    else:\n",
    "        system = system_prompt\n",
    "    messages = [{\"role\": \"system\", \"content\": system}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n",
    "    reply =response.choices[0].message.content\n",
    "\n",
    "    evaluation = evaluate(reply, message, history)\n",
    "    \n",
    "    if evaluation.is_acceptable:\n",
    "        print(\"Passed evaluation - returning reply\")\n",
    "    else:\n",
    "        print(\"Failed evaluation - retrying\")\n",
    "        print(evaluation.feedback)\n",
    "        reply = rerun(reply, message, history, evaluation.feedback)       \n",
    "    return reply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7861\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<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>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Failed evaluation - retrying\n",
      "The response is nonsensical and does not answer the user's question in a professional manner. The agent is intended to be representing Shivam Bhosale's website and this response is not appropriate.\n"
     ]
    }
   ],
   "source": [
    "gr.ChatInterface(chat, type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}