QR Code Generation For Assets

I want to Generate QR Codes for Assets. When an Asset is opened there should be a Button to generate a QR Code for the Asset ID. I already created an Image Field and a Button field. I’m trying to use an API to generate QR Codes. Below is the Code that I have written so far,

import frappe
import base64
import requests

def custom_generate_qr_code(doc, method):
    if doc.custom_generate_qr_code:
        qr_code_url = f"https://quickchart.io/qr?text={doc.name}"
        response = requests.get(qr_code_url)
        
        if response.status_code == 200:
            img_str = base64.b64encode(response.content).decode()
            doc.custom_qr_code = f"data:image/png;base64,{img_str}"
        
        doc.generate_qr_code = None

I get an error in the Line 2, stating “Expected ‘from’ and instead saw ‘import’. Expected ‘(string)’ and instead saw ‘base64’. Missing semicolon.”

Not sure, but it should set like

doc.custom_generate_qr_code = None

instead of

doc.generate_qr_code = None