File size: 1,463 Bytes
af74360
b8adac9
af74360
 
b8adac9
 
 
 
 
 
 
 
af74360
 
 
b8adac9
af74360
 
 
b8adac9
af74360
 
 
 
 
b8adac9
 
af74360
 
 
 
b8adac9
 
 
af74360
 
 
 
 
b8adac9
 
 
af74360
 
 
 
 
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
import qrcode
import urllib.parse
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 = urllib.parse.quote(text)  # 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="file", 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()