File size: 3,823 Bytes
0d4acc0
1ab9eb6
92300cd
 
c7683c0
 
 
909adc2
1ab9eb6
55e8666
fbc2c3c
 
0d4acc0
4717b82
1ab9eb6
e883e33
1ab9eb6
 
 
 
 
 
 
92300cd
1ab9eb6
 
 
 
92300cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55e8666
92300cd
 
1ab9eb6
92300cd
 
 
 
1ab9eb6
 
 
 
 
 
 
 
 
4393dfe
 
 
 
 
 
 
 
92300cd
1ab9eb6
 
 
 
 
 
40f23b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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()