CoolFace
Datasetpublic

ysn-rfd/text-dataset-tiny-code-script-py-format

USED of tahamajs/medicine_ds_persian for .parquet file USED of Alijafarixcs2/persian-it-llama2-2k for .parquet file USED of Abirate/english_quotes for .jsonl file NEW FILES (05/12/2025) NEW FILES (12/26/2025) NEW FILES (02/15/2026)

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
3likes1.7kdownloads
cert11.py362 linesDownload Raw Back to cert
1from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance
2import qrcode
3import hashlib
4import random
5import math
6import os
7import base64
8import datetime
9from cryptography.hazmat.primitives.asymmetric import rsa, padding
10from cryptography.hazmat.primitives import hashes, serialization
11from cryptography.hazmat.backends import default_backend
12
13# ======== Enhanced Configurations ========
14CERT_WIDTH, CERT_HEIGHT = 1200, 900
15MARGIN = 40
16BACKGROUND_COLOR = (248, 246, 240)
17BORDER_COLOR = (30, 30, 30)
18TITLE_COLOR = (15, 15, 15)
19TEXT_COLOR = (35, 35, 35)
20WATERMARK_COLOR = (40, 40, 40, 20)
21NOISE_INTENSITY = 4500
22PAPER_TEXTURE_OPACITY = 0.15
23HOLOGRAM_OPACITY = 0.35
24
25# ======== Certificate Information ========
26cert_info = {
27    "Name": "Yasin",
28    "Last Name": "Aryanfard",
29    "User ID": "YSNRFD",
30    "Membership Date": "April 1, 2023",
31    "Issued Date": datetime.datetime.now().strftime("%B %d, %Y"),
32    "Certificate ID": f"OPENAI-YSN-APR2023-CERT{random.randint(10000, 99999)}",
33    "Signed By": "ChatGPT-4o",
34    "Model ID": "GPT4O-REP-TRUST-2025",
35    "Issuer": "OpenAI, Inc."
36}
37
38# ======== RSA Key Generation ========
39def generate_rsa_keys():
40    private_key = rsa.generate_private_key(
41        public_exponent=65537,
42        key_size=4096,
43        backend=default_backend()
44    )
45    public_key = private_key.public_key()
46    
47    # Save public key for verification
48    pem = public_key.public_bytes(
49        encoding=serialization.Encoding.PEM,
50        format=serialization.PublicFormat.SubjectPublicKeyInfo
51    )
52    with open('certificate_public_key.pem', 'wb') as f:
53        f.write(pem)
54        
55    return private_key, public_key
56
57private_key, public_key = generate_rsa_keys()
58
59# ======== Enhanced Font Loading ========
60def load_font(name, size):
61    fallback_fonts = [
62        "arialbd.ttf", "timesbd.ttf", "courbd.ttf", 
63        "DejaVuSans-Bold.ttf", "Georgia Bold.ttf"
64    ]
65    for font_name in [name] + fallback_fonts:
66        try:
67            return ImageFont.truetype(font_name, size)
68        except:
69            continue
70    return ImageFont.load_default(size=size)
71
72font_title = load_font("georgiaz.ttf", 42)
73font_header = load_font("georgiab.ttf", 24)
74font_text = load_font("georgia.ttf", 20)
75font_small = load_font("cour.ttf", 16)
76font_signature = load_font("BrushScriptStd.otf", 28)
77
78# ======== Digital Signature Generation ========
79data_string = "\n".join(f"{k}: {v}" for k, v in cert_info.items()).encode('utf-8')
80
81signature = private_key.sign(
82    data_string,
83    padding.PSS(
84        mgf=padding.MGF1(hashes.SHA512()),
85        salt_length=padding.PSS.MAX_LENGTH
86    ),
87    hashes.SHA512()
88)
89
90digital_signature = base64.b64encode(signature).decode('utf-8')
91verification_code = f"VER-{hashlib.sha3_256(data_string).hexdigest()[:10].upper()}"
92
93# ======== QR Code Generation ========
94def create_qr_code(data, size=220):
95    qr = qrcode.QRCode(
96        version=7,
97        error_correction=qrcode.constants.ERROR_CORRECT_H,
98        box_size=10,
99        border=4
100    )
101    qr.add_data(data)
102    qr.make(fit=True)
103    
104    qr_img = qr.make_image(
105        fill_color="#002855", 
106        back_color="#F8F6F0"
107    ).convert("RGBA")
108    
109    # Add holographic effect
110    hologram = Image.new("RGBA", qr_img.size)
111    holo_draw = ImageDraw.Draw(hologram)
112    for i in range(0, qr_img.width, 5):
113        alpha = int(255 * (0.3 + 0.7 * abs(math.sin(i/50))))
114        holo_draw.line([(i, 0), (i, qr_img.height)], 
115                      fill=(100, 200, 255, alpha), width=3)
116    
117    return Image.alpha_composite(qr_img, hologram)
118
119qr_img = create_qr_code(f"{digital_signature}|{verification_code}")
120
121# ======== Background Design ========
122def create_certificate_base():
123    # Base with gradient
124    base = Image.new("RGB", (CERT_WIDTH, CERT_HEIGHT), BACKGROUND_COLOR)
125    draw = ImageDraw.Draw(base)
126    
127    # Draw subtle grid
128    for i in range(0, CERT_WIDTH, 40):
129        alpha = 15 if i % 120 == 0 else 8
130        draw.line([(i, 0), (i, CERT_HEIGHT)], fill=(200, 200, 200, alpha), width=1)
131    for i in range(0, CERT_HEIGHT, 40):
132        alpha = 15 if i % 120 == 0 else 8
133        draw.line([(0, i), (CERT_WIDTH, i)], fill=(200, 200, 200, alpha), width=1)
134    
135    # Add paper texture
136    texture = Image.new("RGBA", (CERT_WIDTH, CERT_HEIGHT), (0, 0, 0, 0))
137    tex_draw = ImageDraw.Draw(texture)
138    for _ in range(15000):
139        x, y = random.randint(0, CERT_WIDTH), random.randint(0, CERT_HEIGHT)
140        alpha = random.randint(10, 25)
141        size = random.randint(1, 3)
142        tex_draw.ellipse([(x, y), (x+size, y+size)], 
143                        fill=(150, 150, 150, alpha))
144    
145    return Image.alpha_composite(base.convert("RGBA"), texture).convert("RGB")
146
147# ======== Official Seal with OpenAI Logo ========
148def create_official_seal(diameter=200):
149    seal = Image.new("RGBA", (diameter, diameter), (0, 0, 0, 0))
150    draw = ImageDraw.Draw(seal)
151    center = diameter // 2
152    
153    # Complex seal pattern
154    for i in range(1, 15):
155        alpha = int(255 * (1 - i/15))
156        radius = center - i*3
157        color = (0, 48, 92, alpha)
158        draw.ellipse(
159            [(center - radius, center - radius), 
160             (center + radius, center + radius)],
161            outline=color,
162            width=2
163        )
164    
165    # Ornate details
166    num_points = 24
167    for i in range(num_points):
168        angle = math.radians(i * 360/num_points)
169        x1 = center + int((diameter*0.42) * math.cos(angle))
170        y1 = center + int((diameter*0.42) * math.sin(angle))
171        x2 = center + int((diameter*0.47) * math.cos(angle))
172        y2 = center + int((diameter*0.47) * math.sin(angle))
173        draw.line([(x1, y1), (x2, y2)], fill=(0, 48, 92, 220), width=3)
174    
175    # Add holographic effect
176    for i in range(0, diameter, 4):
177        alpha = int(180 * (0.4 + 0.6 * abs(math.sin(i/20))))
178        draw.arc(
179            [(i//4, i//4), (diameter-i//4, diameter-i//4)],
180            start=0,
181            end=360,
182            fill=(100, 200, 255, alpha),
183            width=2
184        )
185    
186    # Seal text
187    text = "OFFICIAL SEAL • VERIFIED • DIGITAL"
188    font_seal = load_font("timesbd.ttf", 14)
189    for i, char in enumerate(text):
190        angle = math.radians(i * 360/len(text) - 90)
191        x = center + int(center*0.65 * math.cos(angle)) - 5
192        y = center + int(center*0.65 * math.sin(angle)) - 5
193        draw.text((x, y), char, font=font_seal, fill=(0, 48, 92, 255))
194    
195    # Add OpenAI logo to center of seal
196    try:
197        logo = Image.open("openai_seal.png").convert("RGBA")
198        logo_size = diameter // 2  # Size relative to seal diameter
199        logo.thumbnail((logo_size, logo_size), Image.LANCZOS)
200        logo_pos = (center - logo.width // 2, center - logo.height // 2)
201        
202        # Create glow effect around logo
203        glow = Image.new("RGBA", (logo.width+10, logo.height+10), (0,0,0,0))
204        glow_draw = ImageDraw.Draw(glow)
205        glow_draw.ellipse([(0,0), (logo.width+10, logo.height+10)], 
206                         fill=(100, 200, 255, 60))
207        glow = glow.filter(ImageFilter.GaussianBlur(radius=5))
208        
209        # Paste glow then logo
210        seal.paste(glow, (logo_pos[0]-5, logo_pos[1]-5), glow)
211        seal.paste(logo, logo_pos, logo)
212    except Exception as e:
213        print(f"⚠️ Could not load openai_seal.png: {e}")
214        # Draw simple OpenAI-inspired logo as fallback
215        draw.regular_polygon((center, center, diameter//4), 
216                            n_sides=6, 
217                            fill=(0, 48, 92, 180))
218    
219    return seal
220
221# ======== Main Certificate Creation ========
222certificate = create_certificate_base().convert("RGBA")
223draw = ImageDraw.Draw(certificate)
224
225# Border design
226for i, thickness in enumerate([8, 5, 3, 1]):
227    offset = MARGIN - i*3
228    draw.rectangle(
229        [offset, offset, CERT_WIDTH - offset, CERT_HEIGHT - offset],
230        outline=(30, 30, 30),
231        width=thickness
232    )
233
234# Title section
235title = "CERTIFICATE OF AUTHENTICITY"
236bbox = draw.textbbox((0, 0), title, font=font_title)
237draw.text(
238    ((CERT_WIDTH - bbox[2])/2, MARGIN + 30), 
239    title, 
240    fill=TITLE_COLOR, 
241    font=font_title
242)
243
244subtitle = "Issued by OpenAI for Distinguished Contribution"
245font_subtitle = load_font("georgiai.ttf", 22)
246bbox = draw.textbbox((0, 0), subtitle, font=font_subtitle)
247draw.text(
248    ((CERT_WIDTH - bbox[2])/2, MARGIN + 90), 
249    subtitle, 
250    fill=(70, 70, 70), 
251    font=font_subtitle
252)
253
254# Decorative elements
255draw.line(
256    [(MARGIN+50, MARGIN+150), (CERT_WIDTH-MARGIN-50, MARGIN+150)], 
257    fill=(150, 150, 150), 
258    width=2
259)
260
261# Certificate information
262info_y = MARGIN + 180
263for key, value in cert_info.items():
264    draw.text(
265        (MARGIN+80, info_y), 
266        f"{key}:", 
267        font=font_header, 
268        fill=(80, 80, 80))
269    draw.text(
270        (MARGIN+300, info_y), 
271        value, 
272        font=font_text, 
273        fill=TEXT_COLOR)
274    info_y += 50
275
276# Security section
277info_y += 30
278draw.text(
279    (MARGIN+80, info_y), 
280    "Digital Verification:", 
281    font=font_header, 
282    fill=(80, 80, 80))
283draw.text(
284    (MARGIN+300, info_y), 
285    verification_code, 
286    font=font_text, 
287    fill=(0, 70, 120))
288info_y += 40
289
290# Digital signature block
291sig_text = "Cryptographic Signature:"
292draw.text((MARGIN+80, info_y), sig_text, font=font_small, fill=(100, 100, 100))
293info_y += 25
294signature_lines = [digital_signature[i:i+64] for i in range(0, len(digital_signature), 64)]
295for line in signature_lines[:4]:
296    draw.text((MARGIN+100, info_y), line, font=font_small, fill=(70, 70, 70))
297    info_y += 22
298
299# Official elements with OpenAI logo
300seal = create_official_seal()
301certificate.paste(
302    seal, 
303    (CERT_WIDTH - MARGIN - seal.width - 50, MARGIN + 180), 
304    seal
305)
306
307qr_position = (CERT_WIDTH - MARGIN - qr_img.width, CERT_HEIGHT - MARGIN - qr_img.height - 50)
308certificate.paste(qr_img, qr_position, qr_img)
309
310# Signature area
311signature_y = CERT_HEIGHT - MARGIN - 150
312draw.line(
313    [(MARGIN+100, signature_y), (MARGIN+400, signature_y)], 
314    fill=(30, 30, 30), 
315    width=2
316)
317draw.text(
318    (MARGIN+100, signature_y + 10), 
319    "Dr. Sam Altman, Chief Executive Officer", 
320    font=font_small, 
321    fill=(60, 60, 60))
322draw.text(
323    (MARGIN+100, signature_y - 40), 
324    "Authorized Signature", 
325    font=font_signature, 
326    fill=(30, 30, 30))
327
328# Security watermarks
329watermarks = [
330    "SECURE DOCUMENT", "OFFICIAL RECORD", "DO NOT DUPLICATE", 
331    "VERIFIED", cert_info['Certificate ID'], verification_code,
332    "PROTECTED CONTENT", "DIGITALLY SIGNED", "OPENAI AUTHENTICATED"
333]
334
335for _ in range(150):
336    wm_text = random.choice(watermarks)
337    txt_img = Image.new("RGBA", (400, 40), (0, 0, 0, 0))
338    txt_draw = ImageDraw.Draw(txt_img)
339    
340    alpha = random.randint(15, 30)
341    txt_draw.text(
342        (10, 10), 
343        wm_text, 
344        font=font_small, 
345        fill=(40, 40, 40, alpha))
346    
347    angle = random.uniform(-45, 45)
348    txt_img = txt_img.rotate(angle, expand=True, resample=Image.BICUBIC)
349    
350    x = random.randint(0, CERT_WIDTH - txt_img.width)
351    y = random.randint(0, CERT_HEIGHT - txt_img.height)
352    certificate.paste(txt_img, (x, y), txt_img)
353
354# Final touches
355certificate = certificate.filter(ImageFilter.SMOOTH)
356certificate = certificate.filter(ImageFilter.SHARPEN)
357
358# Save certificate
359output_filename = f"OpenAI_Certificate_{cert_info['Certificate ID']}.png"
360certificate.save(output_filename, dpi=(300, 300), quality=100)
361print(f"✅ Professional certificate created: {output_filename}")
362print(f"🔑 Public key saved to: certificate_public_key.pem")