|
import qrcode |
|
import base64 |
|
import gradio as gr |
|
|
|
|
|
def txt2qrcode(text: str): |
|
|
|
encoded_text = base64.b64encode(text.encode('utf-8')).decode('utf-8') |
|
|
|
|
|
final_url = f"https://flowly-ai.vercel.app/tools/qr/pro-qr-codes/read/{encoded_text}" |
|
|
|
|
|
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) |
|
|
|
|
|
img_qr = qr.make_image(fill='black', back_color='white') |
|
|
|
|
|
output_path = "qr_code.png" |
|
img_qr.save(output_path) |
|
|
|
return output_path |
|
|
|
|
|
def qr_code_interface(text: str): |
|
result = txt2qrcode(text) |
|
return result |
|
|
|
|
|
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}" |
|
) |
|
|
|
|
|
interface.launch() |
|
|