File size: 3,320 Bytes
0d4acc0
1ab9eb6
92300cd
 
0d4acc0
909adc2
1ab9eb6
0d4acc0
4717b82
1ab9eb6
 
 
e883e33
1ab9eb6
 
 
 
 
 
 
92300cd
1ab9eb6
 
 
 
92300cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ab9eb6
92300cd
 
 
 
 
1ab9eb6
 
 
 
 
 
 
 
 
 
 
8f34b79
 
1ab9eb6
 
 
 
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

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()