UMAID1 commited on
Commit
da98648
·
verified ·
1 Parent(s): 9554d01

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -30
app.py CHANGED
@@ -5,15 +5,14 @@ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, Tabl
5
  from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
6
  from reportlab.lib import colors
7
  from reportlab.graphics.shapes import Drawing, Rect, Polygon, String
8
- from reportlab.graphics.barcodes import qr
9
 
10
- # पेज सेटअप
11
  st.set_page_config(page_title="Sabir Battery Service Verification", layout="centered")
12
 
13
- # आपका बिल्कुल सही लाइव स्पेस यूआरएल
14
  LIVE_SPACE_URL = "https://umaid1-newbill12.hf.space"
15
 
16
- # --- 1. लाइव QR वेरिफिकेशन पोर्टल लॉजिक ---
17
  query_params = st.query_params
18
 
19
  if "verify" in query_params:
@@ -25,10 +24,10 @@ if "verify" in query_params:
25
  st.markdown(f"### ⏳ Service Duration: {query_params.get('duration', 'N/A').replace('+', ' ')}")
26
  st.markdown(f"### 📅 Issue Details: {query_params.get('date', 'N/A').replace('+', ' ')}")
27
  st.write("---")
28
- st.info("यह विवरण हमारे आधिकारिक डेटाबेस से लाइव सत्यापित है।")
29
  st.stop()
30
 
31
- # --- 2. मुख्य एडमिन पैनल (सर्टिफिकेट बनाने के लिए) ---
32
  st.title("🏆 Sabir Battery Service")
33
  st.subheader("Secure Certificate & Invoice Generator")
34
  st.write("यहाँ विवरण भरें। आपका सर्टिफिकेट ओरिजिनल डिज़ाइन और लाइव एंटी-फेक क्यूआर कोड के साथ जनरेट होगा।")
