File size: 207,075 Bytes
7b5e0ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7961ec4aa6944ceb9cf9347d067f9908",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co./front/assets/huggingface_logo-noborder.sv…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import huggingface_hub\n",
    "huggingface_hub.notebook_login(\"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\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from huggingface_hub import snapshot_download\n",
    "# meta-llama/Llama-2-70b-chat-hf\n",
    "snapshot_download(repo_id=\"BAAI/bge-base-en-v1.5\", cache_dir=\"models\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import (\n",
    "    AutoTokenizer,\n",
    "    AutoModelForCausalLM,\n",
    "    LogitsProcessorList,\n",
    "    MinLengthLogitsProcessor,\n",
    "    StoppingCriteriaList,\n",
    "    MaxLengthCriteria,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained(\"/projectnb/ds549/students/aakash07/llm/models/llama-13b/models--meta-llama--Llama-2-13b-chat-hf/snapshots/0ba94ac9b9e1d5a0037780667e8b219adde1908c\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "999776c97fdb4467bb6ec027f51baf5a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/3 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model = AutoModelForCausalLM.from_pretrained(\n",
    "\"/projectnb/ds549/students/aakash07/llm/models/llama-13b/models--meta-llama--Llama-2-13b-chat-hf/snapshots/0ba94ac9b9e1d5a0037780667e8b219adde1908c\" , \n",
    "device_map=\"auto\",\n",
    "load_in_4bit=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_patient = \"System: You are an ophthalmologist specialist. A patient will describe their symptoms.  Convert those symptoms into actual medical terms that a doctor might use.\\nPatient Description: Doctor, over the past several weeks, I've been experiencing a persistent discomfort in my eyes. It feels like they are constantly dry and gritty. Whenever I blink, it sometimes feels as though there's sandpaper inside my eyelids. I've found myself blinking excessively, trying to generate some moisture, but it provides only temporary relief. Sometimes, the dryness becomes so intense that my eyes start to burn or sting, especially when I've been focusing on something for an extended period, like reading or working on my computer. Surprisingly, even though they feel dry, I've noticed that my eyes water more than usual. But these tears don't seem to alleviate the dryness at all.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set pad_token_id to eos_token_id because GPT2 does not have a PAD token\n",
    "model.generation_config.pad_token_id = model.generation_config.eos_token_id\n",
    "\n",
    "# input_prompt = \"A patient comes with pain in their eyes. Give list of some possible diseases that the patient can have\"\n",
    "input_ids = tokenizer(input_patient, return_tensors=\"pt\").input_ids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[\"System: You are an ophthalmologist specialist. A patient will describe their symptoms.  Convert those symptoms into actual medical terms that a doctor might use.\\nPatient Description: Doctor, over the past several weeks, I've been experiencing a persistent discomfort in my eyes. It feels like they are constantly dry and gritty. Whenever I blink, it sometimes feels as though there's sandpaper inside my eyelids. I've found myself blinking excessively, trying to generate some moisture, but it provides only temporary relief. Sometimes, the dryness becomes so intense that my eyes start to burn or sting, especially when I've been focusing on something for an extended period, like reading or working on my computer. Surprisingly, even though they feel dry, I've noticed that my eyes water more than usual. But these tears don't seem to alleviate the dryness at all. I've also noticed that my vision has become slightly blurry, especially when I'm trying to read or focus on something up close.\\n\\nMedical Terms:\\n\\n1. Dry eye syndrome (DES)\\n2. Dryness (xerostomia)\\n3. Grittiness (dysgeusia)\\n4. Burning (odynophagia)\\n5. Sting\"]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logits_processor = LogitsProcessorList(\n",
    "    [\n",
    "        MinLengthLogitsProcessor(20, eos_token_id=model.generation_config.eos_token_id),\n",
    "    ]\n",
    ")\n",
    "stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=300)])\n",
    "\n",
    "outputs = model.greedy_search(\n",
    "    input_ids, logits_processor=logits_processor, stopping_criteria=stopping_criteria\n",
    ")\n",
    "\n",
    "tokenizer.batch_decode(outputs, skip_special_tokens=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "torch.cuda.device_count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tue Oct 24 11:51:53 2023       \n",
      "+---------------------------------------------------------------------------------------+\n",
      "| NVIDIA-SMI 535.54.03              Driver Version: 535.54.03    CUDA Version: 12.2     |\n",
      "|-----------------------------------------+----------------------+----------------------+\n",
      "| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |\n",
      "| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |\n",
      "|                                         |                      |               MIG M. |\n",
      "|=========================================+======================+======================|\n",
      "|   0  Tesla V100-SXM2-16GB           On  | 00000000:18:00.0 Off |                    0 |\n",
      "| N/A   47C    P0              65W / 300W |  13487MiB / 16384MiB |      0%   E. Process |\n",
      "|                                         |                      |                  N/A |\n",
      "+-----------------------------------------+----------------------+----------------------+\n",
      "|   1  Tesla V100-SXM2-16GB           On  | 00000000:3B:00.0 Off |                    0 |\n",
      "| N/A   42C    P0              62W / 300W |  15997MiB / 16384MiB |      0%   E. Process |\n",
      "|                                         |                      |                  N/A |\n",
      "+-----------------------------------------+----------------------+----------------------+\n",
      "|   2  Tesla V100-SXM2-16GB           On  | 00000000:86:00.0 Off |                    0 |\n",
      "| N/A   42C    P0              60W / 300W |   2211MiB / 16384MiB |      0%   E. Process |\n",
      "|                                         |                      |                  N/A |\n",
      "+-----------------------------------------+----------------------+----------------------+\n",
      "|   3  Tesla V100-SXM2-16GB           On  | 00000000:AF:00.0 Off |                    0 |\n",
      "| N/A   46C    P0              62W / 300W |   2869MiB / 16384MiB |      0%   E. Process |\n",
      "|                                         |                      |                  N/A |\n",
      "+-----------------------------------------+----------------------+----------------------+\n",
      "                                                                                         \n",
      "+---------------------------------------------------------------------------------------+\n",
      "| Processes:                                                                            |\n",
      "|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |\n",
      "|        ID   ID                                                             Usage      |\n",
      "|=======================================================================================|\n",
      "|    0   N/A  N/A    998511      C   .../students/aakash07/myenv/bin/python    13484MiB |\n",
      "|    1   N/A  N/A    998511      C   .../students/aakash07/myenv/bin/python    15994MiB |\n",
      "|    2   N/A  N/A    998511      C   .../students/aakash07/myenv/bin/python     2208MiB |\n",
      "|    3   N/A  N/A    998511      C   .../students/aakash07/myenv/bin/python     2866MiB |\n",
      "+---------------------------------------------------------------------------------------+\n"
     ]
    }
   ],
   "source": [
    "!nvidia-smi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "m42-health/med42-70b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e45f8f1c0e164764a8d228804d82dab3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fetching 38 files:   0%|          | 0/38 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "85298218841d4cbba61bfa000470deaf",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)961f8a65/config.json:   0%|          | 0.00/573 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d89c48a13843416ead63cc2db33b1d10",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)f8a65/.gitattributes:   0%|          | 0.00/1.52k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "aa80a656f4cc46a89ad6e153c42d066f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)24961f8a65/README.md:   0%|          | 0.00/5.95k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0ac83184a37841dd8de63fea394949e1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)neration_config.json:   0%|          | 0.00/132 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b0f8d74e4f414faa9c8981410929c180",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00001-of-00029.bin:   0%|          | 0.00/9.44G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "765bb5b9ada542c8898c56c568a27308",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)65/added_tokens.json:   0%|          | 0.00/21.0 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "506b3ec342014f5faeb9ca4f77a11c20",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00004-of-00029.bin:   0%|          | 0.00/9.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0821db1b32b14652bfce9faa862fe668",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00003-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f31bdb331e5a4797a35f4836a7703b2e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00006-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "33c266a9d57941f7a08addc75b6d019b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00002-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d157e345b8c24bb395af25e495bfc628",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00005-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5ad781431860455388fd6a9b17719c6b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00007-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c0837d0581fb408a97062383ade10672",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00008-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c2baad798404434388f09ce3ea9953df",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00009-of-00029.bin:   0%|          | 0.00/9.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "25b06a5efc99447a8c5b82923064e7d2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00010-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8cc0b3e526ca4d1195114aa038fc57d7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00011-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0476d24cea634081b93bf52be1fa9d94",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00012-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e478e31abe3c45dd86d969d740bc9726",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00013-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "563027f0d5c44b998908448922c8a1c4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00014-of-00029.bin:   0%|          | 0.00/9.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0e7a07ee9e474e3cbbf3ed68f20179c5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00015-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ca8ce721db904dfdbc3bb20c76b60f04",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00016-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a414beeed4df41faad9960fd2d15d5b4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00017-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9d758badacf74d15bcec868e9a27e6c9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00018-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8d426858461849478c9445243d1ca162",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00019-of-00029.bin:   0%|          | 0.00/9.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "06deec770be940b087d758d37411d352",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00020-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "69f199a198244cddaf31044d45eed2e4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00021-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "29d32201b2914b65bec53c34cc3d731c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00022-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c063f7f669a542a0ad53810187bd7158",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00023-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f453da94234a472daa9fee79fb42fa09",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00024-of-00029.bin:   0%|          | 0.00/9.93G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a7a347818e104802a6dcd79e628d1776",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00025-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d1873fe8f37d4bc59e171a1f24ef0743",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00026-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e882dc09dfc045eda061a2c916b6cf0c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00027-of-00029.bin:   0%|          | 0.00/9.33G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "200668e41ebb4268ab85f97454e887d7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00028-of-00029.bin:   0%|          | 0.00/10.0G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d8220b61cd5d4eab82350fc539bcccab",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)l-00029-of-00029.bin:   0%|          | 0.00/7.56G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b6b079d68cfa4b77a4767509d6ab0e19",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)model.bin.index.json:   0%|          | 0.00/66.7k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7145ad464fc944bea4cbf9a3e1111e5a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)cial_tokens_map.json:   0%|          | 0.00/435 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1374f51ab0c944c5be36acb5d1b444fe",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading tokenizer.model:   0%|          | 0.00/500k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "221279046cf14de5ae96b0d4bd85d4f7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)okenizer_config.json:   0%|          | 0.00/825 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'/projectnb/ds549/students/aakash07/llm/models/med42-70b/models--m42-health--med42-70b/snapshots/5aed8c898108fdc60abb619c4e1fff24961f8a65'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from huggingface_hub import snapshot_download\n",
    "snapshot_download(repo_id=\"m42-health/med42-70b\", cache_dir=\"/projectnb/ds549/students/aakash07/llm/models/med42-70b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[?1l\u001b>---------------------------------------+----------------------+------------\u001b[4h-\u001b[4l========|Tue Oct 24 13:12:52 2023\u001b[1;75H5\u001b[3;19H5\u001b[20;10H4\u001b[20;47H2023\u001b[20;71H 46\u001b[24;80H\u001b[1;75H7\u001b[3;19H7\u001b[20;10H5\u001b[20;31H233\u001b[20;48H101\u001b[20;71H100\u001b[24;80H\u001b[1;75H9\u001b[3;19H9\u001b[20;10H4\u001b[20;33H0\u001b[20;49H83\u001b[20;71H 41\u001b[24;80H\u001b[1;72H3:01\u001b[3;16H3:01\u001b[20;10H3\u001b[20;32H21\u001b[20;48H255\u001b[20;72H 0\u001b[24;80H\u001b[1;75H3\u001b[3;19H3\u001b[20;31H 80\u001b[20;48H307\u001b[24;80H\u001b[1;75H5\u001b[3;19H6\u001b[20;49H93\u001b[24;80H\u001b[1;75H8\u001b[3;19H8\u001b[20;10H2\u001b[20;32H67\u001b[24;80H\u001b[1;74H10\u001b[3;18H10\u001b[20;10H1\u001b[24;80H\u001b[24;1H\u001b[2J\u001b[?47l\u001b8"
     ]
    }
   ],
   "source": [
    "!watch nvidia-smi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('/projectnb/ds549/students/aakash07/DrVai/data/Review_of_ophthalmology.json') as f:\n",
    "    json_file = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "chapter_names = list(json_file.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Diseases of Lens',\n",
       " 'Glaucoma',\n",
       " 'Cornea',\n",
       " 'Conjunctiva',\n",
       " 'Sclera and Episclera',\n",
       " 'Uveitis',\n",
       " 'Orbit',\n",
       " 'Ocular Adenexae',\n",
       " 'Lacrimal Drainage',\n",
       " 'Neurophthalmology',\n",
       " 'Fundus',\n",
       " 'Vitreous',\n",
       " 'Squint and Optics',\n",
       " 'Community',\n",
       " 'Embryology',\n",
       " 'Recent Advances']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chapter_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'C H A P T E R': {'start_index': 758656, 'page_number': 381}}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_file['Recent Advances']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C H A P T E R\\nDiseases of Lens\\nANATOMY \\uf077 It is secreted at embryonic stage as a\\nbasement membrane of lens epithelium\\n\\uf077 Lens is biconvex in shape. (Thickest basement membrane in\\n\\uf077 Diameter: 9–10 mm. the body).\\n\\uf077 Refractive index: 1.39. \\uf077 It is thicker anteriorly than posteriorly\\nand at the equator than the poles.\\n\\uf077 Total refractive power: 16 D–17 D.\\nCapsule is thinnest at the\\nStructure of Lens posterior pole.\\n2. Anterior epithelium: It constitutes single\\nEquatorial layer of epithelium cells. They are cuboidal\\nIris Epithelium lens bow\\nat the centre and become columnar at the\\nperiphery.\\n3. Lens fibres: They are of two types:\\na. Nucleus (old lens fibres). It is further\\nCiliary divided into: Embryonic (1–3 months\\nbody gestation), Foetal, Infantile, Adult.\\nHexagonal\\nZonules Cortex Capsulelens fibers b. Cortex (youngest lens fibres). Embr-\\nEmbryonic yonic nucleus is the oldest fibres.\\nnucleus\\n4. Zonules of zinn: They are the suspensory\\nFig. 1.1: Structure of lens ligaments which support the nucleus.\\nLens constitutes of:\\nPHYSIOLOGY\\n1. Lens capsule:\\n\\uf077 80% of glucose is metabolized anaerobically.\\n\\uf077 Lens capsule is a thin, transparent,\\nThis leads to formation of lactic acid in the\\nhyaline collagenous membrane which\\nlens which diffuses into the aqueous\\nsurrounds the lens completely.\\nhumour. Hence, absence of lens will lead to\\n\\uf077 Lens capsule is highly elastic but does decreased lactic acid in the aqueous\\nnot have any elastic tissue. humour.\\n12 Review of Ophthalmology\\n\\uf077 Lens derives its nutrition from aqueous Classification\\nhumour.\\na. Etiologically: (1) Senile (2) Metabolic\\n\\uf077 Antioxidative system of the lens constitutes (3) Complicated (4) Traumatic (5) Radia-\\nof Vitamin C, i.e., ascorbic acid, Vitamin tional (6) Toxic (7) Electric (8) Skin diseases\\nE and glutathione. The detoxifying (9) Osseus diseases (10) Syndromes.\\nenzymes which are responsible to\\nb. According to maturity: (1) Immature\\ncounteract the oxidative damage in the lens\\n(2) Mature (3) Hypermature.\\nare catalase and superoxide dismutase.\\nCataract occurs due to the oxidative c. Anatomically: (1) Capsular cataract–\\ndamage to the lens. Anterior and Posterior (2) Subcapsular\\ncataract–Anterior and Posterior (3) Cortical\\n\\uf077 Glutathione plays a central role in\\ncataract (4) Supranuclear cataract (5)\\nprotecting the lens from oxidative damage.\\nNuclear cataract (6) Polar cataract–\\nIt is a tripeptide synthesized in the lens.\\nAnterior and Posterior.\\nIts levels are reduced in patients of\\ncataract. Most common cause of acquired\\ncataract is senile cataract.\\n\\uf077 Myoinositol is actively transported into the\\nlens by sodium dependent carrier mediated\\nCONGENITAL AND DEVELOPMENTAL\\nmechanism. Its levels are markedly\\nCATARACT\\nreduced in cataract. It is a precursor of\\nmembrane phosphoinositides which are\\nEtiology\\ninvolved in Na/Ka ATPase function. It also\\nparticipates in ascorbic acid transport in\\na. Heredity: Usually dominant.\\nthe lens.\\nb. Maternal factors:\\nLens 1. Malnutrition.\\nWater 99% 66% 2. TORCHS infections, i.e., Toxoplas-\\nNa+ 144 20 mosis, rubella, cytomegalovirus, Herpes\\nand syphilis.\\nNa + K + AT Pase\\nK+ 4.5 125 3. Drug: Thalidomide, Corticosteroid.\\nGlucose 6 1 4. Radiation.\\nLactic acid 7.4 14\\nc. Foetal or Infantile factor:\\nProteins 0.04% (S) 33%\\n1. Anoxia.\\nActive Transport\\nDiffusion 2. Metabolic:\\n(S) Synthesis\\na. Galactosemia–Galactokinase defi-\\nFig. 1.2 ciency.\\nDevelopment of lens: Lens develops from b. Neonatal hypoglycemia.\\nlens vesicle which is derived from surface 3. Congenital anomaly: Lowe’s syndrome,\\nectoderm. Myotonia dystrophica.\\nCataract 4. Birth trauma.\\n5. Malnutrition.\\nDefinition: Any interference in the optical\\nhomogeneity of the lens is called cataract. d. Idiopathic.Diseases of Lens 3\\nTypes\\nCONGENITAL RUBELLA SYNDROME\\na. Cataracta centralis pulverulenta:\\nIt is characterized by the classical triad of–\\n1. Embryonic nuclear cataract.\\nCataract, Headache and Deafness.\\n2. Opacity has powdery appearance.\\n3. Does not affect vision.\\nb. Zonular/lamellar: MNEMONIC\\nMost common type of congenital cataract\\nCHD (Cataract, Headache and Deafness)\\ncausing decreased vision.\\n1. Involves the foetal nucleus. Ocular Features\\n2. Etiology may be: 1. Microphthalmos.\\n2. Cataract: Pearly nuclear or lamellar.\\nA. Genetic: Dominant inheritance.\\n3. Retinopathy: Salt-pepper retinopathy at\\nB. Environmental: (1) Vitamin D defi-\\nposterior pole. It is non progressive.\\nciency, (2) Rubella infection in 7th–\\n4. Glaucoma.\\n8th week of gestation.\\n5. Optic nerve abnormalities.\\n3. Usually bilateral.\\n6. Other complications:\\n4. Causes severe visual defect.\\nA. Pendular nystagmus and strabismus.\\n5. Small linear opacities towards\\nB. Keratitis.\\nequator called Riders are charac-\\nteristic of lamellar cataract. C. Iritis and iris atrophy.\\nD. Extreme refractive error.\\nc. Sutural cataract: Along anterior and\\nposterior sutures. The most common type of cataract in\\nrubella is–Nuclear Pearly.\\nd. Anterior polar cataract.\\nACQUIRED CATARACT\\ne. Posterior polar cataract.\\nf. Coronary cataract: Occurs in adolescence, 1.Senile Cataract\\nclub shaped opacities peripheral in\\nEtiology:\\ndistribution.\\n\\uf077 Heredity.\\ng. Punctate cataract: Also called Blue-dot\\n\\uf077 Dehydrational crisis in diarrhea and\\ncataract or Cataracta-punctate-cerulea–\\ncholera.\\nBluish dots in peripheral part of adolescent\\n\\uf077 UV-Rays.\\nnucleus and deeper cortex are seen. It is the\\nmost common type of congenital cataract. \\uf077 Dietary deficiency of vitamin E,C,B and\\nproteins.\\nh. Total congenital cataract.\\nIt is broadly divided into:\\ni. Congenital membranous cataract: It is due\\n\\uf077 Nuclear.\\nto total or partial absorption of congenital\\ncataract. \\uf077 Cortical.4 Review of Ophthalmology\\nNuclear Cataract: lies right in the pathway of the axial\\nrays, at the nodal point of the eye\\nIt occurs due to following factors:\\n(Nodal point of eye is just behind the\\nw Increased age-related nuclear sclerosis. lens) and thus causes an early loss of\\nw Increase in insoluble proteins. visual acuity.\\nw Deposition of pigments like urochrome\\nMaturation of Cortical Cataract:\\nand melanin.\\n1. Stage of Lamellar Separation.\\nSclerosis makes the lens hard and inelastic\\nleading to shrunken lens with wrinkled 2. Stage of Incipient Cataract.\\ncapsule due to leakage of water. This 3. Immature Senile Cataract (Intumescent\\ncauses inability to accommodate and Cataract—It causes frequent change of\\nprogressive index myopia. It manifests as presbyopic glasses).\\n“Second sight of old age”.\\n4. Mature Senile Cataract (Ripe Cataract).\\nMaturation of Nuclear Cataract: 5. Hypermature Morgagnian Cataract.\\nA. Immature cataract. Causes of frequent change of\\npresbyopic glasses are:\\nB. Mature cataract.\\n1. Early cataract (Intumescent cataract).\\nC. Hypermature nuclear sclerotic cataract.\\n2. Late stage of primary open angle\\nNuclear Cataract may be Tinted:\\nglaucoma.\\nA. Amber. 3. Diabetes mellitus (Hyperglycemia\\nB. Brown—Cataracta Brunescens. causes myopic shift and hypoglycemia\\ncauses hypermetropic shift).\\nC. Black—Cataracta Nigra.\\nD. Red—Cataracta Rubra. Note:\\nNuclear cataract causes Hamarlopia (Day w Intumescent cataract is a cause of\\nBlindness). Phacomorphic glaucoma.\\nCauses of Hamarlopia: w Morgagnian cataract is the most\\ncommon form of senile cataract\\n1. Central corneal opacities.\\ncausing glaucoma.\\n2. Central lenticular opacities. w Most common complication of\\n3. Congenital absence of cones. Morgagnian cataract is Phacolytic\\nCortical Cataract: Decreased levels of Glaucoma. Other complication\\npossible is Phacoanaphylactic\\ntotal protein, amino acids and potassium\\nuveitis.\\nalongwith increased concentration of Na+,\\nleads to hydration and coagulation of w Most common complication of\\nproteins causing cataract. It is of two types: hypermature nuclear sclerotic\\ncataract is subluxation of lens.\\n1. Cuneiform: It generally starts as wedge\\nshaped radial spokes from periphery to 2.Metabolic Cataract\\ncenter. Hence visual disturbances are\\ncomparatively at the late stage. a. Diabetes Mellitus:\\n2. Cupulliform: These are posterior sub- w Causes senile cataract at early age (i.e.,\\ncapsular opacities. This type of cataract presenile cataract).Diseases of Lens 5\\nw Typical morphology is Snow-Flake descements membrane is due to\\nOr Snow-Storm Cataract. copper deposition and is patho-\\nw Increased glucose leads to sorbitol gnomic of Wilson’s disease.\\npathway (Due to saturation of other Note: Fleischer’s ring is iron\\nmetabolic pathways like glycolysis and deposition at the base of the cone in\\nkrebs cycle. When enzyme hexokinase patients of keratoconus.\\nis saturated or inhibited, sorbitol path- e. Lowe’s Syndrome (Oculocere-\\nway is the only pathway remaining for brorenal syndrome): It is an\\nglucose metabolism.\\ninborn error of aminoacid metabolism.\\nw This sorbitol accumulation in the lens Ocular Features:\\n(Due to Aldose Reductase pathway)\\n1. Congenital cataract.\\nleads to overhydration of lens causing\\ncataract. 2. Microphakia.\\n3. Posterior lentiglobus/Posterior Lenti-\\nb. Galactosaemia:\\nconus.\\nw Deficiency of GPUT (Galactose-\\n4. Glaucoma.\\nphosphouridyl transferase) causes Oil\\nDroplet Cataract. f. Mannosidosis: Deficiency of alpha-\\nw Deficiency of Galactokinase causes mannosidase leads to mannose rich\\noligosaccharides in tissues causing\\nlamellar cataract.\\nspoke like posterior capsular cataract.\\nc. Hypocalcaemia: Due to decreased\\nparathyroid activity, i.e., Hypoparathy- g. Fabry’s Disease:\\nroidism.\\nw It is due to deficiency of alpha-\\nd. Wilson’s Disease: Wilson’s disease\\nGalactosidase.\\n(Hepatolenticular degeneration) is a\\nOcular Features:\\nrare condition caused by deficiency of\\nalpha —globulin, ceruplasmin. It is 1. Spoke like cataract—No impairment\\n2\\ncharacterized by widespread deposition of vision.\\nof copper in the tissues and becomes\\n2. Vortex Keratopathy.\\nmanifest in 3 ways:\\n1. Liver disease. 3.Complicated Cataract\\n2. Neurological involvement of the\\nClinical Features:\\nbasal ganglion.\\n3. Psychiatric features. w It is posterior cortical or more\\ncommonly posterior subcapsular due to\\nOcular Features are:\\nposterior segment disease.\\n1. Sunflower Cataract: This type of\\nw It is anterior cortical due to anterior\\ncataract also occurs in blunt trauma\\nsegment disease.\\nwhere it is also known as Rossete\\nCataract. w Most commonly it is Posterior sub-\\ncapsular.\\n2. K.F. Ring (Kayser-Fleischer Ring):\\nGolden brown discoloration of w Spreads axially.6 Review of Ophthalmology\\nw Has Bread Crumb appearance. 5. Busulphan: It is given for treatment of\\nw Polychromatic luster is the patho- CML. It causes PSC, i.e., posterior sub-\\ncapsular cataract.\\ngnomic feature of complicated\\ncataract. 6. Amiodarone: Anterior subcapsular\\ncataract. Also causes vortex keratopathy.\\nCauses:\\n7. Cu, Fe, Au: Gold is used for the\\n1. Inflammatory–Iridocyclitis, Pars- treatment of rheumatoid arthritis and\\nplanitis, Choroiditis, Endophthalmitis, causes ASC.\\nCorneal ulcer. w Most common ocular compli-\\n2. Degenerative–Retinitis pigmentosa, cation of steroid is–Glaucoma.\\nBest disease (It is dystrophy of RPE Occurrence of glaucoma is\\ncells), Myopia. genetically monitored. Less common\\nin short term steroid therapy or\\n3. Tumours.\\nalternate day therapy.\\n4. Glaucoma–Primary and Secondary.\\nw Oral steroids more commonly\\n5. Retinal detachment. lead to cataract and topical\\nHypermetropia is not a degenerative steroids more commonly lead to\\ndisease hence complicated cataract glaucoma.\\ndoes not occur in hypermetropia but w Both phenothiazines (chlorpromazine)\\noccurs in myopia. and chloroquine can cause cataract\\nbut phenothiazines are most\\n4.Toxic Cataract\\ncommonly mentioned in relation to\\ncataract formation.\\nCauses:\\n5.Traumatic Cataract\\n1. Corticosteroids: Typically discoid,\\nposterior sub-capsular cataract which\\nFeatures of Blunt Trauma/\\nat a later stage involves anterior\\nsubcapsular region. Steroids both Concussion Injury:\\nsystemic and topical are cataracto-\\n1. Rossette-shaped cataract: It is also\\ngenic.\\ncalled sunflower cataract. It mainly\\n2. Phenothiazines: Deposition of fine yellow involves posterior cortex first.\\nbrown granules under the anterior 2. Vossius ring: It is the imprint of iris\\ncapsule in pupillary zone which develop pigment on the anterior capsule of the\\ninto large stellate opacities and finally lens, due to blunt trauma.\\nanterior polar cataract.\\n3. Berlins edema: It is also called\\n3. Chloroquine: (Not hydroxychloroquine) Commotio Retinae. It is macular edema\\ncauses white, flaky posterior sub- after blunt trauma and is morpho-\\ncapsular cataract. logically described as “cherry-red spot”.\\n4. Anticholinesterases: Commonly causes 4. Angle-recession glaucoma: Angle\\nanterior subcapsular cataract. Mainly recession occurs due to tear in ciliary\\ndue to long acting miotics like DFP, body after blunt trauma. Glaucoma is\\nEcothiophate, Demecarium bromide. due to damage in trabecular network.Diseases of Lens 7\\n6.Radiational Cataract 2. Ptosis—Usually bilateral.\\nw It occurs due to damage to lens by all 3. Pigmentary retinopathy, i.e., salt\\ntypes of radiations namely UV rays, and pepper fundus.\\nInfrared rays, X-rays/Y-rays or neutrons. 4. Pupillary changes—Light-near\\nw Infrared rays causes “Glass Blower’s” or dissociation.\\nGlass worker’s cataract. 5. Low intraocular—pressure.\\nw MRI has no radiation exposure as it is Hence, we remember its ocular\\ndone by ultrasonic energy and not features as 5 Ps.\\nradiations.\\n2. Atopic dermatitis: Stellate opacities\\nw Most common type of radiational\\nmostly posterior.\\ncataract is Posterior subcapsular\\n3. Diabetes mellitus: It causes snowstorm\\ncataract. They are punctate subcapsular\\nor snowflake opacities.\\nopacities which mature rapidly.\\n7.Syndermatotic Cataract SYNDROMES ASSOCIATED WITH\\nCATARACT\\nThese are cataracts which occur due to skin\\ndiseases.\\nA.Down’s Syndrome\\nCauses:\\nOcular Features:\\nw Atopic dermatitis is the most common 1. Shortened and slanted palpebral fissure.\\ncause.\\n2. Neonatal ectropion.\\nw Poikiloderma.\\n3. Lateral trichiasis and entropion.\\nw Scleroderma.\\n4. Keratoconus.\\n8.Pre-Senile Cataract 5. Cataract.\\nThese are cataracts which occur in young 6. Brushfield spots are light coloured\\nage. spots on iris.\\nB.Others\\nCauses:\\nw Werner’s syndrome.\\n1. Myotonic dystrophy: Myotonic dys-\\ntrophy or Dystrophia myotonica is a w Rothmund’s syndrome.\\ngeneralized dominantly inherited\\nmyopathy characterized by myotonia of CLINICAL FEATURES OF CATARACT\\nperipheral muscles and muscle wasting.\\n1. Misty vision with distortion of vision.\\nOcular Features:\\n2. Loss of vision.\\n1. Pre-senile cataract\\n3. Coloured halos.\\nw “Christmas-tree cataract”—\\nOther causes of coloured halos are:\\nposterior subcapsular, stellate\\nplaque. w Mucopurulent conjunctivitis.\\nw Small iridescent, polychromatic w Acute congestive angle closure\\ncrystals. glaucoma.8 Review of Ophthalmology\\nFinchams Test: It helps to know the 4. Phacoemulsification: Cataract removal\\ncause of halos whether it is due to cataract using phacoemulsification is achieved by\\nor glaucoma. A stenopic slit is passed in ultrasonic fragmentation and aspiration of\\nfront of the eye which is seeing the halos, the lens material. The tip of the phaco-\\nif the halos break then it is due to cataract emulsification hand piece is composed of a\\nand if not then it is due to glaucoma. hollow (approximately 1 mm) titanium\\n4. Black spots in front of eyes. needle that transmits vibrations at a high\\nspeed (30,000 to 60,000 cycles/sec) to\\n5. Glare.\\nemulsify the cataract. These vibrations are\\n6. Uniocular diplopia or polyopia seen in stage\\ntransferred from piezoelectric or magneto-\\nof intumescent cataract.\\nstrictive crystals.\\n5. Lensectomy with anterior vitrectomy:\\nCOMPLICATIONS OF LONG\\nLens in toto with anterior vitreous is\\nSTANDING CATARACT\\nremoved. This procedure is specially opted\\n1. Uveitis. in children when ICCE is indicated. This\\nis because in children there is strong\\n2. Subluxation or dislocation of lens (In\\nadhesion between posterior surface of lens\\nnuclear sclerotic cataract).\\nand anterior hyaloid face of vitreous and\\n3. Glaucoma: Phacoanaphylactic/Phaco-\\nhence any pulling can cause retinal\\nmorphic/Phacolytic.\\ndetachment.\\nMANAGEMENT OF CATARACT 6. Mydriatics/optical iridectomy: This\\nprocedure can be opted for congenital\\nThe first line of treatment in cataract is stationary cataracts but now it is more of\\nsurgery. a theoretical purpose and not opted for.\\nModalities of Treatment of Cataract 7. ECCE with PC IOL with primary posterior\\n1. ICCE (Intracapsular cataract extraction): It capsulotomy: Primary posterior capsulo-\\nconstitutes removal of lens alongwith the tomy is done in children as they are very\\ncapsule. The methods of ICCE are: 1. prone to develop posterior capsular\\nCryoextraction 2. Forceps method (Arrugas opacification after few days of surgery due\\nforceps are used) 3. Irisophake 4. Wire to intense postoperative inflammations.\\nVectis 5. Indiansmith method (Also called\\nDiscission and Needling done in\\ntumbling method). The best method is\\ncongenital cataract are now obsolete\\ncryoextraction. Today the only\\nprocedures.\\nindication of ICCE is subluxation of\\nPreoperative evaluation of cataract\\nlens.\\nsurgery includes:\\n2. ECCE with PC IOL (Extracapsular cataract\\nextraction): It constitutes removal of lens I. General Examination for:\\nleaving behind the posterior capsule on\\n\\uf077 Diabetes mellitus.\\nwhich artificial lens is implanted.\\n\\uf077 Hypertension.\\n3. Manual small incision cataract surgery:\\n\\uf077 Cardiac problems.\\nThis is sutureless small incision cataract\\nsurgery without using the phacoprobe. \\uf077 Obstructive lung disorders.Diseases of Lens 9\\nw Any potential source of infection in the w State of endothelial cells.\\nbody like—septic gums, urinary tract\\nE. Intraocular pressure measurement.\\ninfection.\\nF. Gonioscopy is not done routinely. It is\\nII. Ocular Examination:\\nonly when the IOP is found raised, we\\nA. Retinal function test: can do to assess the state of the angle.\\n1. Perception of light.\\nSURGICAL TECHNIQUES\\n2. Projection of rays—Easy test to\\nassess the function of peripheral\\nECCE\\nretina.\\n(a)Limbal partial thickness incision is made\\n3. Test for Marcus Gunn pupillary\\nfrom 10 o’ clock to 2 o’ clock.\\nresponse.\\n(b)Anterior chamber is formed by viscoelastic\\n4. Two light discrimination.}\\nthrough a small full thickness incision.\\nMacular\\n5. Maddox rod test.\\nfunction (c) Anterior capsulotomy is done (Can opener\\n6. Laser interferometry. test\\ntechnique or Envelope technique).\\n7. Stereoacuity.\\n(d)Partial thickness limbal incision is made\\n8. Color perception—It indicates that full-thickness by corneal scissors.\\noptic nerve is relatively normal.\\n(e) Hydrodissection and hydrodelineation is\\n9. Entoptic visualization is also used to done.\\nindicate retinal function but it is a\\n(f) Nucleus is prolapsed.\\nsubjective test where the patient\\n(g)Cortical matter is aspirated.\\nperceives his own vasculature.\\n10. Indirect ophthalmoscopy. (h)IOL is implanted.\\nB. Objective tests are indicated if some (i) Incision is sutured by radial sutures.\\nretinal pathology suspected. BSS (i.e., Basal salt solution) with glutathione\\ni. ERG—Electroretinogram. is the ideal irrigating fluid in cataract\\nsurgery as it resembles the aqueous humour\\nii. EOG—Electrooculogram.\\nmost.\\niii. VER—Visually-Evoked-Response.\\nAfter cataract surgery, stitches are removed\\nC. Search for local source of infection: at 6 weeks post-operative, and refraction\\nw Conjunctivitis. should be done after 2 weeks of the suture\\nremoval so that any change in corneal\\nw Blepharitis.\\ncurvature due to the sutures (tight or loose)\\nw Meibomitis. is stabilized. (But if in the question, 8 weeks\\nw Lacrimal sac infection—lacrimal is not an alternative, we will mark 6 weeks\\nas the correct answer). This schedule is for\\nsyringing is done.\\nconventional cataract surgery (with sutures).\\nD. Slit lamp examination of anterior\\nIn case of sutureless cataract surgery\\nsegment of eye:\\nwith phaco, refraction can be done after\\nw Presence of uveitis. 1–2 weeks.10 Review of Ophthalmology\\nSmall Incision Cataract Surgery Advantages:\\n(SICS)\\n1. Normal life activity regained faster.\\nECCE can also be done through self-sealing 2. Minimum post-operative astigmatism.\\nsmall incision, which does not need any\\nNote:\\nsutures. This sutureless surgery can be either\\n\\uf077 Vitreous haemorrhage and RD occurs\\nby phaco machine, which is called Phaco-\\nmore commonly in ICCE due to vitreous\\nemulsification or manually called Non-phaco\\ntraction. In ECCE since the posterior\\nsutureless cataract surgery.\\ncapsule (PC) is intact this complication\\n1. Manual small incision cataract\\nis less common.\\nsurgery:\\n\\uf077 Cystoid macular edema (CME) after\\nProcedure:\\ncataract surgery (called Irvine-Gass\\n(a) Triplanar scleral tunnel is made. syndrome) is attributed to both vitreous\\ntraction and prostaglandins released\\n(b) Anterior chamber is formed by\\nduring inflammation. As there is an\\nviscoelastic.\\nintact PC in ECCE hence again this\\n(c) Anterior capsulotomy is done (Preferably\\ncomplication is less common in ECCE.\\nCCC, i.e., continues curvilinear capsu-\\n\\uf077 IOL implantation in diabetic patient\\nlorrhexis or can opener).\\nshould be done after PRP (pan-retinal\\n(d) Hydrodissection and hydrodelineation is\\nphotocoagulation). But if the patient has\\ndone.\\ndeveloped diabetic cataract then IOL\\n(e) Nucleus is first prolapsed in the anterior implantation becomes a prerequisite for\\nchamber and then prolapsed out by proper visualization of fundus and PRP.\\nviscoelastic called viscoexpression.\\n\\uf077 An uncontrolled glaucoma is a contra-\\n(f) Cortical matter is aspirated and IOL indication for IOL implantation surgery.\\nimplanted. If we have to implant a First the glaucoma has to be controlled\\nnonfoldable lens then we need to extend as increased intraocular tension can\\nour scleral incision. lead to per-operative complications.\\n(g) No sutures are required as it is a self- \\uf077 Phacoemulsification is less preferred in\\nsealing incision. black cataract, i.e., grade 4 or grade 5\\nnuclear cataract.\\n2. Phacoemulsification:\\nMANAGEMENT OF PEDIATRIC\\nProcedure:\\nCATARACT\\n(a) Scleral tunnel with an external\\nincision of 3 mm to 3.5 mm is made/ In both bilateral and unilateral cases,\\nCorneal incision can also be made. primary implantation is indicated as soon as\\nthe patient is fit for anesthesia, ideally\\n(b) Circular curvilinear capsulorrhexis\\nbetween 2 and 3 months of age. The earlier\\ndone.\\nthe surgery is done, the better is the chance\\n(c) Hydrodissection and Hydrodelineation\\nthat deep amblyopia can be overcome as the\\ndone and lens material emulsified and\\nvisual reflexes develop by 5–6 months of age.\\naspirated along with the cortical\\nUnilateral cases are particularly at a risk of\\nmatters.\\ndeveloping deep amblyopia and hence dealt\\n(d) Foldable IOL implanted. with more seriously.Diseases of Lens 11\\nManagement can be divided according to two \\uf077 PC-IOL–It is of two types J-loop or\\nage groups: C-loop. C-loop is preferred. Best option for\\n1. Patients younger than 2 years. IOL implantation is posterior capsule as it\\nis most physiological.\\n2. Patients between 2–8 years.\\nBiometry:\\nGuidelines for the Choice of\\nIntraocular Lens The process of calculating the power of\\nintraocular IOL is known as biometry.\\n1. < 2 years old:\\nIt is done by SRK formula:\\n\\uf077 Do biometry and undercorrect by 20%.\\nSRK–I\\nOR\\n\\uf077 Use axial length measurements only. P = A – 2.5 L – 0.9 K\\nA is a constant depending on the surgeon and\\nAxial length IOL diopteric power\\nthe type of IOL.\\n17 mm 28 D\\nL is the axial length and is measured by\\n18 mm 27 D USG-A scan.\\n19 mm 26 D K is the keratometry reading (Average of K1\\n20 mm 24 D and K2) and is measured by Keratometer.\\n21 mm 22 D SRK-II: It is the corrected form of SRK-I,\\ntaking into account any unusual axial length\\n2. Between 2 years to 8 years: Do biometry\\nof the eye (i.e., too long or too short).\\nand undercorrect by 10%.\\nHence preferred choice is SRK-II.\\nThe undercorrection of the IOL power is done\\nto take into account the myopic shift of power COMPLICATIONS OF CATARACT\\nas the child grows.\\nSURGERY\\nThe total diameter of IOL in children should\\nOperative:\\nnot exceed 12 mm.\\n1. SR muscle laceration.\\nIOLS\\n2. Excessive bleeding during conjunctival flap\\npreparation.\\nMaterials:\\n3. Irregular incision.\\n\\uf077 Commonly used material of IOL (Non-\\n4. Injury to cornea, DM-detachment.\\nfoldable) is PMMA (Polymethylmetha-\\ncrylate). 5. Iris injury and iridodialysis.\\n\\uf077 Materials for foldable IOLs are: Hydrogel, 6. Accidental rupture of lens capsule.\\nSilicon and Acrylic.\\n7. Vitreous loss.\\nTypes of Non-Foldable IOLs: 8. Expulsive haemorrhage.\\n\\uf077 AC-IOL-Kelman multiplex. Early Post-Operative:\\n\\uf077 Iris-supported lens–Worst’s or Singh’s iris 1. Hyphema.\\nclaw lenses. 2. Iritis and iris prolapse.12 Review of Ophthalmology\\n3. Striate keratopathy. Types:\\n4. Flat anterior chamber. a. Sunset syndrome: Inferior subluxation\\nof IOL.\\n5. Bacterial endophthalmitis: Painful.\\nb. Sunrise syndrome: Superior subluxa-\\n6. Glaucoma due to retained viscoelastic.\\ntion of IOL.\\nLate Post-Operative:\\nc. Lost lens syndrome: Complete dislo-\\n(All are painless conditions) cation of IOL in the vitreous cavity.\\n1. CME. d. Windshield wiper syndrome: It denotes\\n2. RD. the movement of the superior haptic\\nwith the movement of the head. This\\n3. Epithelial in-growth.\\noccurs due to implantation of a very\\n4. Fibrous down growth. small lens in the ciliary sulcus.\\n5. After cataract. 8. Toxic lens syndrome: It indicates the uveal\\nRD occurs more commonly in aphakes inflammation which occurs due to lens\\ncompared to pseudophakes. The patient will material or the ethylene gas used to sterilise\\npresent as floaters and sudden loss of vision. the lens.\\n\\uf077 Most dreaded complication of\\nIOL-Related\\ncataract surgery is–Endophthal-\\n1. Corneal endothelial damage. mitis. It may be early onset or late\\nonset.\\n2. Uveitis: Mainly with AC-IOLs and iris-claw\\nlenses. Early Onset:\\n3. Secondary glaucoma. 1. Staphylococcal epidermidis is the\\nmost common organism isolated\\n4. Anisocoria (difference in size of pupil):\\nfrom post-surgical endophthalmitis.\\nCommonly when iris claw lenses are\\nimplanted. It can also occur in PC-IOL 2. Other organisms are: Staph aureus,\\nimplantation when there is iris hook by the Pseudomonas and Proteus.\\nhaptic. Late Onset:\\n5. Cystoid macular edema: Its incidence is 1. Propionobacterium acne.\\nspecially more in iris-claw lenses or AC-\\n2. Fungal infection.\\nIOLs when, there is no posterior capsule.\\n\\uf077 Most common late complication of\\nCME after cataract surgery is known as\\ncataract surgery is–After cataract\\n“Irvine–Gass Syndrome”.\\nor PCO.\\n6. UGH syndrome:\\nAfter Cataract\\n\\uf077 Uveitis/glaucoma/hyphema syndrome.\\n\\uf077 Occurs with rigid AC-IOLs. \\uf077 It denotes opacification of posterior capsule\\nafter cataract surgery.\\n7. Malposition of IOLs:\\n\\uf077 It is also known as secondary cataract.\\nIt causes:\\n\\uf077 It may present with various morphological\\na. Astigmatism, if IOL is tilted.\\nforms namely–Elschnig’s pearls,\\nb. Decentration of IOL leads to glare, Soemmering’s rings or just a diffuse\\nhalos, rings of light, uniocular diplopia. opacification.Diseases of Lens 13\\nw Treatment: Homocystinuria: It is an inborn error of\\nmetabolism caused by deficiency of enzyme –\\n(a) Surgical capsulotomy by zeiglers knife.\\nCystathione synthetase leading to increased\\n(b) Laser capsulotomy by Nd-Yag laser\\nlevel of homocysteine in plasma and urine. It\\nwhich is a photodisruptive or cutting\\nis characterized by skeletal deformities\\nlaser.\\nsimilar to Marfan’s syndrome and mental\\nhandicap.\\nDISPLACEMENT OF THE LENS\\nOcular Features:\\nSubluxation is partial dislocation of lens.\\n1. Ectopia lentis in inferonasal direction.\\nCauses:\\n2. Angle anomaly leading to glaucoma or pupil\\n1. Congenital—(a) Simple ectopia lentis block glaucoma due to incarceration of lens\\n(Symmetrical and upwards) (b) Ectopia in the pupil.\\nlentis et pupillae (slit shaped pupil displaced\\n3. Loss of accommodation due to disintegration\\nin opposite direction) (c) Ectopia lentis with\\nof zonules.\\nsystemic anomalies (Marfan’s syndrome,\\nHomocystinuria, Weil-Marchesani syndrome Ehlers-Danlos Syndrome\\nand Ehlers-Danlos syndrome).\\n1. Blue sclera.\\n2. Traumatic—Blunt trauma.\\n2. Ectopia lentis.\\n3. Consecutive or Spontaneous—Hyper-\\nmature cataract, Buphthalmos, High Congenital Anomalies of Lens\\nmyopia and Uveitis.\\nA. Colobomas:\\nMarfan’s Syndrome 1. Mostly occurs inferiorly.\\n2. May be associated with defect in iris\\n1. Megalocornea and Cornea plana.\\nand choroid.\\n2. Angle anomaly leading to glaucoma. {M}\\nB. Congenital Ectopia Lentis.\\n3. Upward/temporal ectopia lentis.\\nC. Lenticonus: It is the conical protrusion of\\n4. Difficulty in pupil dilatation. the lens.\\n5. Lattice degeneration and rhegmatogenous\\nAnterior Lenticonus:\\nretinal detachment.\\nAnterior lenticonus occurs in Alport’s\\nThe most PROMINENT manifestation of\\nSyndrome.\\nMarfan’s syndrome is Megalocornea.\\nAlport’s Syndrome (Familial haemorrhagic\\nThe most COMMON manifestation of\\nnephritis)\\nMarfan’s syndrome is Ectopia lentis.\\nSystemic Features:\\nWeil-Marchesani Syndrome 1. Renal failure.\\n1. Microspherophakia. 2. Hearing loss.\\n2. Pupillary block glaucoma. Ocular Features:\\n3. Ectopia lentis in inferior and forward 1. Posterior polymorphous corneal\\ndirection. dystrophy.14 Review of Ophthalmology\\n2. Juvenile arcus. E. Lentiglobus: It is a generalised hemis-\\npherical deformity of the lens. Posterior\\n3. Pigment dispersion.\\nlentiglobus is seen in Lowe’s syndrome.\\n4. Anterior lenticonus.\\nF. Microphakia: Lens is small in size. It is\\n5. Retinal pigmentary changes.\\nseen in Lowe’s syndrome.\\nPosterior Lenticonus: G. Microspherophakia: Small and spherical lens.\\nIt occurs in Lowe’s Syndrome–i.e., Oculo- Occurs in:\\ncerebrorenal syndrome. 1. Weil-Marchesani syndrome.\\nD. Congenital cataract. 2. Hyperlysinaemia.\\nNEET DRILL\\n1. The equatorial diameter of the lens is 15. Lens nucleus is divided as–embryonic\\n9–10 mm. nucleus–1-3 months of gestation/fetal\\nnucleus–3 months–birth/infantile nucleus-\\n2. The equatorial diameter of the lens at birth\\nbirth–puberty/adult nucleus–in adult life.\\nis 6.5 mm.\\n16. Lens is 66% water and 33% protein.\\n3. Thickness of the lens, i.e., the AP\\ndiameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes–\\nvitamin C, i.e., ascorbic acid, glutathione,\\n4. Radius of curvature of the anterior surface\\nmyoinositol that helps in ascorbic acid\\nis 10 mm.\\ncarrier system and detoxifying enzymes\\n5. Radius of curvature of the posterior\\nlike catalase and superoxide dismutase.\\nsurface is 6 mm.\\n18. Respiratory coefficient of the lens is: 1.\\n6. Refractive index of the lens is 1.39.\\n19. Microwave radiations can also cause\\n7. Refractive power is 16 D–17 D.\\ncataract, proved in animals and claimed\\n8. Accommodative power of the lens at birth: that there is maximum probability for\\n14–16 D at birth, 7–8 D at 25 years and humans also. It occurs in due to rise in\\n1–2 D at 50 years of age. temperature.\\n9. The pigments responsible for the color 20. Length of incision in phacoemulsification\\nchange in the process of development of is 2.75–3.2 mm.\\ncataract are urochrome and melanin. 21. Frequency of the phacoprobe is 40 khz.\\n10. Snowflake or snowstorm cataract is more 22. Most commonly used foldable IOL is\\ncommon in type 1 diabetes. acrylic.\\n11. Cataract in diabetes is due to sorbital 23. MICS, i.e., minimal incision cataract\\naccumulation in the lens and sorbital is surgery: incision is between 1.8 and 2.4 mm.\\nvery hyperosmotic.\\n24. Phaconit: Incision length is 0.9 mm.\\n12. Lens capsule is thinnest at posterior pole\\n25. Father of phaco: Charles D Kelman.\\nwith the thickness of 4 microns.\\n26. Causes of ectopia lentis: Marfan’s syndrome,\\n13. Lens capsule is thickest at equatorial\\nhomocystinuria, Weil-Marchesani, Ehlers-\\nregion and is 23 microns in thickness.\\nDanlos, sulphite oxidase deficiency,\\n14. Suspensory ligament or zonules have a hyperlysenemia, Refsum’s disease and\\ndiameter of 0.35–1 microns. Sturge-Weber syndrome.Diseases of Lens 15\\n27. Anterior lenticonus: Alport’s syndrome, 33. The genes responsible for congenital\\nWaardenburg syndrome. cataract: CRY, i.e., crystallines, Cx, i.e.,\\n28. Posterior lenticonus: Lowe’s syndrome. connexins and MIP, i.e., Major Intrinsic\\n29. Expulsive haemorrhage after cataract Protein.\\nsurgery occurs due to bleeding from the\\n34. The most recent in cataract surgery is\\nposterior ciliary arteries.\\nFemtolaser cataract surgery called LACS,\\n30. The size of opening of posterior capsulo- i.e., laser assisted cataract surgery.\\ntomy done by NdYAG laser ranges from\\n35. Femtolaser is an ultrafast laser, with pulse\\n2–3 mm to 5–6 mm.\\nduration in femtosecond, i.e., 10–15.\\n31. The insoluble proteins raised in a\\ncataractous lens are: HM3, HM4. 36. Minimum chance of after cataract is seen\\n32. In nuclear cataract, it is HM4. with Acrylic Hydrophobic IOLSs.\\n'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_file[chapter_names[0]]['C H A P T E R']['content']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error in Recent Advances. Error is 'content'\n"
     ]
    }
   ],
   "source": [
    "for chapter in chapter_names:\n",
    "    try:\n",
    "        text = json_file[chapter]['C H A P T E R']['content']\n",
    "    except Exception as e:\n",
    "        print(f\"Error in {chapter}. Error is {e}\")\n",
    "    # print(type(text))\n",
    "    with open(f\"data/book/{chapter}\", \"w+\") as f:\n",
    "        f.write(text.replace(\"\\n\", \" \"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from demo_rag_gpt_4 import api_call"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "question = \"Transport of ascorbic acid to lens is done by:\\nA. Myoinositol\\nB. Choline\\nC. Taurine\\nD. Na/K ATPase\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "api_call() got an unexpected keyword argument 'service'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 23\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer \u001b[39m=\u001b[39m api_call(\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m     input_data\u001b[39m=\u001b[39;49mquestion,\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m     service \u001b[39m=\u001b[39;49m \u001b[39m\"\u001b[39;49m\u001b[39mopenai\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m     top_k\u001b[39m=\u001b[39;49m\u001b[39m20\u001b[39;49m,\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m     prompt_file\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X31sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m )\n",
      "\u001b[0;31mTypeError\u001b[0m: api_call() got an unexpected keyword argument 'service'"
     ]
    }
   ],
   "source": [
    "answer = api_call(\n",
    "    input_data=question,\n",
    "    service = \"openai\",\n",
    "    top_k=20,\n",
    "    prompt_file=\"/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Answer for the question is A.\n",
      "\n",
      "Explanation: According to the documents, myoinositol participates in ascorbic acid transport in the lens.\n",
      "\n",
      "Documents used for reference are\n",
      "\n",
      "Document: 1.\n",
      ". Its levels are markedly CATARACT reduced in cataract. It is a precursor of membrane phosphoinositides which are Etiology involved in Na/Ka ATPase function. It also participates in ascorbic acid transport in a. Heredity: Usually dominant. the lens. b. Maternal factors: Lens 1. Malnutrition\n",
      "\n",
      "Document: 2.\n",
      ". 3. Thickness of the lens, i.e., the AP diameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes– vitamin C, i.e., ascorbic acid, glutathione, 4. Radius of curvature of the anterior surface myoinositol that helps in ascorbic acid is 10 mm. carrier system and detoxifying enzymes 5\n"
     ]
    }
   ],
   "source": [
    "print(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "ans = json.loads(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = ans[\"Doc_no\"].replace(\" \",\"\").split(\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = [int(i) for i in l]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "question = \"Transport of ascorbic acid to lens is done by:\\nA. Myoinositol\\nB. Choline\\nC. Taurine\\nD. Na/K ATPase\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Transport of ascorbic acid to lens is done by:\n",
      "A. Myoinositol\n",
      "B. Choline\n",
      "C. Taurine\n",
      "D. Na/K ATPase\n"
     ]
    }
   ],
   "source": [
    "print(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "AuthenticationError",
     "evalue": "Incorrect API key provided: sk-PzTV1***************************************uuhw. You can find your API key at https://platform.openai.com/account/api-keys.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAuthenticationError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 31\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X42sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer \u001b[39m=\u001b[39m api_call(\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#X42sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m     input_data\u001b[39m=\u001b[39;49mquestion,history\u001b[39m=\u001b[39;49m{})\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/demo_rag_gpt_4.py:69\u001b[0m, in \u001b[0;36mapi_call\u001b[0;34m(input_data, history)\u001b[0m\n\u001b[1;32m     66\u001b[0m llm \u001b[39m=\u001b[39m ChatOpenAI(openai_api_key\u001b[39m=\u001b[39mos\u001b[39m.\u001b[39mgetenv(\u001b[39m\"\u001b[39m\u001b[39mOPENAI_API_KEY\u001b[39m\u001b[39m\"\u001b[39m), model\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mgpt-4\u001b[39m\u001b[39m\"\u001b[39m, temperature\u001b[39m=\u001b[39m\u001b[39m0.9\u001b[39m)\n\u001b[1;32m     68\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 69\u001b[0m     output \u001b[39m=\u001b[39m llm(complete_prompt)\u001b[39m.\u001b[39mcontent\n\u001b[1;32m     70\u001b[0m \u001b[39mexcept\u001b[39;00m ApiException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m     71\u001b[0m     \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mAPI Error: \u001b[39m\u001b[39m{\u001b[39;00me\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:600\u001b[0m, in \u001b[0;36mBaseChatModel.__call__\u001b[0;34m(self, messages, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    593\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\n\u001b[1;32m    594\u001b[0m     \u001b[39mself\u001b[39m,\n\u001b[1;32m    595\u001b[0m     messages: List[BaseMessage],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    598\u001b[0m     \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any,\n\u001b[1;32m    599\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m BaseMessage:\n\u001b[0;32m--> 600\u001b[0m     generation \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgenerate(\n\u001b[1;32m    601\u001b[0m         [messages], stop\u001b[39m=\u001b[39;49mstop, callbacks\u001b[39m=\u001b[39;49mcallbacks, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m    602\u001b[0m     )\u001b[39m.\u001b[39mgenerations[\u001b[39m0\u001b[39m][\u001b[39m0\u001b[39m]\n\u001b[1;32m    603\u001b[0m     \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(generation, ChatGeneration):\n\u001b[1;32m    604\u001b[0m         \u001b[39mreturn\u001b[39;00m generation\u001b[39m.\u001b[39mmessage\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:349\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    347\u001b[0m         \u001b[39mif\u001b[39;00m run_managers:\n\u001b[1;32m    348\u001b[0m             run_managers[i]\u001b[39m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 349\u001b[0m         \u001b[39mraise\u001b[39;00m e\n\u001b[1;32m    350\u001b[0m flattened_outputs \u001b[39m=\u001b[39m [\n\u001b[1;32m    351\u001b[0m     LLMResult(generations\u001b[39m=\u001b[39m[res\u001b[39m.\u001b[39mgenerations], llm_output\u001b[39m=\u001b[39mres\u001b[39m.\u001b[39mllm_output)\n\u001b[1;32m    352\u001b[0m     \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m results\n\u001b[1;32m    353\u001b[0m ]\n\u001b[1;32m    354\u001b[0m llm_output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_combine_llm_outputs([res\u001b[39m.\u001b[39mllm_output \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m results])\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:339\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    336\u001b[0m \u001b[39mfor\u001b[39;00m i, m \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(messages):\n\u001b[1;32m    337\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m    338\u001b[0m         results\u001b[39m.\u001b[39mappend(\n\u001b[0;32m--> 339\u001b[0m             \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate_with_cache(\n\u001b[1;32m    340\u001b[0m                 m,\n\u001b[1;32m    341\u001b[0m                 stop\u001b[39m=\u001b[39;49mstop,\n\u001b[1;32m    342\u001b[0m                 run_manager\u001b[39m=\u001b[39;49mrun_managers[i] \u001b[39mif\u001b[39;49;00m run_managers \u001b[39melse\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m    343\u001b[0m                 \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs,\n\u001b[1;32m    344\u001b[0m             )\n\u001b[1;32m    345\u001b[0m         )\n\u001b[1;32m    346\u001b[0m     \u001b[39mexcept\u001b[39;00m \u001b[39mBaseException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m    347\u001b[0m         \u001b[39mif\u001b[39;00m run_managers:\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:492\u001b[0m, in \u001b[0;36mBaseChatModel._generate_with_cache\u001b[0;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    488\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m    489\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m    490\u001b[0m     )\n\u001b[1;32m    491\u001b[0m \u001b[39mif\u001b[39;00m new_arg_supported:\n\u001b[0;32m--> 492\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate(\n\u001b[1;32m    493\u001b[0m         messages, stop\u001b[39m=\u001b[39;49mstop, run_manager\u001b[39m=\u001b[39;49mrun_manager, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m    494\u001b[0m     )\n\u001b[1;32m    495\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m    496\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_generate(messages, stop\u001b[39m=\u001b[39mstop, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:360\u001b[0m, in \u001b[0;36mChatOpenAI._generate\u001b[0;34m(self, messages, stop, run_manager, stream, **kwargs)\u001b[0m\n\u001b[1;32m    358\u001b[0m message_dicts, params \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_create_message_dicts(messages, stop)\n\u001b[1;32m    359\u001b[0m params \u001b[39m=\u001b[39m {\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs}\n\u001b[0;32m--> 360\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcompletion_with_retry(\n\u001b[1;32m    361\u001b[0m     messages\u001b[39m=\u001b[39;49mmessage_dicts, run_manager\u001b[39m=\u001b[39;49mrun_manager, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mparams\n\u001b[1;32m    362\u001b[0m )\n\u001b[1;32m    363\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_create_chat_result(response)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:299\u001b[0m, in \u001b[0;36mChatOpenAI.completion_with_retry\u001b[0;34m(self, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    295\u001b[0m \u001b[39m@retry_decorator\u001b[39m\n\u001b[1;32m    296\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_completion_with_retry\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[1;32m    297\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mclient\u001b[39m.\u001b[39mcreate(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m--> 299\u001b[0m \u001b[39mreturn\u001b[39;00m _completion_with_retry(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:289\u001b[0m, in \u001b[0;36mBaseRetrying.wraps.<locals>.wrapped_f\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m    287\u001b[0m \u001b[39m@functools\u001b[39m\u001b[39m.\u001b[39mwraps(f)\n\u001b[1;32m    288\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mwrapped_f\u001b[39m(\u001b[39m*\u001b[39margs: t\u001b[39m.\u001b[39mAny, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkw: t\u001b[39m.\u001b[39mAny) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m t\u001b[39m.\u001b[39mAny:\n\u001b[0;32m--> 289\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m(f, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkw)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:379\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    377\u001b[0m retry_state \u001b[39m=\u001b[39m RetryCallState(retry_object\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m, fn\u001b[39m=\u001b[39mfn, args\u001b[39m=\u001b[39margs, kwargs\u001b[39m=\u001b[39mkwargs)\n\u001b[1;32m    378\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[0;32m--> 379\u001b[0m     do \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49miter(retry_state\u001b[39m=\u001b[39;49mretry_state)\n\u001b[1;32m    380\u001b[0m     \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(do, DoAttempt):\n\u001b[1;32m    381\u001b[0m         \u001b[39mtry\u001b[39;00m:\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:314\u001b[0m, in \u001b[0;36mBaseRetrying.iter\u001b[0;34m(self, retry_state)\u001b[0m\n\u001b[1;32m    312\u001b[0m is_explicit_retry \u001b[39m=\u001b[39m fut\u001b[39m.\u001b[39mfailed \u001b[39mand\u001b[39;00m \u001b[39misinstance\u001b[39m(fut\u001b[39m.\u001b[39mexception(), TryAgain)\n\u001b[1;32m    313\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (is_explicit_retry \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mretry(retry_state)):\n\u001b[0;32m--> 314\u001b[0m     \u001b[39mreturn\u001b[39;00m fut\u001b[39m.\u001b[39;49mresult()\n\u001b[1;32m    316\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m    317\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter(retry_state)\n",
      "File \u001b[0;32m~/miniconda3/lib/python3.10/concurrent/futures/_base.py:451\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m    449\u001b[0m     \u001b[39mraise\u001b[39;00m CancelledError()\n\u001b[1;32m    450\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_state \u001b[39m==\u001b[39m FINISHED:\n\u001b[0;32m--> 451\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__get_result()\n\u001b[1;32m    453\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_condition\u001b[39m.\u001b[39mwait(timeout)\n\u001b[1;32m    455\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_state \u001b[39min\u001b[39;00m [CANCELLED, CANCELLED_AND_NOTIFIED]:\n",
      "File \u001b[0;32m~/miniconda3/lib/python3.10/concurrent/futures/_base.py:403\u001b[0m, in \u001b[0;36mFuture.__get_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    401\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_exception:\n\u001b[1;32m    402\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 403\u001b[0m         \u001b[39mraise\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_exception\n\u001b[1;32m    404\u001b[0m     \u001b[39mfinally\u001b[39;00m:\n\u001b[1;32m    405\u001b[0m         \u001b[39m# Break a reference cycle with the exception in self._exception\u001b[39;00m\n\u001b[1;32m    406\u001b[0m         \u001b[39mself\u001b[39m \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:382\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    380\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(do, DoAttempt):\n\u001b[1;32m    381\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 382\u001b[0m         result \u001b[39m=\u001b[39m fn(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m    383\u001b[0m     \u001b[39mexcept\u001b[39;00m \u001b[39mBaseException\u001b[39;00m:  \u001b[39m# noqa: B902\u001b[39;00m\n\u001b[1;32m    384\u001b[0m         retry_state\u001b[39m.\u001b[39mset_exception(sys\u001b[39m.\u001b[39mexc_info())  \u001b[39m# type: ignore[arg-type]\u001b[39;00m\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:297\u001b[0m, in \u001b[0;36mChatOpenAI.completion_with_retry.<locals>._completion_with_retry\u001b[0;34m(**kwargs)\u001b[0m\n\u001b[1;32m    295\u001b[0m \u001b[39m@retry_decorator\u001b[39m\n\u001b[1;32m    296\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_completion_with_retry\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[0;32m--> 297\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mclient\u001b[39m.\u001b[39;49mcreate(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_resources/chat_completion.py:25\u001b[0m, in \u001b[0;36mChatCompletion.create\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m     23\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[1;32m     24\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 25\u001b[0m         \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49mcreate(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m     26\u001b[0m     \u001b[39mexcept\u001b[39;00m TryAgain \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m     27\u001b[0m         \u001b[39mif\u001b[39;00m timeout \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m time\u001b[39m.\u001b[39mtime() \u001b[39m>\u001b[39m start \u001b[39m+\u001b[39m timeout:\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py:155\u001b[0m, in \u001b[0;36mEngineAPIResource.create\u001b[0;34m(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)\u001b[0m\n\u001b[1;32m    129\u001b[0m \u001b[39m@classmethod\u001b[39m\n\u001b[1;32m    130\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcreate\u001b[39m(\n\u001b[1;32m    131\u001b[0m     \u001b[39mcls\u001b[39m,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    138\u001b[0m     \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams,\n\u001b[1;32m    139\u001b[0m ):\n\u001b[1;32m    140\u001b[0m     (\n\u001b[1;32m    141\u001b[0m         deployment_id,\n\u001b[1;32m    142\u001b[0m         engine,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    152\u001b[0m         api_key, api_base, api_type, api_version, organization, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams\n\u001b[1;32m    153\u001b[0m     )\n\u001b[0;32m--> 155\u001b[0m     response, _, api_key \u001b[39m=\u001b[39m requestor\u001b[39m.\u001b[39;49mrequest(\n\u001b[1;32m    156\u001b[0m         \u001b[39m\"\u001b[39;49m\u001b[39mpost\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m    157\u001b[0m         url,\n\u001b[1;32m    158\u001b[0m         params\u001b[39m=\u001b[39;49mparams,\n\u001b[1;32m    159\u001b[0m         headers\u001b[39m=\u001b[39;49mheaders,\n\u001b[1;32m    160\u001b[0m         stream\u001b[39m=\u001b[39;49mstream,\n\u001b[1;32m    161\u001b[0m         request_id\u001b[39m=\u001b[39;49mrequest_id,\n\u001b[1;32m    162\u001b[0m         request_timeout\u001b[39m=\u001b[39;49mrequest_timeout,\n\u001b[1;32m    163\u001b[0m     )\n\u001b[1;32m    165\u001b[0m     \u001b[39mif\u001b[39;00m stream:\n\u001b[1;32m    166\u001b[0m         \u001b[39m# must be an iterator\u001b[39;00m\n\u001b[1;32m    167\u001b[0m         \u001b[39massert\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(response, OpenAIResponse)\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:299\u001b[0m, in \u001b[0;36mAPIRequestor.request\u001b[0;34m(self, method, url, params, headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[1;32m    278\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mrequest\u001b[39m(\n\u001b[1;32m    279\u001b[0m     \u001b[39mself\u001b[39m,\n\u001b[1;32m    280\u001b[0m     method,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    287\u001b[0m     request_timeout: Optional[Union[\u001b[39mfloat\u001b[39m, Tuple[\u001b[39mfloat\u001b[39m, \u001b[39mfloat\u001b[39m]]] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m,\n\u001b[1;32m    288\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], \u001b[39mbool\u001b[39m, \u001b[39mstr\u001b[39m]:\n\u001b[1;32m    289\u001b[0m     result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mrequest_raw(\n\u001b[1;32m    290\u001b[0m         method\u001b[39m.\u001b[39mlower(),\n\u001b[1;32m    291\u001b[0m         url,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    297\u001b[0m         request_timeout\u001b[39m=\u001b[39mrequest_timeout,\n\u001b[1;32m    298\u001b[0m     )\n\u001b[0;32m--> 299\u001b[0m     resp, got_stream \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_interpret_response(result, stream)\n\u001b[1;32m    300\u001b[0m     \u001b[39mreturn\u001b[39;00m resp, got_stream, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapi_key\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:710\u001b[0m, in \u001b[0;36mAPIRequestor._interpret_response\u001b[0;34m(self, result, stream)\u001b[0m\n\u001b[1;32m    702\u001b[0m     \u001b[39mreturn\u001b[39;00m (\n\u001b[1;32m    703\u001b[0m         \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_interpret_response_line(\n\u001b[1;32m    704\u001b[0m             line, result\u001b[39m.\u001b[39mstatus_code, result\u001b[39m.\u001b[39mheaders, stream\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m\n\u001b[1;32m    705\u001b[0m         )\n\u001b[1;32m    706\u001b[0m         \u001b[39mfor\u001b[39;00m line \u001b[39min\u001b[39;00m parse_stream(result\u001b[39m.\u001b[39miter_lines())\n\u001b[1;32m    707\u001b[0m     ), \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m    708\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m    709\u001b[0m     \u001b[39mreturn\u001b[39;00m (\n\u001b[0;32m--> 710\u001b[0m         \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_interpret_response_line(\n\u001b[1;32m    711\u001b[0m             result\u001b[39m.\u001b[39;49mcontent\u001b[39m.\u001b[39;49mdecode(\u001b[39m\"\u001b[39;49m\u001b[39mutf-8\u001b[39;49m\u001b[39m\"\u001b[39;49m),\n\u001b[1;32m    712\u001b[0m             result\u001b[39m.\u001b[39;49mstatus_code,\n\u001b[1;32m    713\u001b[0m             result\u001b[39m.\u001b[39;49mheaders,\n\u001b[1;32m    714\u001b[0m             stream\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m    715\u001b[0m         ),\n\u001b[1;32m    716\u001b[0m         \u001b[39mFalse\u001b[39;00m,\n\u001b[1;32m    717\u001b[0m     )\n",
      "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:775\u001b[0m, in \u001b[0;36mAPIRequestor._interpret_response_line\u001b[0;34m(self, rbody, rcode, rheaders, stream)\u001b[0m\n\u001b[1;32m    773\u001b[0m stream_error \u001b[39m=\u001b[39m stream \u001b[39mand\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39merror\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m resp\u001b[39m.\u001b[39mdata\n\u001b[1;32m    774\u001b[0m \u001b[39mif\u001b[39;00m stream_error \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39m200\u001b[39m \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m rcode \u001b[39m<\u001b[39m \u001b[39m300\u001b[39m:\n\u001b[0;32m--> 775\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhandle_error_response(\n\u001b[1;32m    776\u001b[0m         rbody, rcode, resp\u001b[39m.\u001b[39mdata, rheaders, stream_error\u001b[39m=\u001b[39mstream_error\n\u001b[1;32m    777\u001b[0m     )\n\u001b[1;32m    778\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n",
      "\u001b[0;31mAuthenticationError\u001b[0m: Incorrect API key provided: sk-PzTV1***************************************uuhw. You can find your API key at https://platform.openai.com/account/api-keys."
     ]
    }
   ],
   "source": [
    "answer = api_call(\n",
    "    input_data=question,history={})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Answer for the question is A.\n",
      "\n",
      "Explanation: The transport of ascorbic acid to the lens is done by myoinositol. Myoinositol participates in ascorbic acid transport in the lens and is actively transported into the lens by a sodium-dependent carrier-mediated mechanism.\n",
      "\n",
      "Documents used for reference are\n",
      "\n",
      "Document: 1.\n",
      ". Its levels are markedly CATARACT reduced in cataract. It is a precursor of membrane phosphoinositides which are Etiology involved in Na/Ka ATPase function. It also participates in ascorbic acid transport in a. Heredity: Usually dominant. the lens. b. Maternal factors: Lens 1. Malnutrition\n",
      "\n",
      "Document: 2.\n",
      ". 3. Thickness of the lens, i.e., the AP diameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes– vitamin C, i.e., ascorbic acid, glutathione, 4. Radius of curvature of the anterior surface myoinositol that helps in ascorbic acid is 10 mm. carrier system and detoxifying enzymes 5\n",
      "\n",
      "Document: 4.\n",
      ". Anterior and Posterior. Its levels are reduced in patients of cataract. Most common cause of acquired cataract is senile cataract.  Myoinositol is actively transported into the lens by sodium dependent carrier mediated CONGENITAL AND DEVELOPMENTAL mechanism\n"
     ]
    }
   ],
   "source": [
    "print(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_rag = np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/data/answer_pred_list_rag.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_rag = [i.lower() for i in pred_rag]\n",
    "# pred_rag = [None for i in pred_rag if len(i) == 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "binary_value = []\n",
    "for i in range(len(pred_rag[:94])):\n",
    "    true_list = "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a',\n",
       " 'a',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " 'd',\n",
       " '',\n",
       " 'a',\n",
       " 'c',\n",
       " '',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " 'b',\n",
       " 'c',\n",
       " 'd',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " 'c',\n",
       " 'b',\n",
       " 'd',\n",
       " '',\n",
       " 'b',\n",
       " 'a',\n",
       " 'b',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a, b',\n",
       " 'a',\n",
       " '',\n",
       " 'e',\n",
       " 'b',\n",
       " 'd',\n",
       " 'a, b, c, d, e',\n",
       " 'b',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " '',\n",
       " 'b',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a, d',\n",
       " 'd',\n",
       " 'd',\n",
       " 'a',\n",
       " 'd',\n",
       " 'c',\n",
       " '',\n",
       " 'd',\n",
       " '',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " 'b',\n",
       " '',\n",
       " 'c',\n",
       " 'd',\n",
       " 'd',\n",
       " 'a',\n",
       " 'd',\n",
       " 'a',\n",
       " 'b',\n",
       " 'd',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " 'a',\n",
       " 'b',\n",
       " 'd',\n",
       " 'd',\n",
       " '',\n",
       " 'b',\n",
       " 'd',\n",
       " '',\n",
       " 'c',\n",
       " 'c',\n",
       " 'b',\n",
       " 'b',\n",
       " '',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " '',\n",
       " 'a',\n",
       " '',\n",
       " 'b',\n",
       " 'c',\n",
       " 'a',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " 'd',\n",
       " 'b',\n",
       " '']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_rag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import classification_report\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "true_csv = pd.read_csv(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/data/chapter_1_mcq_true.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "true_ans = true_csv[\"answer\"].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "binary_value = []\n",
    "binary_true = []\n",
    "for i in range(len(pred_rag[:94])):\n",
    "    true_list = true_ans[i].replace(\" \", \"\").split(\",\")\n",
    "    if pred_rag[i] in true_list:\n",
    "        binary_value.append(1)\n",
    "    else:\n",
    "        binary_value.append(0)\n",
    "    \n",
    "    binary_true.append(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('a', 'a')\n",
      "('a', 'a')\n",
      "('a', 'b')\n",
      "('', 'b')\n",
      "('', 'a')\n",
      "('d', 'c')\n",
      "('', 'a')\n",
      "('a', 'b')\n",
      "('c', 'b')\n",
      "('', 'c')\n",
      "('c', 'b')\n",
      "('b', 'a')\n",
      "('a', 'a')\n",
      "('', 'c')\n",
      "('', 'c')\n",
      "('c', 'b')\n",
      "('b', 'a')\n",
      "('a', 'a')\n",
      "('b', 'c')\n",
      "('c', 'a')\n",
      "('d', 'b')\n",
      "('c', 'b')\n",
      "('b', 'c')\n",
      "('a', 'c')\n",
      "('c', 'd')\n",
      "('b', 'd')\n",
      "('d', 'a')\n",
      "('', 'b')\n",
      "('b', 'c')\n",
      "('a', 'b')\n",
      "('b', 'b')\n",
      "('a', 'a')\n",
      "('a', 'b')\n",
      "('a, b', 'a')\n",
      "('a', 'b')\n",
      "('', 'a')\n",
      "('e', 'a')\n",
      "('b', 'c')\n",
      "('d', 'c')\n",
      "('a, b, c, d, e', 'a')\n",
      "('b', 'a')\n",
      "('', 'a')\n",
      "('c', 'a')\n",
      "('', 'a')\n",
      "('', 'd')\n",
      "('', 'd')\n",
      "('b', 'b')\n",
      "('a', 'c')\n",
      "('a', 'd')\n",
      "('a', 'd')\n",
      "('a', 'a')\n",
      "('a', 'b')\n",
      "('a, d', 'c')\n",
      "('d', 'a')\n",
      "('d', 'b')\n",
      "('a', 'b')\n",
      "('d', 'a')\n",
      "('c', 'd')\n",
      "('', 'd')\n",
      "('d', 'a')\n",
      "('', 'd')\n",
      "('', 'a')\n",
      "('c', 'b')\n",
      "('', 'b')\n",
      "('b', 'c')\n",
      "('', 'b')\n",
      "('c', 'a')\n",
      "('d', 'b')\n",
      "('d', 'd')\n",
      "('a', 'b')\n",
      "('d', 'b')\n",
      "('a', 'b')\n",
      "('b', 'd')\n",
      "('d', 'a')\n",
      "('c', 'a')\n",
      "('', 'c')\n",
      "('', 'd')\n",
      "('a', 'b')\n",
      "('b', 'a')\n",
      "('d', 'a')\n",
      "('d', 'a')\n",
      "('', 'b')\n",
      "('b', 'a')\n",
      "('d', 'c')\n",
      "('', 'b')\n",
      "('c', 'c')\n",
      "('c', 'd')\n",
      "('b', 'd')\n",
      "('b', 'c')\n",
      "('', 'a')\n",
      "('a', 'b')\n",
      "('', 'd')\n",
      "('', 'b')\n",
      "('', 'a')\n"
     ]
    }
   ],
   "source": [
    "for i in zip(pred_rag[:94], true_ans):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a',\n",
       " 'a',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " 'd',\n",
       " '',\n",
       " 'a',\n",
       " 'c',\n",
       " '',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " 'b',\n",
       " 'c',\n",
       " 'd',\n",
       " 'c',\n",
       " 'b',\n",
       " 'a',\n",
       " 'c',\n",
       " 'b',\n",
       " 'd',\n",
       " '',\n",
       " 'b',\n",
       " 'a',\n",
       " 'b',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a, b',\n",
       " 'a',\n",
       " '',\n",
       " 'e',\n",
       " 'b',\n",
       " 'd',\n",
       " 'a, b, c, d, e',\n",
       " 'b',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " '',\n",
       " 'b',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a',\n",
       " 'a, d',\n",
       " 'd',\n",
       " 'd',\n",
       " 'a',\n",
       " 'd',\n",
       " 'c',\n",
       " '',\n",
       " 'd',\n",
       " '',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " 'b',\n",
       " '',\n",
       " 'c',\n",
       " 'd',\n",
       " 'd',\n",
       " 'a',\n",
       " 'd',\n",
       " 'a',\n",
       " 'b',\n",
       " 'd',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " 'a',\n",
       " 'b',\n",
       " 'd',\n",
       " 'd',\n",
       " '',\n",
       " 'b',\n",
       " 'd',\n",
       " '',\n",
       " 'c',\n",
       " 'c',\n",
       " 'b',\n",
       " 'b',\n",
       " '',\n",
       " 'a',\n",
       " '',\n",
       " '',\n",
       " '',\n",
       " 'a',\n",
       " '',\n",
       " 'b',\n",
       " 'c',\n",
       " 'a',\n",
       " '',\n",
       " 'c',\n",
       " '',\n",
       " '',\n",
       " 'd',\n",
       " 'b',\n",
       " '']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_rag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.00      0.00      0.00         0\n",
      "           1       1.00      0.11      0.19        94\n",
      "\n",
      "    accuracy                           0.11        94\n",
      "   macro avg       0.50      0.05      0.10        94\n",
      "weighted avg       1.00      0.11      0.19        94\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n"
     ]
    }
   ],
   "source": [
    "print(classification_report(binary_true, binary_value))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from tqdm.autonotebook import tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading model\n",
      "\n",
      "\n",
      "Models downloaded\n",
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\n",
      "Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023/11/02 10:43:28 [W] [service.go:132] login to server failed: EOF\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": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from demo_rag_gpt_4 import api_call\n",
    "\n",
    "import gradio as gr\n",
    "\n",
    "# answer = api_call(\n",
    "#     input_data=question,\n",
    "#     service = \"openai\",\n",
    "#     top_k=20,\n",
    "#     prompt_file=\"/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\",\n",
    "# )\n",
    "\n",
    "gr.ChatInterface(api_call).launch(share=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    ">>> from datasets import load_dataset\n",
    ">>> dataset = load_dataset('squad', split='train')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject list at 0x109c43fb0> JSON: {\n",
       "  \"object\": \"list\",\n",
       "  \"data\": [\n",
       "    {\n",
       "      \"id\": \"text-search-babbage-doc-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-16k-0613\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1685474247,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"curie-search-query\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-16k\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1683758102,\n",
       "      \"owned_by\": \"openai-internal\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-babbage-query-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649358449,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-search-query\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-babbage-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364043,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"whisper-1\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1677532384,\n",
       "      \"owned_by\": \"openai-internal\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-similarity-davinci-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci-similarity\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"code-davinci-edit-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649880484,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"curie-similarity\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172510,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-search-document\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172510,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"curie-instruct-beta\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364042,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-ada-doc-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci-instruct-beta\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364042,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-4\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1687882411,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-similarity-babbage-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-davinci-doc-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-similarity\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-embedding-ada-002\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1671217299,\n",
       "      \"owned_by\": \"openai-internal\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci-search-query\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-similarity-curie-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-davinci-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364042,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-davinci-query-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada-search-document\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada-code-search-code\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-002\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1692634615,\n",
       "      \"owned_by\": \"system\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci-002\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1692634301,\n",
       "      \"owned_by\": \"system\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci-search-document\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"curie-search-document\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172508,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-code-search-code\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-ada-query-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"code-search-ada-text-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"babbage-code-search-text\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"code-search-babbage-code-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada-search-query\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada-code-search-text\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172510,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-curie-query-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-davinci-002\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649880484,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-davinci-edit-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649809179,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"code-search-babbage-text-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1677610602,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-instruct-0914\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1694122472,\n",
       "      \"owned_by\": \"system\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649357491,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-ada-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364042,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"ada-similarity\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"code-search-ada-code-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172507,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-similarity-ada-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172505,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-0301\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1677649963,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-instruct\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1692901427,\n",
       "      \"owned_by\": \"system\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-search-curie-doc-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1651172509,\n",
       "      \"owned_by\": \"openai-dev\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-davinci-003\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1669599635,\n",
       "      \"owned_by\": \"openai-internal\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-4-0613\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1686588896,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"text-curie-001\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649364043,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"curie\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649359874,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-4-0314\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1687882410,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"davinci\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1649359874,\n",
       "      \"owned_by\": \"openai\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"dall-e-2\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1698798177,\n",
       "      \"owned_by\": \"system\"\n",
       "    },\n",
       "    {\n",
       "      \"id\": \"gpt-3.5-turbo-0613\",\n",
       "      \"object\": \"model\",\n",
       "      \"created\": 1686587434,\n",
       "      \"owned_by\": \"openai\"\n",
       "    }\n",
       "  ]\n",
       "}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import openai\n",
    "openai.organization = \"org-0UQMhO1JHKnODDAGm43isRSP\"\n",
    "openai.api_key = \"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\"\n",
    "openai.Model.list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "d = openai.Model.list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gpt-4\n"
     ]
    }
   ],
   "source": [
    "for i in d['data']:\n",
    "    if i['id'] == 'gpt-4':\n",
    "        print(i['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GB6Qr5nSr8uI70QxDJ2PT3BlbkFJTIfe5DGwsNfiiOHo3hyZ'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.environ[\"OPENAI_API_KEY\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from tqdm.autonotebook import tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading model\n",
      "\n",
      "\n",
      "Models downloaded\n"
     ]
    }
   ],
   "source": [
    "from demo_rag_gpt_4 import api_call\n",
    "from tqdm import tqdm\n",
    "import numpy as np\n",
    "from langchain.prompts import PromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate\n",
    "from langchain.chat_models import ChatOpenAI\n",
    "from langchain.schema.messages import SystemMessage\n",
    "import os\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt_file = \"prompts/version_1_wihtout_rag.txt\"\n",
    "prompt = open(prompt_file).read()\n",
    "\n",
    "    # Create Chat Template\n",
    "\n",
    "chat_template = ChatPromptTemplate.from_messages(\n",
    "[\n",
    "    SystemMessage(\n",
    "        content=prompt,     \n",
    "    ),\n",
    "    HumanMessagePromptTemplate.from_template(\"Answer the following question.\\n{question}\"),\n",
    "    # HumanMessagePromptTemplate.from_template(\"Answer this question. Give only the option followed by a brief explanation as output\\\\n{text}\"),\n",
    "]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = ChatOpenAI(model=\"gpt-4\", temperature=0.9, openai_organization=os.getenv(\"ORGANIZATION_KEY\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "question_list = np.load(\"data/medmcqa/question_list.npy\")\n",
    "true = np.load(\"data/medmcqa/answer_list.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 57%|█████▋    | 127/221 [19:04<17:53, 11.42s/it]Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600).\n",
      "100%|██████████| 221/221 [49:37<00:00, 13.47s/it]   \n"
     ]
    }
   ],
   "source": [
    "pred_list_without_rag = []\n",
    "doc_list_without_rag = []\n",
    "exception_list_without_rag = []\n",
    "for question in tqdm(question_list[279:500]):\n",
    "    complete_prompt = chat_template.format_messages(question=question)\n",
    "    answer = llm(complete_prompt).content\n",
    "    try:\n",
    "        answer = json.loads(answer)\n",
    "        option = answer[\"option\"]\n",
    "        # doc = answer[\"doc_no\"]\n",
    "        pred_list_without_rag.append(option)\n",
    "        # doc_list_without_rag.append([int(i) for i in doc.split(',')])\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        exception_list_without_rag.append([e, answer])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"option\": \"C\", \"explanation\": \"Central serous retinopathy generally does not cause sudden loss of vision. It typically presents with mild to moderate vision loss or distortion that develops slowly over time. On the other hand, Angle closure glaucoma, endophthalmitis, and corneal ulceration can all lead to a rapid onset of visual loss.\"}'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_after_279 = np.array(pred_list_without_rag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/arr_after_279.npy\", arr_after_279)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_279 = np.array(pred_list_without_rag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/arr_279.npy\", arr_279)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# arr_1 = np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/pred.npy\")\n",
    "# arr_2= np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/w_rag/medmcqa/array_131.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_list = np.load(\"prediction/wo_rag/medmcqa/pred.npy\")\n",
    "true_list = np.load(\"data/medmcqa/answer_list.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_list = {\"a\":0, \"b\": 1, \"c\": 2, \"d\": 3}\n",
    "option_list = [\"a\", \"b\", \"c\", \"d\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_pross = []\n",
    "for i in range(len(pred_list)):\n",
    "    pred = pred_list[i]\n",
    "    actual = true_list[i]\n",
    "    if pred.lower() in option_list:\n",
    "        p = map_list[pred.lower()]\n",
    "        if p == actual:\n",
    "            pred_pross.append(True)\n",
    "        else:\n",
    "            pred_pross.append(False)\n",
    "    else:\n",
    "        pred_pross.append(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True,\n",
       " False,\n",
       " False,\n",
       " False,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " True,\n",
       " False,\n",
       " True]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_pross"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "actual"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "actual = [1 for pred in pred_pross]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import classification_report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n"
     ]
    }
   ],
   "source": [
    "report = classification_report(actual, pred_pross)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.00      0.00      0.00         0\n",
      "           1       1.00      0.76      0.86       500\n",
      "\n",
      "    accuracy                           0.76       500\n",
      "   macro avg       0.50      0.38      0.43       500\n",
      "weighted avg       1.00      0.76      0.86       500\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(report)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['A', 'C', 'C', 'A', 'B', 'A', 'B', 'D', 'A', 'C', 'A', 'A', 'C',\n",
       "       'C', 'B', 'C', 'D', 'B', 'D', 'A', 'C', 'B', 'A', 'A', 'A', 'A',\n",
       "       'A', 'C', 'C', 'D', 'C', 'C', 'D', 'C', 'C', 'B', 'D', 'A', 'B',\n",
       "       'D', 'D', 'B', 'C', 'B', 'C', 'D', 'A', 'B', 'A', 'C', 'C', 'B',\n",
       "       'A', 'D', 'A', 'B', 'B', 'B', 'D', 'C', 'C', 'B', 'A', 'B', 'C',\n",
       "       'D', 'A', 'D', 'C', 'A', 'B', 'B', 'D', 'D', 'A', 'D', 'D', 'D',\n",
       "       'B', 'A', 'D', 'C', 'B', 'D', 'C', 'A', 'A', 'D', 'D', 'A', 'A',\n",
       "       'C', 'A', 'B', 'A', 'B', 'D', 'A', 'C', 'C', 'B', 'A', 'C', 'B',\n",
       "       'D', 'B', 'A', 'C', 'B', 'C', 'C', 'C', 'B', 'A', 'D', 'C', 'B',\n",
       "       'D', 'A', 'D', 'C', 'A', 'A', 'C', 'A', 'D', 'D', 'D', 'B', 'D',\n",
       "       'D', 'A', 'A', 'D', 'C', 'C', 'B', 'D', 'D', 'A', 'A', 'A', 'C',\n",
       "       'B', 'B', 'B', 'C', 'D', 'B', 'D', 'B', 'B', 'A', 'D', 'B', 'A',\n",
       "       'B', 'D', 'B', 'C', 'B', 'C', 'A', 'C', 'B', 'A', 'D', 'A', 'C',\n",
       "       'C', 'C', 'A', 'C', '', 'A', 'A', 'C', 'A', 'D', 'B', 'A', 'C',\n",
       "       'C', 'C', 'C', 'C', 'D', 'C', 'D', 'B', 'C', 'C', 'C', 'D', 'A',\n",
       "       'D', 'C', 'A', 'B', 'D', 'B', 'B', 'A', 'D', 'A', 'D', 'D', 'D',\n",
       "       'C', 'B', 'D', 'A', 'B', 'B', 'A', 'D', 'A', 'B', '', 'B', 'B',\n",
       "       'C', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'A', 'C', 'A',\n",
       "       'A', 'D', 'B', 'D', 'B', 'B', 'C', 'D', 'A', 'A', 'D', 'B', 'C',\n",
       "       'A', 'D', 'B', 'A', 'D', 'A', 'A', 'D', 'A', 'C', 'A', 'B', 'A',\n",
       "       'B', 'B', 'D', 'D', 'C', 'B', 'A', 'C', 'D', 'B', 'B', 'A', 'B',\n",
       "       'A', 'B', 'D', 'B', 'D', 'A', 'A', 'Missing', 'B', 'B', 'A', 'D',\n",
       "       'D', 'B', 'A', 'B', 'B', 'A', 'D', 'C', 'B', 'A', 'A', 'D', 'B',\n",
       "       'B', 'B', 'D', 'B', 'B', 'B', 'B', 'C', 'B', 'C', 'A', 'C', 'C',\n",
       "       'D', 'A', 'D', 'B', 'D', 'C', 'C', 'A', 'D', 'D', 'D', 'C', 'A',\n",
       "       'A', 'B', 'A', 'A', 'C', 'C', 'A', 'C', 'B', 'D', 'C', 'A', 'A',\n",
       "       'A, B', 'C', 'A', 'B', 'C', 'A', 'A', 'A', 'D', 'B', 'D', 'C', 'B',\n",
       "       'A', 'A', 'A', 'B', 'A', 'D', 'A', 'None of the above', 'B', 'D',\n",
       "       'B', 'A', 'A', 'A', 'B', 'C', 'A', 'D', 'B', 'B', 'B', 'A', 'B',\n",
       "       'B', 'B', 'C', 'A', 'B', 'D', 'A', 'D', 'A', 'D', 'C', 'B', 'C',\n",
       "       'B', 'D', 'B', 'B', 'D', 'D', 'D', 'B', 'D', 'A', 'D', 'C', 'A',\n",
       "       'D', 'B', 'D', 'A', 'A', 'A', 'D', 'C', 'B', 'A', 'C', 'B', 'C',\n",
       "       'D', 'A', 'A', 'D', 'D', 'A', 'C', 'C', 'B', 'B', 'D', 'C', 'C',\n",
       "       'A', 'A', 'A', 'B', 'A', 'C', 'B', 'D', 'D', 'A', 'C', 'D', 'A',\n",
       "       'B', 'C', 'D', 'C', 'A', 'C', 'D', 'C', 'B', 'C', 'A', 'A', 'D',\n",
       "       'C', 'C', 'A', 'C', 'B', 'A', 'A', 'C', 'B', 'C', 'B', 'D', 'D',\n",
       "       'D', 'A', 'B', 'B', 'D', 'D', 'D', 'A', 'B', 'A', 'B', 'D', 'B',\n",
       "       'A', 'B', 'B', 'C', 'B', 'B', 'C', 'A', 'A', 'D', 'B', 'C', 'B',\n",
       "       'C', 'A', 'A', 'C', 'B', 'A', 'A', 'A', 'C', 'B'], dtype='<U17')"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## RAG VERSION 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from tqdm.autonotebook import tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading model\n",
      "\n",
      "\n",
      "Models downloaded\n"
     ]
    }
   ],
   "source": [
    "from demo_rag_gpt_4 import api_call\n",
    "from tqdm import tqdm\n",
    "import numpy as np\n",
    "# from langchain.prompts import PromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate\n",
    "# from langchain.chat_models import ChatOpenAI\n",
    "# from langchain.schema.messag\n",
    "# es import SystemMessage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "question_list = np.load(\"data/medmcqa/question_list.npy\")\n",
    "true = np.load(\"data/medmcqa/answer_list.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/500 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 48%|████▊     | 239/500 [20:08<21:43,  5.00s/it]Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600).\n",
      " 54%|█████▍    | 271/500 [22:30<16:43,  4.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(429)\n",
      "Reason: Too Many Requests\n",
      "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:23:33 GMT', 'x-envoy-upstream-service-time': '3', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n",
      "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 67%|██████▋   | 334/500 [26:46<10:24,  3.76s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(429)\n",
      "Reason: Too Many Requests\n",
      "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:27:50 GMT', 'x-envoy-upstream-service-time': '0', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n",
      "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 96%|█████████▌| 481/500 [37:20<01:12,  3.82s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(429)\n",
      "Reason: Too Many Requests\n",
      "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:38:24 GMT', 'x-envoy-upstream-service-time': '1', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n",
      "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 500/500 [38:41<00:00,  4.64s/it]\n"
     ]
    }
   ],
   "source": [
    "import concurrent.futures\n",
    "from tqdm import tqdm\n",
    "import time  # Import the time module\n",
    "\n",
    "pred_list = []\n",
    "exception_list = []\n",
    "doc_list = []\n",
    "\n",
    "def process_question(question):\n",
    "    answer = None  # Initialize answer before the try block\n",
    "    try:\n",
    "        answer = api_call(question, history={})\n",
    "        option = answer[\"option\"]\n",
    "        doc = answer[\"doc_no\"]\n",
    "        pred_list.append(option)\n",
    "        doc_list.append([i for i in doc.split(',')])\n",
    "        pbar.update(1)  # Update the tqdm progress bar\n",
    "        time.sleep(5)  # Add a 1-second delay between API calls (adjust as needed)\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        exception_list.append([e, answer])\n",
    "        pred_list.append(\"\")\n",
    "        pbar.update(1)  # Update the tqdm progress bar\n",
    "        time.sleep(5)  # Add a 1-second delay even when an exception occurs\n",
    "\n",
    "question_list = question_list[:500]\n",
    "\n",
    "# Specify the number of threads by setting max_workers\n",
    "num_threads = 4  # You can adjust this number as needed\n",
    "with tqdm(total=len(question_list)) as pbar:\n",
    "    with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:\n",
    "        list(executor.map(process_question, question_list))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = np.array(pred_list)\n",
    "np.save(\"prediction/w_rag/medmcqa/pred_error.npy\", arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['1'],\n",
       " [''],\n",
       " ['1', '4'],\n",
       " ['2'],\n",
       " [''],\n",
       " ['1', '2'],\n",
       " ['1', '4'],\n",
       " ['1'],\n",
       " ['No document used'],\n",
       " ['Document 3'],\n",
       " ['1', '2'],\n",
       " ['4'],\n",
       " [''],\n",
       " ['No document used'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['4'],\n",
       " ['3'],\n",
       " ['Not mentioned in the provided documents'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1', '4'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['4'],\n",
       " ['2'],\n",
       " ['5'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['1', '2', '4'],\n",
       " ['Not available in documents'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['None'],\n",
       " ['1', '4'],\n",
       " ['3'],\n",
       " ['1', '2'],\n",
       " ['No document used'],\n",
       " ['None'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['1', '3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1', '2', '4'],\n",
       " ['Not available in provided documents'],\n",
       " ['2'],\n",
       " ['1', ' 2', ' 3'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['5'],\n",
       " ['Not mentioned in provided documents'],\n",
       " ['1', '3'],\n",
       " ['1'],\n",
       " ['4', '2'],\n",
       " ['No Document Used'],\n",
       " ['2'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['3'],\n",
       " ['Not applicable'],\n",
       " ['1', ' 4'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['5'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " ['1', '5'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['3'],\n",
       " ['2'],\n",
       " ['1', '2', '4', '5'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['1', '3', '4'],\n",
       " ['3'],\n",
       " ['N/A'],\n",
       " ['1', '4', '5'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1', '2'],\n",
       " [''],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1', '3', '5'],\n",
       " ['3', '5'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['Not used'],\n",
       " ['2'],\n",
       " ['5'],\n",
       " ['4'],\n",
       " ['5'],\n",
       " ['1'],\n",
       " ['1', '2', '3', '4'],\n",
       " ['1'],\n",
       " ['Document 1', ' Document 2', ' Document 4', ' Document 5'],\n",
       " ['4'],\n",
       " ['2'],\n",
       " [''],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['None'],\n",
       " ['3', '4'],\n",
       " ['1'],\n",
       " ['5'],\n",
       " ['2'],\n",
       " ['Not mentioned in any document'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1', '3'],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1', '3'],\n",
       " ['5'],\n",
       " ['Not applicable'],\n",
       " ['2'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['1', '4'],\n",
       " ['None'],\n",
       " ['4'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['Based on medical knowledge'],\n",
       " ['1', '2', '3', '4'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['Document: 1', ' Document: 2'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1', '2', '5'],\n",
       " ['Not explicitly stated in the provided documents'],\n",
       " ['3'],\n",
       " ['1'],\n",
       " [''],\n",
       " [''],\n",
       " ['1', ' 4'],\n",
       " ['2'],\n",
       " [''],\n",
       " ['1', '3', '4', '5'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['1', ' 2'],\n",
       " ['No document used.'],\n",
       " ['1', '3'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['None'],\n",
       " ['4', '5'],\n",
       " ['1', ' 2', ' 3'],\n",
       " ['1', '4'],\n",
       " ['4'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " [''],\n",
       " ['No document used'],\n",
       " ['5'],\n",
       " ['1', '5'],\n",
       " ['4'],\n",
       " ['1', '2', '5'],\n",
       " ['1', '2', '3'],\n",
       " [''],\n",
       " ['0'],\n",
       " ['2'],\n",
       " ['5'],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['1', '3'],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['1', '4', '5'],\n",
       " ['None'],\n",
       " ['Not mentioned in provided documents'],\n",
       " ['1'],\n",
       " ['2', '4'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['N/A'],\n",
       " ['4'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['Not Mentioned'],\n",
       " ['1', '2', '3', '4'],\n",
       " ['5'],\n",
       " ['Not mentioned in any document'],\n",
       " [''],\n",
       " [''],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['None used'],\n",
       " ['2', '3', '5'],\n",
       " ['Not mentioned'],\n",
       " ['1', '2', '3'],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['4', '5'],\n",
       " ['1', '3'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1', '5'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['None'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['5'],\n",
       " ['3', ' 2'],\n",
       " ['3'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['4'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['2', '3'],\n",
       " ['3', ' 4'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['2'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1', '3', '4'],\n",
       " ['1', '2'],\n",
       " ['5'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " ['No Document used. This information comes from general ophthalmological knowledge.'],\n",
       " ['1'],\n",
       " [''],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['1', '4'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['Not mentioned in the provided documents but answered based on general knowledge'],\n",
       " ['1'],\n",
       " ['2', '3'],\n",
       " ['2'],\n",
       " ['2', '3'],\n",
       " ['1', '2'],\n",
       " ['5'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['2', '4'],\n",
       " ['1', '4'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['4'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['Not mentioned in the provided documents'],\n",
       " ['1', '3'],\n",
       " ['4'],\n",
       " ['None'],\n",
       " ['None'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['4'],\n",
       " ['5'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['5'],\n",
       " ['1', ' 2', ' 4'],\n",
       " ['1', '2', ' and 4'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['4'],\n",
       " ['1'],\n",
       " ['4'],\n",
       " ['2'],\n",
       " ['2', '5'],\n",
       " ['1'],\n",
       " ['None'],\n",
       " ['1'],\n",
       " ['4'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1', '5'],\n",
       " ['1', '3'],\n",
       " ['2'],\n",
       " ['1', '2', '3', '4'],\n",
       " ['1'],\n",
       " ['1', '4'],\n",
       " ['1'],\n",
       " ['1', '3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1', '2'],\n",
       " ['1', '3'],\n",
       " ['4'],\n",
       " ['1', '3'],\n",
       " ['5'],\n",
       " ['none'],\n",
       " ['1', '2'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['Not explicitly mentioned in the documents'],\n",
       " ['1', '2'],\n",
       " [''],\n",
       " ['Not found in documents', ' knowledge based answer'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1', '3'],\n",
       " ['No document used'],\n",
       " ['1', '2', '4'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " [''],\n",
       " ['1'],\n",
       " ['Not applicable'],\n",
       " [''],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " ['3'],\n",
       " ['Not mentioned in the provided documents'],\n",
       " ['1', '3'],\n",
       " ['Not mentioned in provided documents'],\n",
       " ['1', ' 3', ' 5'],\n",
       " ['3', '5'],\n",
       " ['1', '2', '3'],\n",
       " ['Not mentioned in the documents'],\n",
       " ['Not provided in the given documents'],\n",
       " ['Not applicable'],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['1', ' 4'],\n",
       " ['1', '4'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['5'],\n",
       " [''],\n",
       " ['No document used'],\n",
       " ['1'],\n",
       " ['1', '5'],\n",
       " ['1', '2', '4'],\n",
       " ['3', '4'],\n",
       " ['2'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['Not applicable'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1', '5'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['4'],\n",
       " ['3'],\n",
       " ['1', '2', '3'],\n",
       " ['1'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1'],\n",
       " ['5'],\n",
       " ['1'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['1', '3'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['1', '2', '3', '5'],\n",
       " ['1'],\n",
       " ['3'],\n",
       " ['4'],\n",
       " [''],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['3'],\n",
       " ['1', '4'],\n",
       " [''],\n",
       " ['1', ' 2', ' 3'],\n",
       " ['1', '2', '3'],\n",
       " ['1', '2'],\n",
       " ['1', '2'],\n",
       " [''],\n",
       " ['3'],\n",
       " ['1'],\n",
       " ['None'],\n",
       " ['1', '3'],\n",
       " ['1', '2'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['No document used'],\n",
       " ['4'],\n",
       " ['4'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['4'],\n",
       " ['2', '3'],\n",
       " ['1', '3'],\n",
       " [''],\n",
       " ['1'],\n",
       " ['None'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['1'],\n",
       " ['2'],\n",
       " ['4'],\n",
       " ['4']]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "doc_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc_str = [str(i) for i in doc_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = np.array(pred_list)\n",
    "np.save(\"prediction/w_rag/medmcqa/pred.npy\", pred_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "exp_list = []\n",
    "for i in range(len(pred_list)):\n",
    "    if len(arr[i]) == 0:\n",
    "        exp_list.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 333, 480]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exp_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "exp_ques = [question_list[i] for i in exp_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/500 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  1%|          | 3/500 [00:17<47:07,  5.69s/it]  \n"
     ]
    }
   ],
   "source": [
    "pred_list_2 = []\n",
    "exception_list_2 = []\n",
    "doc_list_2 = []\n",
    "\n",
    "def process_question(question):\n",
    "    answer = None  # Initialize answer before the try block\n",
    "    try:\n",
    "        answer = api_call(question, history={})\n",
    "        option = answer[\"option\"]\n",
    "        doc = answer[\"doc_no\"]\n",
    "        pred_list_2.append(option)\n",
    "        doc_list_2.append([i for i in doc.split(',')])\n",
    "        pbar.update(1)  # Update the tqdm progress bar\n",
    "        time.sleep(5)  # Add a 1-second delay between API calls (adjust as needed)\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        exception_list_2.append([e, answer])\n",
    "        pred_list_2.append(\"\")\n",
    "        pbar.update(1)  # Update the tqdm progress bar\n",
    "        time.sleep(5)  # Add a 1-second delay even when an exception occurs\n",
    "\n",
    "# question_list = question_list[:500]\n",
    "\n",
    "# Specify the number of threads by setting max_workers\n",
    "num_threads = 4  # You can adjust this number as needed\n",
    "with tqdm(total=len(question_list)) as pbar:\n",
    "    with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:\n",
    "        list(executor.map(process_question, exp_ques))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C', 'D', 'B']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_list_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(exp_list)):\n",
    "    pred_list[exp_list[i]] = pred_list_2[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = np.load(\"prediction/w_rag/medmcqa/pred.npy\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_list = list(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "true_list = np.load(\"data/medmcqa/answer_list.npy\")\n",
    "map_list = {\"a\":0, \"b\": 1, \"c\": 2, \"d\": 3}\n",
    "option_list = [\"a\", \"b\", \"c\", \"d\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_pross = []\n",
    "for i in range(len(pred_list)):\n",
    "    pred = pred_list[i]\n",
    "    actual = true_list[i]\n",
    "    if pred.lower() in option_list:\n",
    "        p = map_list[pred.lower()]\n",
    "        if p == actual:\n",
    "            pred_pross.append(True)\n",
    "        else:\n",
    "            pred_pross.append(False)\n",
    "    else:\n",
    "        pred_pross.append(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
      "To disable this warning, you can either:\n",
      "\t- Avoid using `tokenizers` before the fork if possible\n",
      "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
      "  _warn_prf(average, modifier, msg_start, len(result))\n"
     ]
    }
   ],
   "source": [
    "actual = [1 for pred in pred_pross]\n",
    "from sklearn.metrics import classification_report\n",
    "report = classification_report(actual, pred_pross)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.00      0.00      0.00         0\n",
      "           1       1.00      0.52      0.68       500\n",
      "\n",
      "    accuracy                           0.52       500\n",
      "   macro avg       0.50      0.26      0.34       500\n",
      "weighted avg       1.00      0.52      0.68       500\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(report)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/vectorstores/pinecone.py:59: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "from conversation import make_conversation, auth_function, random_response\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "demo = gr.ChatInterface(make_conversation).queue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# demo.launch(auth=auth_function, share=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from global_variable_module import global_output, gobal_input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# def random_response(message, accuracy, history):\n",
    "#     print(type(message))\n",
    "#     print(message)\n",
    "#     print(accuracy)\n",
    "    \n",
    "#     out = random.choice([\"Yes\", \"No\"])\n",
    "#     # open a txt file\n",
    "#     with open(\"function hit\", \"a+\") as f:\n",
    "#         f.write(message)\n",
    "#     return "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:816: UserWarning: Expected 3 arguments for function <function random_response at 0x29ba863b0>, received 2.\n",
      "  warnings.warn(\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:820: UserWarning: Expected at least 3 arguments for function <function random_response at 0x29ba863b0>, received 2.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "with gr.Blocks() as demo:\n",
    "    chatbot = gr.ChatInterface(random_response)\n",
    "    # print(chatbot)\n",
    "    radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n",
    "    submit_radio = gr.Button(value=\"Submit\")\n",
    "    t = gr.Textbox(value=\"\", label=\"Input\")\n",
    "    txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n",
    "    submit_radio.click(random_response, inputs=[t, radio], outputs=[txt_3])\n",
    "    # msg.submit(random_response, [msg, chatbot], [msg, chatbot])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'global_variable_module'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 99\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#Y203sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mglobal_variable_module\u001b[39;00m \u001b[39mimport\u001b[39;00m global_var\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'global_variable_module'"
     ]
    }
   ],
   "source": [
    "from global_variable_module import global_var"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\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": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/helpers.py:796: UserWarning: Unexpected argument. Filling with None.\n",
      "  warnings.warn(\"Unexpected argument. Filling with None.\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "hi\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "demo.launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/vectorstores/pinecone.py:59: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "from conversation import run\n",
    "import random\n",
    "import time\n",
    "import random\n",
    "\n",
    "global USERNAME\n",
    "global PASSWORD\n",
    "global INPUT\n",
    "global OUTPUT\n",
    "global SOURCE\n",
    "global DOCS\n",
    "\n",
    "def auth_function(username, password):\n",
    "    USERNAME = username\n",
    "    user_name = username\n",
    "    return username == password\n",
    "\n",
    "def random_response(message):\n",
    "    # print(type(message))\n",
    "    # print(message)\n",
    "    # print(accuracy)\n",
    "    \n",
    "    out = random.choice([\"Yes\", \"No\"])\n",
    "    # open a txt file\n",
    "    # with open(\"function hit\", \"a+\") as f:\n",
    "    #     f.write(message)\n",
    "    return out, \"THIS IS SOURCE\", \"THIS IS DOCS\"\n",
    "\n",
    "\n",
    "def make_conversation(message, history):\n",
    "    INPUT = message\n",
    "    text_, source, docs = random_response(message)\n",
    "    OUTPUT = text_\n",
    "    SOURCE = source\n",
    "    DOCS = docs\n",
    "\n",
    "    print(\"INPUT: \", INPUT)\n",
    "    print(\"OUTPUT: \", OUTPUT)\n",
    "    print(\"SOURCE: \", SOURCE)\n",
    "    print(\"DOCS: \", DOCS)\n",
    "\n",
    "    for i in range(len(text_)):\n",
    "        time.sleep(0.001)\n",
    "        yield text_[: i+1]\n",
    "\n",
    "def insert_text(accuracy, correct_output):\n",
    "    print(accuracy)\n",
    "    print(\"input \", INPUT)\n",
    "    print(\"output \", OUTPUT)\n",
    "    print(\"correct output\", correct_output)\n",
    "    print(\"source \", SOURCE)\n",
    "    print(\"docs \", DOCS)\n",
    "\n",
    "    return \"DONE\"\n",
    "\n",
    "with gr.Blocks() as demo:\n",
    "    chatbot = gr.ChatInterface(make_conversation)\n",
    "    # print(chatbot)\n",
    "    radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n",
    "    t = gr.Textbox(value=\"\", label=\"Input\")\n",
    "    submit_radio = gr.Button(value=\"Submit\")\n",
    "    txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n",
    "    submit_radio.click(insert_text, inputs=[t, radio], outputs=[txt_3])\n",
    "    # msg.submit(random_response, [msg, chatbot], [msg, chatbot])\n",
    "\n",
    "# with gr.Blocks(css=\"style.css\") as demo:\n",
    "#     gr.Markdown(\"##DR. VAI\")\n",
    "#     gr.ChatInterface(make_conversation).queue()\n",
    "\n",
    "# demo.launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\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": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INPUT:  hi\n",
      "OUTPUT:  No\n",
      "SOURCE:  THIS IS SOURCE\n",
      "DOCS:  THIS IS DOCS\n",
      "this is correct\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n",
      "    output = await route_utils.call_process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n",
      "    output = await app.get_blocks().process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1497, in process_api\n",
      "    result = await self.call_function(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1119, in call_function\n",
      "    prediction = await anyio.to_thread.run_sync(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/to_thread.py\", line 33, in run_sync\n",
      "    return await get_asynclib().run_sync_in_worker_thread(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 877, in run_sync_in_worker_thread\n",
      "    return await future\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 807, in run\n",
      "    result = context.run(func, *args)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py\", line 665, in wrapper\n",
      "    response = f(*args, **kwargs)\n",
      "  File \"/var/folders/73/1kdzs7qn01v55rn5825j1cjr0000gn/T/ipykernel_7321/1082532790.py\", line 49, in insert_text\n",
      "    print(\"input \", INPUT)\n",
      "NameError: name 'INPUT' is not defined\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n",
      "    output = await route_utils.call_process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n",
      "    output = await app.get_blocks().process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1497, in process_api\n",
      "    result = await self.call_function(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1119, in call_function\n",
      "    prediction = await anyio.to_thread.run_sync(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/to_thread.py\", line 33, in run_sync\n",
      "    return await get_asynclib().run_sync_in_worker_thread(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 877, in run_sync_in_worker_thread\n",
      "    return await future\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 807, in run\n",
      "    result = context.run(func, *args)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py\", line 665, in wrapper\n",
      "    response = f(*args, **kwargs)\n",
      "  File \"/var/folders/73/1kdzs7qn01v55rn5825j1cjr0000gn/T/ipykernel_7321/1082532790.py\", line 49, in insert_text\n",
      "    print(\"input \", INPUT)\n",
      "NameError: name 'INPUT' is not defined\n",
      "\n",
      "The above exception was the direct cause of the following exception:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 472, in process_events\n",
      "    response = await self.call_prediction(awake_events, batch)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 436, in call_prediction\n",
      "    raise Exception(str(error) if show_error else None) from error\n",
      "Exception: None\n"
     ]
    }
   ],
   "source": [
    "demo.launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'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'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "os.getenv(\"OPENAI_API_KEY\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:816: UserWarning: Expected 2 arguments for function <function insert_text at 0x288a30d30>, received 1.\n",
      "  warnings.warn(\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:820: UserWarning: Expected at least 2 arguments for function <function insert_text at 0x288a30d30>, received 1.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7862\n",
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7862/\" 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": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import gradio as gr\n",
    "from conversation import run, auth_function\n",
    "import random\n",
    "import time\n",
    "import random\n",
    "\n",
    "\n",
    "\n",
    "def random_response(message):\n",
    "    \n",
    "    out = random.choice([\"Yes\", \"No\"])\n",
    "    return out, \"THIS IS SOURCE\", \"THIS IS DOCS\"\n",
    "\n",
    "\n",
    "def make_conversation(message, history):\n",
    "    text_, source, docs = run(message)\n",
    "    return text_, str(history)\n",
    "\n",
    "\n",
    "with gr.Blocks() as demo:\n",
    "    input_history = gr.State([])\n",
    "    output1_history = gr.State([])\n",
    "    output_2_history = gr.State([])\n",
    "\n",
    "   \n",
    "\n",
    "    chatbot = gr.ChatInterface(make_conversation)\n",
    "    # print(chatbot)\n",
    "    radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n",
    "    t = gr.Textbox(value=\"\", label=\"Input\")\n",
    "    submit_radio = gr.Button(value=\"Submit\")\n",
    "    txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n",
    "    \n",
    "    # msg.submit(random_response, [msg, chatbot], [msg, chatbot])\n",
    "\n",
    "    def make_conversation(message, history):\n",
    "        text_, source, docs = run(message)\n",
    "        return {\n",
    "            input_history: message,\n",
    "            output1_history: text_,\n",
    "\n",
    "        }\n",
    "    \n",
    "    submit_radio.click(insert_text, inputs=[chatbot], outputs=[txt_3])\n",
    "# with gr.Blocks(css=\"style.css\") as demo:\n",
    "#     gr.Markdown(\"##DR. VAI\")\n",
    "#     gr.ChatInterface(make_conversation).queue()\n",
    "\n",
    "demo.launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/vectorstores/pinecone.py:59: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "\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": 1,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3mHello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n",
      "    output = await route_utils.call_process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n",
      "    output = await app.get_blocks().process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1506, in process_api\n",
      "    data = self.postprocess_data(fn_index, result[\"prediction\"], state)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1396, in postprocess_data\n",
      "    outputs_cached = processing_utils.move_files_to_cache(prediction_value, block)  # type: ignore\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 294, in move_files_to_cache\n",
      "    return client_utils.traverse(data, _move_to_cache, client_utils.is_file_obj)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n",
      "    new_obj.append(traverse(item, func, is_root))\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n",
      "    new_obj.append(traverse(item, func, is_root))\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 777, in traverse\n",
      "    new_obj[key] = traverse(value, func, is_root)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 773, in traverse\n",
      "    return func(json_obj)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 287, in _move_to_cache\n",
      "    temp_file_path = move_resource_to_block_cache(payload.path, block)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 265, in move_resource_to_block_cache\n",
      "    temp_file_path = save_file_to_cache(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 191, in save_file_to_cache\n",
      "    temp_dir = hash_file(file_path)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 118, in hash_file\n",
      "    with open(file_path, \"rb\") as f:\n",
      "FileNotFoundError: [Errno 2] No such file or directory: \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\"\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n",
      "    output = await route_utils.call_process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n",
      "    output = await app.get_blocks().process_api(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1506, in process_api\n",
      "    data = self.postprocess_data(fn_index, result[\"prediction\"], state)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1396, in postprocess_data\n",
      "    outputs_cached = processing_utils.move_files_to_cache(prediction_value, block)  # type: ignore\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 294, in move_files_to_cache\n",
      "    return client_utils.traverse(data, _move_to_cache, client_utils.is_file_obj)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n",
      "    new_obj.append(traverse(item, func, is_root))\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n",
      "    new_obj.append(traverse(item, func, is_root))\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 777, in traverse\n",
      "    new_obj[key] = traverse(value, func, is_root)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 773, in traverse\n",
      "    return func(json_obj)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 287, in _move_to_cache\n",
      "    temp_file_path = move_resource_to_block_cache(payload.path, block)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 265, in move_resource_to_block_cache\n",
      "    temp_file_path = save_file_to_cache(\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 191, in save_file_to_cache\n",
      "    temp_dir = hash_file(file_path)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 118, in hash_file\n",
      "    with open(file_path, \"rb\") as f:\n",
      "FileNotFoundError: [Errno 2] No such file or directory: \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\"\n",
      "\n",
      "The above exception was the direct cause of the following exception:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 472, in process_events\n",
      "    response = await self.call_prediction(awake_events, batch)\n",
      "  File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 436, in call_prediction\n",
      "    raise Exception(str(error) if show_error else None) from error\n",
      "Exception: None\n"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "from conversation import make_conversation, auth_function\n",
    "import random\n",
    "\n",
    "demo = gr.ChatInterface(make_conversation).queue()\n",
    "\n",
    "demo.launch(auth=auth_function)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Token will not been saved to git credential helper. Pass `add_to_git_credential=True` if you want to set the git credential as well.\n",
      "Token is valid (permission: write).\n",
      "Your token has been saved to /Users/aakashbhatnagar/.cache/huggingface/token\n",
      "Login successful\n"
     ]
    }
   ],
   "source": [
    "# !huggingface-cli login\n",
    "# or using an environment variable\n",
    "!huggingface-cli login --token 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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Dependency' object has no attribute 'launch'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 109\u001b[0m line \u001b[0;36m2\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#Y212sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mgradio\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mgr\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb#Y212sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m gr\u001b[39m.\u001b[39;49mInterface\u001b[39m.\u001b[39;49mload(\u001b[39m\"\u001b[39;49m\u001b[39mhuggingface/drvai/drvai\u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m.\u001b[39;49mlaunch()\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'Dependency' object has no attribute 'launch'"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "gr.Interface.load(\"huggingface/drvai/drvai\").launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "myenv",
   "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.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}