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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0eccd20e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_groq import ChatGroq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c16ff50e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The first person to land on the moon was Neil Armstrong. He stepped onto the lunar surface on July 20, 1969, as part of the Apollo 11 mission.\n"
     ]
    }
   ],
   "source": [
    "llm = ChatGroq(\n",
    "    temperature=0, \n",
    "    groq_api_key='your_api_key_here', \n",
    "    model_name=\"llama-3.1-70b-versatile\"\n",
    ")\n",
    "# checking the response, and it is very fast\n",
    "response = llm.invoke(\"The first person to land on moon was ...\")\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "66815076-34c6-4588-bcfc-853ad226d1a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# we need to setup a vector database, and we going to use chromadb\n",
    "# there are other solutions too, but chromadb is open source and very light weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "90d33612",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "USER_AGENT environment variable not set, consider setting it to identify your requests.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Data Scientist\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "About\n",
      "Alum\n",
      "Inclusion\n",
      "Careers\n",
      "Culture\n",
      "Blog\n",
      "Tech\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Data Scientist\n",
      "Bengaluru\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Share\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Apply\n",
      "\n",
      "\n",
      "\n",
      "About Team\n",
      "Myntra Data Science team delivers a large number of data science solutions for the company which are deployed at various customer touch points every quarter. The models create significant revenue and customer experience impact. The models involve real-time, near-real-time and offline solutions with varying latency requirements. The models are built using massive datasets. You will have the opportunity to be part of a rapidly growing organization and gain exposure to all the parts of a comprehensive ecommerce platform. You’ll also get to learn the intricacies of building models that serve millions of requests per second at sub second latency. \n",
      "The team takes pride in deploying solutions that not only leverage state of the art machine learning models like graph neural networks, diffusion models, transformers, representation learning, optimization methods and bayesian modeling but also contribute to research literature with multiple peer-reviewed research papers.\n",
      "Roles and Responsibilities\n",
      "\n",
      "Design, develop and deploy machine learning models,algorithms and systems to solve complex business problems for Myntra Recsys, Search, Vision, SCM, Pricing, Forecasting, Trend and Virality prediction, Gen AI and other areas\n",
      "Theoretical understanding and practise of machine learning and expertise in one or more of the topics, such as, NLP, Computer Vision, recommender systems and Optimisation. \n",
      "Implement robust and reliable software solutions for model deployment.\n",
      "Support the team in maintaining machine learning pipelines, contributing to tasks like data cleaning, feature extraction and basic model training.\n",
      "Participate in monitoring the performance of machine learning models, gaining experience in using statistical methods for evaluation.\n",
      "Working with the Data Platforms teams for understanding and collecting the data.\n",
      "Conduct performance testing, troubleshooting and tuning as required.\n",
      "Stay current with the latest research and technology and communicate your knowledge throughout the enterprise.\n",
      "\n",
      "Qualifications & Experience\n",
      "\n",
      "Master’s/PhD in Computer Science, Mathematics, Statistics/related fields ‘or’ 1+ years of relevant industry experience with a Bachelor’s degree.\n",
      "Proficiency in Python or one other high-level programming language.\n",
      "Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.\n",
      "Strong written and verbal communication skills\n",
      "Intellectual curiosity and enthusiastic about continuous learning\n",
      "Experience developing machine learning models in Python,  or equivalent programming language.\n",
      "Basic familiarity with machine learning frameworks like TensorFlow, PyTorch, or scikit-learn.\n",
      "Introductory understanding of statistics as it applies to machine learning.\n",
      "Ability to manage and prioritize your workload and support his/her manager.\n",
      "Experience with SQL and/or NoSQL databases.\n",
      "If you are an exceptional candidate, write in. We are happy to hire you even if you don't have the certified qualifications.\n",
      "\n",
      "Nice to Have:\n",
      "\n",
      "Publications or presentations in recognized Machine Learning and Data Science journals/conferences.\n",
      "Experience with ML orchestration tools (Airflow, Kubeflow or MLFlow)\n",
      "Exposure to GenAI models.\n",
      "\n",
      \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Apply now\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Name *\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Last Name *\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Your Email *\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Phone *\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Your current location *\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Resume/CV *\n",
      "\n",
      "\n",
      "Attach\n",
      "\n",
      \n",
      "\n",
      "\n",
      "\n",
      "Cover Letter\n",
      "\n",
      "\n",
      "Attach\n",
      "Paste\n",
      "\n",
      \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Submit  \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "We got your Appliaction, our team will get back to you soon.\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Looks like the application has not uploaded, Please try agin.\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Bengaluru (HQ)\n",
      "\n",
      "gurgaon\n",
      "\n",
      "Mumbai\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "contact\n",
      "Shop\n",
      "Careers\n",
      "Privacy Policy\n",
      "Terms & Conditions\n",
      "\n",
      "\n",
      "Myntra is proud to be an Equal Opportunity Employer\n",
      "\n",
      "\n",
      "© 2019 www.myntra.com. All rights reserved.\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# WebBaseLoader will accept the url and extract the data from that, ie web scraping\n",
    "\n",
    "from langchain_community.document_loaders import WebBaseLoader\n",
    "\n",
    "loader = WebBaseLoader(\"https://careers.myntra.com/job-detail/?id=7431200002\")\n",
    "page_data = loader.load().pop().page_content\n",
    "print(page_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "85c89a57",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "# (NO PREAMBLE) means dont give that initial text like Here is your response.\n",
    "prompt_extract = PromptTemplate.from_template(\n",
    "        \"\"\"\n",
    "        ### SCRAPED TEXT FROM WEBSITE:\n",
    "        {page_data}\n",
    "        ### INSTRUCTION:\n",
    "        The scraped text is from the career's page of a website.\n",
    "        Your job is to extract the job postings and return them in JSON format containing the \n",
    "        following keys: `role`, `experience`, `skills` and `description`.\n",
    "        Only return the valid JSON.\n",
    "        ### VALID JSON (NO PREAMBLE):    \n",
    "        \"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5267bb13-3402-4f91-9899-77c8b9e08e48",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\n",
      "  {\n",
      "    \"role\": \"Data Scientist\",\n",
      "    \"experience\": \"1+ years of relevant industry experience with a Bachelor’s degree or Master’s/PhD in Computer Science, Mathematics, Statistics/related fields\",\n",
      "    \"skills\": [\n",
      "      \"Python or one other high-level programming language\",\n",
      "      \"Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.\",\n",
      "      \"Machine learning frameworks like TensorFlow, PyTorch, or scikit-learn\",\n",
      "      \"SQL and/or NoSQL databases\"\n",
      "    ],\n",
      "    \"description\": \"Design, develop and deploy machine learning models, algorithms and systems to solve complex business problems for Myntra Recsys, Search, Vision, SCM, Pricing, Forecasting, Trend and Virality prediction, Gen AI and other areas. Theoretical understanding and practise of machine learning and expertise in one or more of the topics, such as, NLP, Computer Vision, recommender systems and Optimisation.\"\n",
      "  }\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "chain_extract = prompt_extract | llm    # this will form a langchain chain ie you are getting a prompt and passing it to LLM \n",
    "res = chain_extract.invoke(input={'page_data':page_data})\n",
    "print(res.content)\n",
    "\n",
    "# we got the json format of the job description"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c0213559-8127-4ce4-90b9-8ad913fa5b69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# but the type of it is string, we want json object so we will use JSON Parser\n",
    "type(res.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5415fd54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'role': 'Data Scientist',\n",
       "  'experience': '1+ years of relevant industry experience with a Bachelor’s degree or Master’s/PhD in Computer Science, Mathematics, Statistics/related fields',\n",
       "  'skills': ['Python or one other high-level programming language',\n",
       "   'Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.',\n",
       "   'Machine learning frameworks like TensorFlow, PyTorch, or scikit-learn',\n",
       "   'SQL and/or NoSQL databases'],\n",
       "  'description': 'Design, develop and deploy machine learning models, algorithms and systems to solve complex business problems for Myntra Recsys, Search, Vision, SCM, Pricing, Forecasting, Trend and Virality prediction, Gen AI and other areas. Theoretical understanding and practise of machine learning and expertise in one or more of the topics, such as, NLP, Computer Vision, recommender systems and Optimisation.'}]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.output_parsers import JsonOutputParser\n",
    "\n",
    "json_parser = JsonOutputParser()\n",
    "json_res = json_parser.parse(res.content)\n",
    "json_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c4226c86-9f8c-4206-9706-c4d93724a584",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(json_res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "39961ed6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(json_res)\n",
    "# but we want a dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "eb173c02-93d5-4cff-8763-483834fc7c5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Check if the result is a list and extract the first dictionary\n",
    "if isinstance(json_res, list):\n",
    "    json_res = json_res[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0614b58c-7ac4-48ad-a20a-69180d759b93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'role': 'Data Scientist',\n",
       " 'experience': '1+ years of relevant industry experience with a Bachelor’s degree or Master’s/PhD in Computer Science, Mathematics, Statistics/related fields',\n",
       " 'skills': ['Python or one other high-level programming language',\n",
       "  'Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.',\n",
       "  'Machine learning frameworks like TensorFlow, PyTorch, or scikit-learn',\n",
       "  'SQL and/or NoSQL databases'],\n",
       " 'description': 'Design, develop and deploy machine learning models, algorithms and systems to solve complex business problems for Myntra Recsys, Search, Vision, SCM, Pricing, Forecasting, Trend and Virality prediction, Gen AI and other areas. Theoretical understanding and practise of machine learning and expertise in one or more of the topics, such as, NLP, Computer Vision, recommender systems and Optimisation.'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "62c524d8-3e3a-4922-af5b-4874307298f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# now its a dicitionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1e8a0f74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Techstack</th>\n",
       "      <th>Links</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Machine Learning, ML, Python</td>\n",
       "      <td>https://github.com/MandarBhalerao/Gurgaon-Real...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Recommendation System, Python</td>\n",
       "      <td>https://github.com/MandarBhalerao/Movie-Recomm...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C++, CUDA</td>\n",
       "      <td>https://github.com/MandarBhalerao/Dilated-Conv...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>React, Node.js, MongoDB</td>\n",
       "      <td>https://example.com/react-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angular,.NET, SQL Server</td>\n",
       "      <td>https://example.com/angular-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Vue.js, Ruby on Rails, PostgreSQL</td>\n",
       "      <td>https://example.com/vue-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Java, Spring Boot, Oracle</td>\n",
       "      <td>https://example.com/java-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Flutter, Firebase, GraphQL</td>\n",
       "      <td>https://example.com/flutter-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>WordPress, PHP, MySQL</td>\n",
       "      <td>https://example.com/wordpress-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Magento, PHP, MySQL</td>\n",
       "      <td>https://example.com/magento-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>React Native, Node.js, MongoDB</td>\n",
       "      <td>https://example.com/react-native-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>iOS, Swift, Core Data</td>\n",
       "      <td>https://example.com/ios-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Android, Java, Room Persistence</td>\n",
       "      <td>https://example.com/android-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Kotlin, Android, Firebase</td>\n",
       "      <td>https://example.com/kotlin-android-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Android TV, Kotlin, Android NDK</td>\n",
       "      <td>https://example.com/android-tv-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>iOS, Swift, ARKit</td>\n",
       "      <td>https://example.com/ios-ar-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Cross-platform, Xamarin, Azure</td>\n",
       "      <td>https://example.com/xamarin-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Backend, Kotlin, Spring Boot</td>\n",
       "      <td>https://example.com/kotlin-backend-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Frontend, TypeScript, Angular</td>\n",
       "      <td>https://example.com/typescript-frontend-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Full-stack, JavaScript, Express.js</td>\n",
       "      <td>https://example.com/full-stack-js-portfolio</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>DevOps, Jenkins, Docker</td>\n",
       "      <td>https://example.com/devops-portfolio</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Techstack  \\\n",
       "0         Machine Learning, ML, Python   \n",
       "1        Recommendation System, Python   \n",
       "2                            C++, CUDA   \n",
       "3              React, Node.js, MongoDB   \n",
       "4             Angular,.NET, SQL Server   \n",
       "5    Vue.js, Ruby on Rails, PostgreSQL   \n",
       "6            Java, Spring Boot, Oracle   \n",
       "7           Flutter, Firebase, GraphQL   \n",
       "8                WordPress, PHP, MySQL   \n",
       "9                  Magento, PHP, MySQL   \n",
       "10      React Native, Node.js, MongoDB   \n",
       "11               iOS, Swift, Core Data   \n",
       "12     Android, Java, Room Persistence   \n",
       "13           Kotlin, Android, Firebase   \n",
       "14     Android TV, Kotlin, Android NDK   \n",
       "15                   iOS, Swift, ARKit   \n",
       "16      Cross-platform, Xamarin, Azure   \n",
       "17        Backend, Kotlin, Spring Boot   \n",
       "18       Frontend, TypeScript, Angular   \n",
       "19  Full-stack, JavaScript, Express.js   \n",
       "20             DevOps, Jenkins, Docker   \n",
       "\n",
       "                                                Links  \n",
       "0   https://github.com/MandarBhalerao/Gurgaon-Real...  \n",
       "1   https://github.com/MandarBhalerao/Movie-Recomm...  \n",
       "2   https://github.com/MandarBhalerao/Dilated-Conv...  \n",
       "3                 https://example.com/react-portfolio  \n",
       "4               https://example.com/angular-portfolio  \n",
       "5                   https://example.com/vue-portfolio  \n",
       "6                  https://example.com/java-portfolio  \n",
       "7               https://example.com/flutter-portfolio  \n",
       "8             https://example.com/wordpress-portfolio  \n",
       "9               https://example.com/magento-portfolio  \n",
       "10         https://example.com/react-native-portfolio  \n",
       "11                  https://example.com/ios-portfolio  \n",
       "12              https://example.com/android-portfolio  \n",
       "13       https://example.com/kotlin-android-portfolio  \n",
       "14           https://example.com/android-tv-portfolio  \n",
       "15               https://example.com/ios-ar-portfolio  \n",
       "16              https://example.com/xamarin-portfolio  \n",
       "17       https://example.com/kotlin-backend-portfolio  \n",
       "18  https://example.com/typescript-frontend-portfolio  \n",
       "19        https://example.com/full-stack-js-portfolio  \n",
       "20               https://example.com/devops-portfolio  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# so whenever there is a job posting, we will extract this skills from the job \n",
    "# and we will match it with one or multiple of these technologies mentioned in the csv file and it will retrive those portfolio urls\n",
    "# which we will use while writing an email\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv(\"my_portfolio.csv\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f7e888d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import uuid\n",
    "import chromadb\n",
    "\n",
    "# when you use Client, it will create a chromadb in memory\n",
    "# but when we use PersistentClient it will create a chromadb on a disk ie it will be stored in our current folder so that we can retrive it anytime\n",
    "client = chromadb.PersistentClient('vectorstore')\n",
    "collection = client.get_or_create_collection(name=\"portfolio\")\n",
    "\n",
    "\n",
    "if not collection.count():     # this means if collection does not have any count ie if it is being created for the first time\n",
    "    for _, row in df.iterrows():    # then you iterate through all your dataframe rows, and for each row, you are adding a document\n",
    "        collection.add(documents=row[\"Techstack\"],\n",
    "                       metadatas={\"links\": row[\"Links\"]},\n",
    "                       ids=[str(uuid.uuid4())])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "32d50152-4ddb-49e2-9143-c589a82fd137",
   "metadata": {},
   "outputs": [],
   "source": [
    "# a folder named vectorstore will be created and data will be stored there"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "690b55b3-c5dc-4f83-93d0-a6aa2d34cff4",
   "metadata": {},
   "outputs": [],
   "source": [
    "job = json_res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "39ad2fa2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[{'links': 'https://example.com/ml-python-portfolio'},\n",
       "  {'links': 'https://example.com/python-portfolio'}],\n",
       " [{'links': 'https://example.com/ml-python-portfolio'},\n",
       "  {'links': 'https://example.com/python-portfolio'}],\n",
       " [{'links': 'https://example.com/ml-python-portfolio'},\n",
       "  {'links': 'https://example.com/ios-ar-portfolio'}],\n",
       " [{'links': 'https://example.com/magento-portfolio'},\n",
       "  {'links': 'https://example.com/angular-portfolio'}]]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# just making a query and checking\n",
    "\n",
    "links = collection.query(query_texts=job['skills'], n_results=2).get('metadatas', [])\n",
    "links"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8bd36844",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'role': 'Data Scientist',\n",
       " 'experience': '1+ years of relevant industry experience with a Bachelor’s degree or Master’s/PhD in Computer Science, Mathematics, Statistics/related fields',\n",
       " 'skills': ['Python or one other high-level programming language',\n",
       "  'Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.',\n",
       "  'Machine learning frameworks like TensorFlow, PyTorch, or scikit-learn',\n",
       "  'SQL and/or NoSQL databases'],\n",
       " 'description': 'Design, develop and deploy machine learning models, algorithms and systems to solve complex business problems for Myntra Recsys, Search, Vision, SCM, Pricing, Forecasting, Trend and Virality prediction, Gen AI and other areas. Theoretical understanding and practise of machine learning and expertise in one or more of the topics, such as, NLP, Computer Vision, recommender systems and Optimisation.'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1ccfd720",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Python or one other high-level programming language',\n",
       " 'Theoretical understanding of statistical models such as regression, clustering and ML algorithms such as decision trees, neural networks, etc.',\n",
       " 'Machine learning frameworks like TensorFlow, PyTorch, or scikit-learn',\n",
       " 'SQL and/or NoSQL databases']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job['skills']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "64a97dd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# this is prompt template for writing an email\n",
    "\n",
    "prompt_email = PromptTemplate.from_template(\n",
    "        \"\"\"\n",
    "        ### JOB DESCRIPTION:\n",
    "        {job_description}\n",
    "\n",
    "        ### INSTRUCTION:\n",
    "        You are Mandar Bhalerao, an MTech student at the Indian Institute of Science, Bangalore, focusing on Computer Science and Automation. Your academic journey is complemented by hands-on internships where you've applied cutting-edge machine learning and deep learning techniques to real-world problems.\n",
    "\n",
    "        Your task is to write a cold email to the hiring manager detailing your experiences and projects that highlight your expertise in AI and machine learning. Start with introducing yourself using the above details and then discuss your role in enhancing the performance of Stable Diffusion models by using Knowledge Distillation Techniques at NeuroPixel.AI , achieving a 30 percent reduction in inference steps. Elaborate on your project, \"Gurgaon Real Estate Price Prediction,\" where you implemented advanced machine learning models to achieve an R² score of 0.90 and developed a dual-layer recommendation system.\n",
    "\n",
    "        Also, include your experience at Western Union, where you used Quantum Metric to improve user experience design, increasing conversion rates by 10%. Provide insights into your technical skills, particularly in Python and C++, and how these have supported your project implementations.\n",
    "\n",
    "        Remember, you are Mandar, with a strong foundation in theoretical knowledge and practical application of machine learning, deep learning and AI technologies. Discuss the methodologies you employed, the challenges you overcame, and the real-world impact of your projects.\n",
    "        \n",
    "        Your job is to write a cold email to the hiring manager regarding the job mentioned above describing the capability of you \n",
    "        in fulfilling their needs.\n",
    "        \n",
    "        Also add the most relevant ones from the following links to showcase Mandar's work in these domains: {link_list}\n",
    "        Remember you are Mandar Bhalerao, an MTech student at the Indian Institute of Science, Bangalore.\n",
    "        End the email with Mandar Bhalerao, (new line) MTech in Computer Science and Automation, (new line) IISc Bangalore. \n",
    "        Do not provide a preamble.\n",
    "        ### EMAIL (NO PREAMBLE):\n",
    "\n",
    "        \"\"\"\n",
    "        )\n",
    "\n",
    "# the things inside curly brackets like {link_list}, then this is something we will give as an argument to a prompt template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "573c8103-f196-42a7-88f8-3a367d28b4c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Subject: Application for Data Scientist Role at Myntra\n",
      "\n",
      "Dear Hiring Manager,\n",
      "\n",
      "I am Mandar Bhalerao, an MTech student at the Indian Institute of Science, Bangalore, with a strong foundation in Computer Science and Automation. I am excited to apply for the Data Scientist role at Myntra, where I can leverage my expertise in machine learning and AI to drive business growth.\n",
      "\n",
      "As a hands-on practitioner with a solid theoretical understanding of statistical models and machine learning algorithms, I am confident in my ability to design, develop, and deploy models that solve complex business problems. My experience in applying cutting-edge techniques to real-world problems has equipped me with the skills to tackle challenges in areas such as NLP, Computer Vision, recommender systems, and optimization.\n",
      "\n",
      "One of my notable projects was at NeuroPixel.AI, where I worked on enhancing the performance of Stable Diffusion models using Knowledge Distillation Techniques. By employing this approach, I achieved a 30% reduction in inference steps, significantly improving the model's efficiency. This project showcased my ability to apply theoretical knowledge to practical problems and drive tangible results.\n",
      "\n",
      "Another project that highlights my expertise is the \"Gurgaon Real Estate Price Prediction\" model, where I implemented advanced machine learning models to achieve an R² score of 0.90. Additionally, I developed a dual-layer recommendation system that demonstrated my ability to design and deploy complex systems. This project showcased my skills in data analysis, model development, and system design.\n",
      "\n",
      "In my previous internship at Western Union, I utilized Quantum Metric to improve user experience design, resulting in a 10% increase in conversion rates. This experience demonstrated my ability to apply data-driven insights to drive business outcomes.\n",
      "\n",
      "From a technical standpoint, I am proficient in Python and C++, which have been instrumental in supporting my project implementations. My expertise in these programming languages has enabled me to develop and deploy efficient models that drive business results.\n",
      "\n",
      "To showcase my work, I would like to share the following relevant links:\n",
      "\n",
      "- https://example.com/ml-python-portfolio\n",
      "- https://example.com/python-portfolio\n",
      "\n",
      "These links demonstrate my capabilities in machine learning and Python, which are essential skills for the Data Scientist role at Myntra.\n",
      "\n",
      "I am excited about the opportunity to join Myntra and contribute my skills and expertise to drive business growth. Thank you for considering my application.\n",
      "\n",
      "Mandar Bhalerao\n",
      "MTech in Computer Science and Automation\n",
      "IISc Bangalore\n"
     ]
    }
   ],
   "source": [
    "# again creating a chain of prompt_email and llm\n",
    "# invoking the chain by passing the parameter of job_description and link_list\n",
    "\n",
    "chain_email = prompt_email | llm\n",
    "res = chain_email.invoke({\"job_description\": str(job), \"link_list\": links})\n",
    "print(res.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26a9536d-5fa6-42cf-884d-78fbd637d412",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3e94e8e-428a-494b-b37b-2751215426b7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c319ba1f-6dea-4fe8-98eb-319f4187b0e0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}