Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This Gradio app generates a QR code from a given URL and applies a sepia filter to the image.
|
2 |
+
#reference https://github.com/lincolnloop/python-qrcode
|
3 |
+
import numpy as np
|
4 |
+
import qrcode
|
5 |
+
import gradio as gr
|
6 |
+
##
|
7 |
+
from qrcode.image.styledpil import StyledPilImage
|
8 |
+
from qrcode.image.styles.moduledrawers.pil import HorizontalBarsDrawer
|
9 |
+
##
|
10 |
+
|
11 |
+
def sepia(text1):
|
12 |
+
# Generate a QR code from the input text
|
13 |
+
##img = qrcode.make(text1)
|
14 |
+
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
|
15 |
+
qr.add_data(text1)
|
16 |
+
img=qr.make_image(image_factory=StyledPilImage, module_drawer=HorizontalBarsDrawer())
|
17 |
+
# Convert the QR code to a numpy array
|
18 |
+
img_np = np.array(img.convert("RGB"))
|
19 |
+
# Define the sepia filter matrix
|
20 |
+
sepia_filter = np.array([
|
21 |
+
[1.0, 1.0, 1.0],
|
22 |
+
[1.0, 1.0, 1.0],
|
23 |
+
[1.0, 1.0, 1.0]
|
24 |
+
])
|
25 |
+
# Apply the sepia filter to the image
|
26 |
+
sepia_img = img_np.dot(sepia_filter.T)
|
27 |
+
# Normalize the image to the range [0, 255]
|
28 |
+
sepia_img /= sepia_img.max()
|
29 |
+
sepia_img *= 255
|
30 |
+
# Convert the image back to uint8
|
31 |
+
sepia_img = sepia_img.astype(np.uint8)
|
32 |
+
# Return the sepia-filtered image
|
33 |
+
#return img
|
34 |
+
return sepia_img
|
35 |
+
|
36 |
+
# Create a Gradio interface that takes a textbox input, runs it through the sepia function, and returns output to an image.
|
37 |
+
demo = gr.Interface(sepia, gr.Textbox(
|
38 |
+
label="Enter Website URL",
|
39 |
+
info="Kindly include 'https://'",
|
40 |
+
lines=7,
|
41 |
+
value="",
|
42 |
+
), "image", theme=gr.themes.Monochrome(),
|
43 |
+
title = 'QR Code Maker', css='footer {visibility: hidden}')
|
44 |
+
|
45 |
+
# Launch the interface.
|
46 |
+
if __name__ == "__main__":
|
47 |
+
demo.launch()
|