@@ -39,7 +38,7 @@ worker_name = st.text_input("वर्कर का पूरा नाम द
39
  working_date_or_duration = st.text_input("वर्कर का कार्यकाल (e.g., Since 2024):")
40
  issue_date = st.text_input("जारी करने की तारीख और जगह (e.g., 10/06/2026, Delhi):")
41
 
42
- # सिग्नेचर फाइल चेक करना
43
  sig_file = "Screenshot_20260609-204241.Files by Google.png"
44
  if not os.path.exists(sig_file):
45
  if os.path.exists("signature.png"):
@@ -53,15 +52,18 @@ if worker_name:
53
  formatted_duration = working_date_or_duration.replace(" ", "+")
54
  formatted_date = issue_date.replace(" ", "+")
55
 
56
- # लाइव स्कैन यूआरएल लिंक
57
  verify_url = f"{LIVE_SPACE_URL}/?verify=true&invoice={invoice_no}&name={formatted_name}&duration={formatted_duration}&date={formatted_date}"
58
 
59
- # --- 3. ReportLab PDF जनरेशन लॉजिक ---
 
 
 
60
  def make_pdf():
61
  from reportlab.lib.io import BytesIO
62
  buffer = BytesIO()
63
 
64
- # पेज साइज: A4 Landscape
65
  doc = SimpleDocTemplate(
66
  buffer,
67
  pagesize=landscape(A4),
@@ -82,25 +84,18 @@ if worker_name:
82
  d.add(Rect(32, 32, 778, 531, fillColor=None, strokeColor=colors.HexColor('#c5a059'), strokeWidth=1))
83
 
84
  # बायीं तरफ का Burgundy और Gold जियोमेट्रिक आर्ट
85
- d.add(Polygon([25, 570, 180, 570, 80, 25, 25, 25], fillColor=colors.HexColor('#4a0710'), strokeColor=None)) # Burgundy
86
- d.add(Polygon([180, 570, 210, 570, 110, 25, 80, 25], fillColor=colors.HexColor('#d4af37'), strokeColor=None)) # Gold
87
- d.add(Polygon([25, 300, 120, 180, 25, 60], fillColor=colors.HexColor('#111111'), strokeColor=None)) # Dark Grey
88
 
89
  # वाटरमार्क टेक्स्ट
90
  d.add(String(480, 260, "SABIR BATTERY SERVICE", fontSize=42, fontName="Helvetica-Bold", fillColor=colors.HexColor('#f3ece0'), textAnchor="middle"))
91
 
92
- # --- लाइव एंटी-फेक क्यूआर कोड जोड़ना ---
93
- qr_code = qr.QrCodeWidget(verify_url)
94
- qr_code.barWidth = 85
95
- qr_code.barHeight = 85
96
- qr_code.x = 45
97
- qr_code.y = 75
98
- d.add(qr_code)
99
-
100
  d.add(String(87, 58, "SCAN TO VERIFY", fontSize=8, fontName="Helvetica-Bold", fillColor=colors.HexColor('#111111'), textAnchor="middle"))
101
 
102
  story.append(d)
103
- story.append(Spacer(1, -550)) # कंटेंट को वापस ऊपर सेट करने के लिए
104
 
105
  # --- टेक्स्ट स्टाइल्स ---
106
  styles = getSampleStyleSheet()
@@ -113,7 +108,7 @@ if worker_name:
113
  style_name = ParagraphStyle('Name', fontName='Times-Bold', fontSize=28, textColor=colors.HexColor('#6b0f1a'), alignment=1, leftIndent=120, spaceBefore=5)
114
  style_body = ParagraphStyle('Body', fontName='Helvetica', fontSize=10, textColor=colors.HexColor('#222222'), alignment=1, leftIndent=140, rightIndent=40, spaceBefore=15, leading=16)
115
 
116
- # --- कंटेंट जोड़ना (यहाँ गलती बिल्कुल ठीक कर दी गई है!) ---
117
  story.append(Paragraph(f"INVOICE NO: {invoice_no}", style_invoice))
118
  story.append(Spacer(1, 15))
119
 
@@ -125,10 +120,11 @@ if worker_name:
125
  story.append(Paragraph("This certificate is proudly presented to", style_present))
126
  story.append(Paragraph(f"Mr. {worker_name}", style_name))
127
 
128
- details = f"Who has successfully demonstrated master-level technical expertise in <b>Inverter Board Repairing, Solar Power Systems Fitting, Commercial Electrical Wiring,</b> and Digital IT Operations. His outstanding dedication and professional service during his tenure (<b>{working_date_or_duration}</b>) are highly appreciated."
129
  story.append(Paragraph(details, style_body))
130
- story.append(Spacer(1, 40))
131
 
 
132
  from reportlab.platypus import Image
133
 
134
  if sig_file:
@@ -136,18 +132,24 @@ if worker_name:
136
  else:
137
  sig_img = Paragraph("<b>Gulam Sabir</b>", ParagraphStyle('SigText', fontName='Times-BoldItalic', fontSize=14, textColor=colors.HexColor('#4a0710'), alignment=1))
138
 
 
 
 
 
 
139
  footer_data = [
140
- [Paragraph(f"<b>{issue_date}</b>", ParagraphStyle('F1', fontName='Helvetica-Bold', fontSize=10, alignment=1)), sig_img],
141
- [Paragraph("<font color='#888888'>_______________________</font>", ParagraphStyle('Line', alignment=1)), Paragraph("<font color='#888888'>_______________________</font>", ParagraphStyle('Line', alignment=1))],
142
- [Paragraph("DATE & PLACE", ParagraphStyle('L1', fontName='Helvetica', fontSize=8, textColor=colors.HexColor('#444444'), alignment=1)),
143
  Paragraph("SHOP OWNER / PROPRIETOR", ParagraphStyle('L2', fontName='Helvetica-Bold', fontSize=8, textColor=colors.HexColor('#4a0710'), alignment=1))]
144
  ]
145
 
146
- footer_table = Table(footer_data, colWidths=[180, 180], hAlign='RIGHT')
147
  footer_table.setStyle(TableStyle([
148
  ('VALIGN', (0,0), (-1,-1), 'BOTTOM'),
149
  ('BOTTOMPADDING', (0,0), (-1,-1), 2),
150
- ('RIGHTPADDING', (1,0), (1,-1), 40)
 
151
  ]))
152
 
153
  story.append(footer_table)
@@ -167,3 +169,4 @@ if worker_name:
167
  )
168
  else:
169
  st.warning("⚠️ डाउनलोड बटन और क्यूआर कोड चालू करने के लिए वर्कर का नाम डालें।")
 
 
5
  from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
6
  from reportlab.lib import colors
7
  from reportlab.graphics.shapes import Drawing, Rect, Polygon, String
 
8
 
9
+ # 1. पेज सेटअप - Streamlit UI Configuration
10
  st.set_page_config(page_title="Sabir Battery Service Verification", layout="centered")
11
 
12
+ # आपका बिल्कुल सही लाइव स्पेस यूआरएल जो क्यूआर कोड स्कैनिंग के काम आएगा
13
  LIVE_SPACE_URL = "https://umaid1-newbill12.hf.space"
14
 
15
+ # --- 2. लाइव QR वेरिफिकेशन पोर्टल लॉजिक (एंटी-फेक सिस्टम) ---
16
  query_params = st.query_params
17
 
18
  if "verify" in query_params:
 
24
  st.markdown(f"### ⏳ Service Duration: {query_params.get('duration', 'N/A').replace('+', ' ')}")
25
  st.markdown(f"### 📅 Issue Details: {query_params.get('date', 'N/A').replace('+', ' ')}")
26
  st.write("---")
27
+ st.info("यह विवरण हमारे आधिकारिक डेटाबेस से लाइव सत्यापित है। कोई भी बदलाव अनधिकृत माना जाएगा।")
28
  st.stop()
29
 
30
+ # --- 3. मुख्य एडमिन पैनल (सर्टिफिकेट बनाने के लिए) ---
31
  st.title("🏆 Sabir Battery Service")
32
  st.subheader("Secure Certificate & Invoice Generator")
33
  st.write("यहाँ विवरण भरें। आपका सर्टिफिकेट ओरिजिनल डिज़ाइन और लाइव एंटी-फेक क्यूआर कोड के साथ जनरेट होगा।")
 
38
  working_date_or_duration = st.text_input("वर्कर का कार्यकाल (e.g., Since 2024):")
39
  issue_date = st.text_input("जारी करने की तारीख और जगह (e.g., 10/06/2026, Delhi):")
40
 
41
+ # सिग्नेचर फाइल पाथ चेक करना
42
  sig_file = "Screenshot_20260609-204241.Files by Google.png"
43
  if not os.path.exists(sig_file):
44
  if os.path.exists("signature.png"):
 
52
  formatted_duration = working_date_or_duration.replace(" ", "+")
53
  formatted_date = issue_date.replace(" ", "+")
54
 
55
+ # लाइव स्कैन यूआरएल लिंक जो मोबाइल कैमरे से खुलेगा
56
  verify_url = f"{LIVE_SPACE_URL}/?verify=true&invoice={invoice_no}&name={formatted_name}&duration={formatted_duration}&date={formatted_date}"
57
 
58
+ # बिना किसी एक्स्ट्रा लाइब्रेरी के डायरेक्ट क्यूआर कोड इमेज जनरेट करने का सबसे सुरक्षित तरीका
59
+ qr_api_url = f"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data={verify_url}&color=4a0710&bgcolor=fcf9f2"
60
+
61
+ # --- 4. ReportLab PDF जनरेशन लॉजिक ---
62
  def make_pdf():
63
  from reportlab.lib.io import BytesIO
64
  buffer = BytesIO()
65
 
66
+ # पेज साइज: A4 Landscape (297mm x 210mm)
67
  doc = SimpleDocTemplate(
68
  buffer,
69
  pagesize=landscape(A4),
 
84
  d.add(Rect(32, 32, 778, 531, fillColor=None, strokeColor=colors.HexColor('#c5a059'), strokeWidth=1))
85
 
86
  # बायीं तरफ का Burgundy और Gold जियोमेट्रिक आर्ट
87
+ d.add(Polygon([25, 570, 180, 570, 80, 25, 25, 25], fillColor=colors.HexColor('#4a0710'), strokeColor=None))
88
+ d.add(Polygon([180, 570, 210, 570, 110, 25, 80, 25], fillColor=colors.HexColor('#d4af37'), strokeColor=None))
89
+ d.add(Polygon([25, 300, 120, 180, 25, 60], fillColor=colors.HexColor('#111111'), strokeColor=None))
90
 
91
  # वाटरमार्क टेक्स्ट
92
  d.add(String(480, 260, "SABIR BATTERY SERVICE", fontSize=42, fontName="Helvetica-Bold", fillColor=colors.HexColor('#f3ece0'), textAnchor="middle"))
93
 
94
+ # क्यूआर कोड के नीचे गाइड टेक्स्ट
 
 
 
 
 
 
 
95
  d.add(String(87, 58, "SCAN TO VERIFY", fontSize=8, fontName="Helvetica-Bold", fillColor=colors.HexColor('#111111'), textAnchor="middle"))
96
 
97
  story.append(d)
98
+ story.append(Spacer(1, -550)) # कंटेंट को वापस ऊपर अलाइन करने के लिए
99
 
100
  # --- टेक्स्ट स्टाइल्स ---
101
  styles = getSampleStyleSheet()
 
108
  style_name = ParagraphStyle('Name', fontName='Times-Bold', fontSize=28, textColor=colors.HexColor('#6b0f1a'), alignment=1, leftIndent=120, spaceBefore=5)
109
  style_body = ParagraphStyle('Body', fontName='Helvetica', fontSize=10, textColor=colors.HexColor('#222222'), alignment=1, leftIndent=140, rightIndent=40, spaceBefore=15, leading=16)
110
 
111
+ # --- कंटेंट जोड़ना ---
112
  story.append(Paragraph(f"INVOICE NO: {invoice_no}", style_invoice))
113
  story.append(Spacer(1, 15))
114
 
 
120
  story.append(Paragraph("This certificate is proudly presented to", style_present))
121
  story.append(Paragraph(f"Mr. {worker_name}", style_name))
122
 
123
+ details = f"Who has successfully demonstrated master-level technical expertise in <b>Inverter Board Repairing Master</b> (diagnosing complex motherboard faults of brands like Exide, Luminous, Microtek), <b>Solar & Power Systems</b> (Solar Panel Fitting and Inverter-Battery Installation), <b>Electrical Wiring</b> (commercial and domestic wiring), and <b>Digital & IT Operations</b> (CSC Center services and laptop troubleshooting). His swift problem-solving ability, disciplined work ethic, and polite customer handling are highly commendable during his tenure (<b>{working_date_or_duration}</b>)."
124
  story.append(Paragraph(details, style_body))
125
+ story.append(Spacer(1, 45))
126
 
127
+ # नीचे तारीख, क्यूआर कोड और हस्ताक्षर अरेंज करना
128
  from reportlab.platypus import Image
129
 
130
  if sig_file:
 
132
  else:
133
  sig_img = Paragraph("<b>Gulam Sabir</b>", ParagraphStyle('SigText', fontName='Times-BoldItalic', fontSize=14, textColor=colors.HexColor('#4a0710'), alignment=1))
134
 
135
+ try:
136
+ qr_img = Image(qr_api_url, width=85, height=85)
137
+ except:
138
+ qr_img = Paragraph("[QR Code]", ParagraphStyle('QRErr'))
139
+
140
  footer_data = [
141
+ [qr_img, Paragraph(f"<b>{issue_date}</b>", ParagraphStyle('F1', fontName='Helvetica-Bold', fontSize=10, alignment=1)), sig_img],
142
+ ['', Paragraph("<font color='#888888'>_______________________</font>", ParagraphStyle('Line', alignment=1)), Paragraph("<font color='#888888'>_______________________</font>", ParagraphStyle('Line', alignment=1))],
143
+ ['', Paragraph("DATE & PLACE", ParagraphStyle('L1', fontName='Helvetica', fontSize=8, textColor=colors.HexColor('#444444'), alignment=1)),
144
  Paragraph("SHOP OWNER / PROPRIETOR", ParagraphStyle('L2', fontName='Helvetica-Bold', fontSize=8, textColor=colors.HexColor('#4a0710'), alignment=1))]
145
  ]
146
 
147
+ footer_table = Table(footer_data, colWidths=[140, 180, 180], hAlign='LEFT')
148
  footer_table.setStyle(TableStyle([
149
  ('VALIGN', (0,0), (-1,-1), 'BOTTOM'),
150
  ('BOTTOMPADDING', (0,0), (-1,-1), 2),
151
+ ('LEFTPADDING', (0,0), (0,-1), 45),
152
+ ('BOTTOMPADDING', (0,0), (0,0), 10), # QR कोड अलाइनमेंट सेटिंग्स
153
  ]))
154
 
155
  story.append(footer_table)
 
169
  )
170
  else:
171
  st.warning("⚠️ डाउनलोड बटन और क्यूआर कोड चालू करने के लिए वर्कर का नाम डालें।")
172
+