import qrcode import base64 import gradio as gr # Function to process text and generate QR code def txt2qrcode(text: str): # Encode the text as URL-safe base64 or URL encoding encoded_text = base64.b64encode(text.encode('utf-8')).decode('utf-8') # URL encoding the input text # Construct the final URL to embed into the QR code final_url = f"https://flowly-ai.vercel.app/tools/qr/pro-qr-codes/read/{encoded_text}" # Create the QR code qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(final_url) qr.make(fit=True) # Create an image for the QR code img_qr = qr.make_image(fill='black', back_color='white') # Save the QR code image and return the path output_path = "qr_code.png" img_qr.save(output_path) return output_path # Gradio Interface for the QR code generation def qr_code_interface(text: str): result = txt2qrcode(text) return result # Create a Gradio interface interface = gr.Interface( fn=qr_code_interface, inputs=gr.Textbox(label="Enter Text to Encode", placeholder="Enter your text here..."), outputs=gr.Image(type="filepath", label="Generated QR Code"), description="Generate a QR Code from your text. The input text will be URL encoded and embedded into a QR code pointing to a specific URL.", css="footer {visibility: hidden}" ) # Launch the Gradio app interface.launch()