ricklon commited on
Commit
92300cd
·
1 Parent(s): e883e33

missing code filled in

Browse files
Files changed (1) hide show
  1. app.py +31 -22
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  from svgwrite import Drawing
 
 
3
 
4
  def create_postcard(name, tagline, description, events, location, hours, contact, call_to_action, logo_file_info):
5
- # Create a new SVG drawing
6
  dwg = Drawing(size=("200mm", "100mm"))
7
 
8
- # Assume the logo is a PIL Image; convert to base64 to embed in SVG
9
  if logo_file_info is not None:
10
  import base64
11
  from io import BytesIO
@@ -13,39 +13,50 @@ def create_postcard(name, tagline, description, events, location, hours, contact
13
  logo_file_info.save(buffer, format="PNG")
14
  logo_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
15
  dwg.add(dwg.image(href=f"data:image/png;base64,{logo_base64}", insert=("10mm", "10mm"), size=("50mm", "50mm")))
16
-
17
 
18
- # Define text styles
19
  header_style = "font-size:18px; font-weight:bold;"
20
  subheader_style = "font-size:12px;"
21
  text_style = "font-size:10px;"
22
-
23
- # Add the Makerspace name
24
- dwg.add(dwg.text(name, insert=("10mm", "15mm"), style=header_style))
25
 
26
- # Add the tagline
27
  dwg.add(dwg.text(tagline, insert=("10mm", "25mm"), style=subheader_style))
28
-
29
- # Add a rectangle for the CTA
30
  dwg.add(dwg.rect(insert=("150mm", "80mm"), size=("40mm", "15mm"), rx="2mm", fill="#FFD700"))
31
  dwg.add(dwg.text(call_to_action, insert=("155mm", "90mm"), style=header_style))
32
 
33
- # Add description, events, and other information
34
- # ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- # For QR Code: You'll need to use a QR Code generator library to create a QR code
37
- # and then convert it to SVG to include it here.
38
- # ...
 
 
39
 
40
- # Save the SVG to a file
41
  svg_output = name.replace(" ", "_").lower() + "_postcard.svg"
42
  dwg.saveas(svg_output)
43
 
44
  return svg_output
45
 
46
-
47
-
48
- # Define your Gradio interface
49
  iface = gr.Interface(
50
  fn=create_postcard,
51
  inputs=[
@@ -57,13 +68,11 @@ iface = gr.Interface(
57
  gr.Textbox(label="Hours of Operation"),
58
  gr.Textbox(label="Contact Information"),
59
  gr.Textbox(label="Call to Action"),
60
- gr.Image(label="Upload Logo", type="pil") # Accepts image uploads
61
-
62
  ],
63
  outputs="file",
64
  title="Makerspace Postcard Creator",
65
  description="Fill out the details to create a postcard for your makerspace."
66
  )
67
 
68
- # Run the interface
69
  iface.queue().launch()
 
1
  import gradio as gr
2
  from svgwrite import Drawing
3
+ import qrcode
4
+ from PIL import Image
5
 
6
  def create_postcard(name, tagline, description, events, location, hours, contact, call_to_action, logo_file_info):
 
7
  dwg = Drawing(size=("200mm", "100mm"))
8
 
 
9
  if logo_file_info is not None:
10
  import base64
11
  from io import BytesIO
 
13
  logo_file_info.save(buffer, format="PNG")
14
  logo_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
15
  dwg.add(dwg.image(href=f"data:image/png;base64,{logo_base64}", insert=("10mm", "10mm"), size=("50mm", "50mm")))
 
16
 
 
17
  header_style = "font-size:18px; font-weight:bold;"
18
  subheader_style = "font-size:12px;"
19
  text_style = "font-size:10px;"
 
 
 
20
 
21
+ dwg.add(dwg.text(name, insert=("10mm", "15mm"), style=header_style))
22
  dwg.add(dwg.text(tagline, insert=("10mm", "25mm"), style=subheader_style))
 
 
23
  dwg.add(dwg.rect(insert=("150mm", "80mm"), size=("40mm", "15mm"), rx="2mm", fill="#FFD700"))
24
  dwg.add(dwg.text(call_to_action, insert=("155mm", "90mm"), style=header_style))
25
 
26
+ # Add description, events, location, hours, and contact information
27
+ dwg.add(dwg.text("Description:", insert=("10mm", "40mm"), style=subheader_style))
28
+ dwg.add(dwg.text(description, insert=("10mm", "45mm"), style=text_style))
29
+ dwg.add(dwg.text("Events:", insert=("10mm", "55mm"), style=subheader_style))
30
+ dwg.add(dwg.text(events, insert=("10mm", "60mm"), style=text_style))
31
+ dwg.add(dwg.text("Location:", insert=("10mm", "70mm"), style=subheader_style))
32
+ dwg.add(dwg.text(location, insert=("10mm", "75mm"), style=text_style))
33
+ dwg.add(dwg.text("Hours:", insert=("10mm", "80mm"), style=subheader_style))
34
+ dwg.add(dwg.text(hours, insert=("10mm", "85mm"), style=text_style))
35
+ dwg.add(dwg.text("Contact:", insert=("10mm", "90mm"), style=subheader_style))
36
+ dwg.add(dwg.text(contact, insert=("10mm", "95mm"), style=text_style))
37
+
38
+ # Generate QR Code
39
+ qr = qrcode.QRCode(
40
+ version=1,
41
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
42
+ box_size=10,
43
+ border=4,
44
+ )
45
+ qr.add_data(name) # You can change this to any data you'd like to encode
46
+ qr.make(fit=True)
47
+ qr_img = qr.make_image(fill_color="black", back_color="white")
48
 
49
+ # Embed QR Code in SVG
50
+ buffer = BytesIO()
51
+ qr_img.save(buffer, format="PNG")
52
+ qr_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
53
+ dwg.add(dwg.image(href=f"data:image/png;base64,{qr_base64}", insert=("150mm", "10mm"), size=("40mm", "40mm")))
54
 
 
55
  svg_output = name.replace(" ", "_").lower() + "_postcard.svg"
56
  dwg.saveas(svg_output)
57
 
58
  return svg_output
59
 
 
 
 
60
  iface = gr.Interface(
61
  fn=create_postcard,
62
  inputs=[
 
68
  gr.Textbox(label="Hours of Operation"),
69
  gr.Textbox(label="Contact Information"),
70
  gr.Textbox(label="Call to Action"),
71
+ gr.Image(label="Upload Logo", type="pil")
 
72
  ],
73
  outputs="file",
74
  title="Makerspace Postcard Creator",
75
  description="Fill out the details to create a postcard for your makerspace."
76
  )
77
 
 
78
  iface.queue().launch()