postcardbuilder / app.py
ricklon
added defaults again
4393dfe
import gradio as gr
from svgwrite import Drawing
import qrcode
from PIL import Image
import base64
from io import BytesIO
def create_postcard(name, tagline, description, events, location, hours, contact, call_to_action, logo_file_info):
dwg = Drawing(size=("200mm", "100mm"))
# Add a light green background
dwg.add(dwg.rect(insert=("0mm", "0mm"), size=("200mm", "100mm"), fill="#90EE90")) # Light green
if logo_file_info is not None:
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))
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))
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(name)
qr.make(fit=True)
qr_img = qr.make_image(fill_color="black", back_color="white")
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", value="FUBAR Labs"),
gr.Textbox(label="Tagline or Mission Statement", value="Promoting education & collaboration through technical, scientific, and artistic skills."),
gr.TextArea(label="Description of Services", value="FUBAR Labs is a community space that offers workshops, collaborative projects, and educational events in STEM and arts."),
gr.TextArea(label="Upcoming Events", value="AI study GROUP, 3D Printing, Fusion 360, KiCAD"),
gr.Textbox(label="Location", value="1510b Jersey Avenue, North Brunswick, NJ 08902"),
gr.Textbox(label="Hours of Operation", value="Thurs 7:30 PM - 9:30 PM, Sun: 1:30 PM - 4:30 PM"),
gr.Textbox(label="Contact Information", value="Phone: 732-50-FUBAR\nEmail: info@fubarlabs.org"),
gr.Textbox(label="Call to Action", value="Join us and bring your ideas to life! Visit our website for more info."),
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()