Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import qrcode
|
3 |
+
from unidecode import unidecode
|
4 |
+
from PIL import Image
|
5 |
+
import base64
|
6 |
+
import io
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
#inputs
|
13 |
+
name = st.text_input("Ad", key="name")
|
14 |
+
last_name = st.text_input("Soyad", key="last_name")
|
15 |
+
title = st.text_input("Ünvan", key="title")
|
16 |
+
e_mail = st.text_input("E-posta adresi", key="email")
|
17 |
+
e_mail2 = st.text_input("E-posta adresi2", key="email2")
|
18 |
+
tel = st.text_input("Telefon", key="tel")
|
19 |
+
mobile = st.text_input("Mobil Telefon", key="mobile")
|
20 |
+
home_address = st.text_input("Ev adresi", key="home_address")
|
21 |
+
work_address = st.text_input("İş adresi", key="work_address")
|
22 |
+
organisation = st.text_input("İşyeri Adı", key="organisation")
|
23 |
+
website = st.text_input("Websitesi", key="website")
|
24 |
+
|
25 |
+
def generate_qr_code(data):
|
26 |
+
# Create the vCard text as a string
|
27 |
+
vcard_template = """BEGIN:VCARD;CHARSET=iso-8859-1
|
28 |
+
VERSION:4.0
|
29 |
+
N:{last_name};{name}
|
30 |
+
FN:{name} {last_name}
|
31 |
+
ORG:{organisation}
|
32 |
+
TITLE: {title}
|
33 |
+
EMAIL;PREF=1;TYPE=INTERNET:{email}
|
34 |
+
EMAIL:{email2}
|
35 |
+
TEL;TYPE#work,voice;VALUE#uri:tel:{tel}
|
36 |
+
TEL;TYPE#mobile,voice;VALUE#uri:tel:{mobile}
|
37 |
+
ADR;TYPE#WORK;PREF#1: {work_address}
|
38 |
+
ADR;TYPE#HOME: {home_address}
|
39 |
+
URL:{website}
|
40 |
+
END:VCARD"""
|
41 |
+
|
42 |
+
# Format the vCard text with the variables from the data dictionary
|
43 |
+
vcard_text = vcard_template.format(**data)
|
44 |
+
|
45 |
+
# Create the QR code image
|
46 |
+
qr_img = qrcode.make(vcard_text, box_size=10)
|
47 |
+
|
48 |
+
# Convert the QR code image to a bytes-like object
|
49 |
+
img_bytes = io.BytesIO()
|
50 |
+
qr_img.save(img_bytes, format='PNG')
|
51 |
+
img_bytes.seek(0)
|
52 |
+
|
53 |
+
# Create the PIL Image object
|
54 |
+
pil_img = Image.open(img_bytes)
|
55 |
+
|
56 |
+
return pil_img
|
57 |
+
|
58 |
+
|
59 |
+
# Add a "Generate QR Code" button
|
60 |
+
if st.button("Dijital Kartvizit Oluşturun"):
|
61 |
+
# Create the data dictionary
|
62 |
+
data = {
|
63 |
+
"name": name,
|
64 |
+
"last_name": last_name,
|
65 |
+
"email": e_mail,
|
66 |
+
"email2": e_mail2,
|
67 |
+
"tel": tel,
|
68 |
+
"mobile": mobile,
|
69 |
+
"home_address": home_address,
|
70 |
+
"work_address": work_address,
|
71 |
+
"organisation": organisation,
|
72 |
+
"website": website,
|
73 |
+
"title": title
|
74 |
+
}
|
75 |
+
# Generate the QR code image
|
76 |
+
img = generate_qr_code(data)
|
77 |
+
# Display the QR code image
|
78 |
+
st.image(img)
|
79 |
+
|
80 |
+
# Convert the image to bytes
|
81 |
+
img_bytes = io.BytesIO()
|
82 |
+
img.save(img_bytes, format='PNG')
|
83 |
+
# Add a download button for the image
|
84 |
+
st.download_button(
|
85 |
+
label=" ⬇️ VR Kodunu İndirin",
|
86 |
+
data=img_bytes.getvalue(),
|
87 |
+
file_name="qrcode.png",
|
88 |
+
mime="image/png"
|
89 |
+
)
|
90 |
+
|
91 |
+
# Convert the name to Latin characters using the unidecode function
|
92 |
+
file_name = unidecode(name)
|
93 |
+
|
94 |
+
# Make the file name all lowercase
|
95 |
+
file_name = file_name.lower()
|
96 |
+
|
97 |
+
# Replace any spaces with underscores
|
98 |
+
file_name = file_name.replace(' ', '_')
|
99 |
+
|
100 |
+
# Add the .png extension to the file name
|
101 |
+
file_name = f'{file_name}_vcard.png'
|
102 |
+
|
103 |
+
# Save the QR code image to a file
|
104 |
+
#with open(file_name, 'wb') as f:
|
105 |
+
#img.save(f)
|