postcardbuilder / app.py
ricklon
missing code filled in
92300cd
raw
history blame
No virus
3.32 kB
import gradio as gr
from svgwrite import Drawing
import qrcode
from PIL import Image
def create_postcard(name, tagline, description, events, location, hours, contact, call_to_action, logo_file_info):
dwg = Drawing(size=("200mm", "100mm"))
if logo_file_info is not None:
import base64
from io import BytesIO
buffer = BytesIO()
logo_file_info.save(buffer, format="PNG")
logo_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
dwg.add(dwg.image(href=f"data:image/png;base64,{logo_base64}", insert=("10mm", "10mm"), size=("50mm", "50mm")))
header_style = "font-size:18px; font-weight:bold;"
subheader_style = "font-size:12px;"
text_style = "font-size:10px;"
dwg.add(dwg.text(name, insert=("10mm", "15mm"), style=header_style))
dwg.add(dwg.text(tagline, insert=("10mm", "25mm"), style=subheader_style))
dwg.add(dwg.rect(insert=("150mm", "80mm"), size=("40mm", "15mm"), rx="2mm", fill="#FFD700"))
dwg.add(dwg.text(call_to_action, insert=("155mm", "90mm"), style=header_style))
# Add description, events, location, hours, and contact information
dwg.add(dwg.text("Description:", insert=("10mm", "40mm"), style=subheader_style))
dwg.add(dwg.text(description, insert=("10mm", "45mm"), style=text_style))
dwg.add(dwg.text("Events:", insert=("10mm", "55mm"), style=subheader_style))
dwg.add(dwg.text(events, insert=("10mm", "60mm"), style=text_style))
dwg.add(dwg.text("Location:", insert=("10mm", "70mm"), style=subheader_style))
dwg.add(dwg.text(location, insert=("10mm", "75mm"), style=text_style))
dwg.add(dwg.text("Hours:", insert=("10mm", "80mm"), style=subheader_style))
dwg.add(dwg.text(hours, insert=("10mm", "85mm"), style=text_style))
dwg.add(dwg.text("Contact:", insert=("10mm", "90mm"), style=subheader_style))
dwg.add(dwg.text(contact, insert=("10mm", "95mm"), style=text_style))
# Generate QR Code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(name) # You can change this to any data you'd like to encode
qr.make(fit=True)
qr_img = qr.make_image(fill_color="black", back_color="white")
# Embed QR Code in SVG
buffer = BytesIO()
qr_img.save(buffer, format="PNG")
qr_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
dwg.add(dwg.image(href=f"data:image/png;base64,{qr_base64}", insert=("150mm", "10mm"), size=("40mm", "40mm")))
svg_output = name.replace(" ", "_").lower() + "_postcard.svg"
dwg.saveas(svg_output)
return svg_output
iface = gr.Interface(
fn=create_postcard,
inputs=[
gr.Textbox(label="Makerspace Name"),
gr.Textbox(label="Tagline or Mission Statement"),
gr.TextArea(label="Description of Services"),
gr.TextArea(label="Upcoming Events"),
gr.Textbox(label="Location"),
gr.Textbox(label="Hours of Operation"),
gr.Textbox(label="Contact Information"),
gr.Textbox(label="Call to Action"),
gr.Image(label="Upload Logo", type="pil")
],
outputs="file",
title="Makerspace Postcard Creator",
description="Fill out the details to create a postcard for your makerspace."
)
iface.queue().launch()