Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +59 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import uuid # Permite generar valores aleatorios
|
3 |
+
from amzqr import amzqr
|
4 |
+
from PIL import Image
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
|
8 |
+
class GeneradorQR():
|
9 |
+
|
10 |
+
# Constructor
|
11 |
+
def __init__(self, fondo, hipervinculo, nombre_archivo):
|
12 |
+
self.__fondo = fondo
|
13 |
+
self.__hipervinculo = hipervinculo
|
14 |
+
self.__nombre_archivo = nombre_archivo
|
15 |
+
|
16 |
+
def generate_qrcode(self):
|
17 |
+
_, _, self.__qr_name = amzqr.run(
|
18 |
+
self.__hipervinculo, # Hipervinculo
|
19 |
+
version=1,
|
20 |
+
level='H',
|
21 |
+
picture=self.__fondo, # Imagen de fondo
|
22 |
+
colorized=True,
|
23 |
+
contrast=1.0,
|
24 |
+
brightness=0.8,
|
25 |
+
save_name=self.__nombre_archivo, # Nombre del archivo con el c贸digo QR
|
26 |
+
save_dir=os.getcwd()
|
27 |
+
)
|
28 |
+
|
29 |
+
def get_qrcode(self):
|
30 |
+
return self.__qr_name
|
31 |
+
|
32 |
+
|
33 |
+
# Funci贸n para Gradio
|
34 |
+
def generar_qr(hipervinculo, fondo):
|
35 |
+
nombre_archivo = f"{uuid.uuid4()}.png" # Nombre del archivo imagen. Es un valor aleatorio
|
36 |
+
# Instanciar la clase GeneradorQR
|
37 |
+
print(f'nombre_archivo:{nombre_archivo}')
|
38 |
+
print(f'hipervinculo:{hipervinculo}')
|
39 |
+
print(f'fondo:{fondo}')
|
40 |
+
generador_qr = GeneradorQR(nombre_archivo=nombre_archivo,
|
41 |
+
hipervinculo=hipervinculo,
|
42 |
+
fondo=fondo)
|
43 |
+
generador_qr.generate_qrcode() # Genera archivo imagen con el c贸digo QR
|
44 |
+
qr_path = generador_qr.get_qrcode() # Obtiene ruta del archivo imagen con el c贸digo QR
|
45 |
+
return qr_path
|
46 |
+
|
47 |
+
|
48 |
+
# Interfaz de Gradio
|
49 |
+
interface = gr.Interface(
|
50 |
+
fn=generar_qr,
|
51 |
+
inputs=[
|
52 |
+
gr.Textbox(label="Hiperv铆nculo"),
|
53 |
+
gr.Image(type="filepath", label="Imagen de fondo")
|
54 |
+
],
|
55 |
+
outputs=gr.Image(label="C贸digo QR generado"),
|
56 |
+
title="Generador de c贸digo QR con fondo personalizado"
|
57 |
+
)
|
58 |
+
|
59 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ipython==8.29.0
|
2 |
+
amzqr==0.0.1
|