How to adjust Kp and Kd values automatically?

im using the QTR-8RC sensor for line follower.Is there anyway to calculate the Kp Kd values for the line follower automatically in the code without changing the values and burning the code again and again

There are various automatic PID tuning algorithms (your favorite search engine will show them to you), but they would not be practical to implement in a line follower.

Many people write interactive code to modify the K values between runs, which avoids uploading new software. If you are using Arduino, the serial monitor can display current values, and the keyboard can be used to send commands and/or data back to the robot.

why wont they be practical for line follower?

If you look up how the automatic tuning algorithms work and at some example code, you will understand.

but i found out there is a autotune pid lib file for arduino wont it be good?

Try it and see!