Spaces:
Runtime error
Runtime error
Mateo Fidabel
commited on
Commit
路
7825075
1
Parent(s):
cd87cfc
Se agrega los portanombres
Browse files- .gitignore +1 -0
- app.py +88 -1
- fonts/Montserrat-Bold.ttf +0 -0
- fonts/Montserrat-Regular.ttf +0 -0
- fonts/Quattrocento-Bold.ttf +0 -0
- fonts/Quattrocento-Regular.ttf +0 -0
- modelos/mascara_qr.png +0 -0
- modelos/portanombres.png +0 -0
- requirements.txt +3 -2
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
voluntarios_repo
|
app.py
CHANGED
@@ -1,6 +1,89 @@
|
|
1 |
import gradio as gr
|
2 |
import qrcode
|
3 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def generar_qr(texto):
|
6 |
return np.array(qrcode.make(texto).convert("L"))
|
@@ -9,6 +92,10 @@ qr_demo = gr.Interface(fn=generar_qr,
|
|
9 |
inputs=gr.Text(label="Texto/Link"),
|
10 |
outputs=gr.Image(label="C贸digo QR"))
|
11 |
|
12 |
-
demo = gr.TabbedInterface([
|
|
|
|
|
|
|
|
|
13 |
|
14 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import qrcode
|
3 |
import numpy as np
|
4 |
+
from delta import *
|
5 |
+
import pyspark
|
6 |
+
import pyspark.sql.functions as F
|
7 |
+
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
8 |
+
import os
|
9 |
+
from huggingface_hub import HfApi, hf_hub_download, Repository
|
10 |
+
|
11 |
+
# Configurar dataset de voluntarios
|
12 |
+
api = HfApi()
|
13 |
+
|
14 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/ieeecsuna-comite/bd-voluntarios"
|
15 |
+
VOLUNTARIOS_TABLE = "voluntarios"
|
16 |
+
VOLUNTARIOS_DIR = "voluntarios_repo"
|
17 |
+
|
18 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
19 |
+
|
20 |
+
repo = Repository(
|
21 |
+
local_dir=VOLUNTARIOS_DIR, clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
22 |
+
)
|
23 |
+
|
24 |
+
repo.git_pull()
|
25 |
+
|
26 |
+
# Crear la app de Spark
|
27 |
+
builder = pyspark.sql.SparkSession.builder.appName("IEEECSTOOLS") \
|
28 |
+
.config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension") \
|
29 |
+
.config("spark.sql.catalog.spark_catalog", "org.apache.spark.sql.delta.catalog.DeltaCatalog")
|
30 |
+
|
31 |
+
spark = configure_spark_with_delta_pip(builder).getOrCreate()
|
32 |
+
|
33 |
+
bd_cc = spark.read.format("delta").load(os.path.join(VOLUNTARIOS_DIR, VOLUNTARIOS_TABLE))
|
34 |
+
|
35 |
+
# Paths
|
36 |
+
font_path = "./fonts"
|
37 |
+
modelos_path = "./modelos"
|
38 |
+
|
39 |
+
# Configuraciones
|
40 |
+
name_font = ImageFont.truetype(os.path.join(font_path, "Montserrat-Bold.ttf"), 45)
|
41 |
+
comite_font = ImageFont.truetype(os.path.join(font_path, "Montserrat-Regular.ttf"), 35)
|
42 |
+
codigo_font = ImageFont.truetype(os.path.join(font_path, "Montserrat-Regular.ttf"), 25)
|
43 |
+
|
44 |
+
|
45 |
+
def generar_portanombre(id = "CSUNA-XX0000"):
|
46 |
+
im = Image.open(os.path.join(modelos_path, "portanombres.png")).convert("RGBA")
|
47 |
+
|
48 |
+
try:
|
49 |
+
# Obtener voluntario
|
50 |
+
voluntario = bd_cc.filter(F.col("cod_voluntario") == id).collect()[0]
|
51 |
+
|
52 |
+
# Construir el nombre y el c贸digo de voluntario
|
53 |
+
name = (str(voluntario["Nombre"]) + " " + str(voluntario["Apellido"])).upper()
|
54 |
+
codigo = id
|
55 |
+
|
56 |
+
# Generar c贸digo QR
|
57 |
+
codigo_qr = codigo_qr = qrcode.make(codigo).convert("RGBA").resize((290, 290))
|
58 |
+
mascara_qr = Image.open(os.path.join(modelos_path, "mascara_qr.png")).convert("L").resize((290, 290))
|
59 |
+
im.paste(codigo_qr, (645, 91), mask=mascara_qr)
|
60 |
+
|
61 |
+
# Poner los nombres
|
62 |
+
d = ImageDraw.Draw(im)
|
63 |
+
|
64 |
+
# Nombre
|
65 |
+
if len(name) < 30:
|
66 |
+
d.text((505, 517), name, fill="black", anchor="mm", font=name_font)
|
67 |
+
else:
|
68 |
+
d.text((505, 517), name, fill="black", anchor="mm", font=ImageFont.truetype(os.path.join(font_path, "Montserrat-Bold.ttf"), 35))
|
69 |
+
|
70 |
+
# Comite
|
71 |
+
d.text((505, 573), "Comit茅 de Cursos y Charlas", fill="black", anchor="mm", font=comite_font)
|
72 |
+
|
73 |
+
# Codigo
|
74 |
+
d.text((790, 361), codigo, fill="gray", anchor="mm", font=codigo_font)
|
75 |
+
|
76 |
+
except Exception as e:
|
77 |
+
print("Hubo un error al generar: " + e)
|
78 |
+
finally:
|
79 |
+
return im.convert("RGB")
|
80 |
+
|
81 |
+
with gr.Blocks() as portanombre_demo:
|
82 |
+
id = gr.Textbox(label="Identificador")
|
83 |
+
portanombre = gr.Image(label="Portanombre")
|
84 |
+
generar_boton = gr.Button("Generar Portanombre")
|
85 |
+
generar_boton.click(fn=generar_portanombre, inputs=id, outputs=portanombre, api_name="portanombre")
|
86 |
+
|
87 |
|
88 |
def generar_qr(texto):
|
89 |
return np.array(qrcode.make(texto).convert("L"))
|
|
|
92 |
inputs=gr.Text(label="Texto/Link"),
|
93 |
outputs=gr.Image(label="C贸digo QR"))
|
94 |
|
95 |
+
demo = gr.TabbedInterface([portanombre_demo,
|
96 |
+
qr_demo],
|
97 |
+
["馃挸 Generar Portanombre",
|
98 |
+
"馃 Generador de C贸digo QR"],
|
99 |
+
title="Herramientas de IEEE CS SBC UNA")
|
100 |
|
101 |
demo.launch()
|
fonts/Montserrat-Bold.ttf
ADDED
Binary file (198 kB). View file
|
|
fonts/Montserrat-Regular.ttf
ADDED
Binary file (198 kB). View file
|
|
fonts/Quattrocento-Bold.ttf
ADDED
Binary file (154 kB). View file
|
|
fonts/Quattrocento-Regular.ttf
ADDED
Binary file (148 kB). View file
|
|
modelos/mascara_qr.png
ADDED
![]() |
modelos/portanombres.png
ADDED
![]() |
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
qrcode==7.4.2
|
2 |
-
numpy
|
3 |
Pillow==9.4.0
|
4 |
-
|
|
|
|
1 |
qrcode==7.4.2
|
2 |
+
numpy>=1.23.5
|
3 |
Pillow==9.4.0
|
4 |
+
pyspark==3.4.1
|
5 |
+
delta-spark==2.4.0
|