Spaces:
Running
Running
File size: 1,695 Bytes
d9a73e9 | 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 | # This Gradio app generates a QR code from a given URL and applies a sepia filter to the image.
#reference https://github.com/lincolnloop/python-qrcode
import numpy as np
import qrcode
import gradio as gr
##
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import HorizontalBarsDrawer
##
def sepia(text1):
# Generate a QR code from the input text
##img = qrcode.make(text1)
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data(text1)
img=qr.make_image(image_factory=StyledPilImage, module_drawer=HorizontalBarsDrawer())
# Convert the QR code to a numpy array
img_np = np.array(img.convert("RGB"))
# Define the sepia filter matrix
sepia_filter = np.array([
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0]
])
# Apply the sepia filter to the image
sepia_img = img_np.dot(sepia_filter.T)
# Normalize the image to the range [0, 255]
sepia_img /= sepia_img.max()
sepia_img *= 255
# Convert the image back to uint8
sepia_img = sepia_img.astype(np.uint8)
# Return the sepia-filtered image
#return img
return sepia_img
# Create a Gradio interface that takes a textbox input, runs it through the sepia function, and returns output to an image.
demo = gr.Interface(sepia, gr.Textbox(
label="Enter Website URL",
info="Kindly include 'https://'",
lines=7,
value="",
), "image", theme=gr.themes.Monochrome(),
title = 'QR Code Maker', css='footer {visibility: hidden}')
# Launch the interface.
if __name__ == "__main__":
demo.launch() |