LovnishVerma commited on
Commit
2d79d8b
·
verified ·
1 Parent(s): 5c19ee1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -56
app.py CHANGED
@@ -251,40 +251,46 @@ Click "Generate Report" to download your detailed results!""", True
251
  )
252
 
253
  # Header with candidate photo
254
- from reportlab.platypus import Image
255
- header_data = []
256
-
257
- if photo_path and os.path.exists(photo_path):
258
- try:
259
- # Create header table with photo
260
- photo_img = Image(photo_path, width=60, height=60)
261
- header_info = [
262
- "CCC Plus - Computer Concepts Plus",
263
- "Quiz Assessment Report",
264
- f"Candidate: {self.user_name}",
265
- datetime.now().strftime('%d %B %Y at %H:%M:%S')
266
- ]
267
-
268
- header_table = Table([
269
- [photo_img, Paragraph("<br/>".join(header_info), styles['Normal'])]
270
- ], colWidths=[80, 400])
271
-
272
- header_table.setStyle(TableStyle([
273
- ('ALIGN', (0, 0), (0, 0), 'CENTER'),
274
- ('VALIGN', (0, 0), (-1, -1), 'TOP'),
275
- ('FONTSIZE', (1, 0), (1, 0), 12),
276
- ('BOTTOMPADDING', (0, 0), (-1, -1), 12),
277
- ]))
278
-
279
- story.append(header_table)
280
-
281
- except Exception as e:
282
- logger.warning(f"Could not add photo to PDF: {e}")
283
- # Fallback to text header
 
 
 
 
 
284
  story.append(Paragraph("CCC Plus - Computer Concepts Plus", title_style))
285
  story.append(Paragraph("Quiz Assessment Report", subtitle_style))
286
- else:
287
- # Text-only header
 
288
  story.append(Paragraph("CCC Plus - Computer Concepts Plus", title_style))
289
  story.append(Paragraph("Quiz Assessment Report", subtitle_style))
290
 
@@ -601,32 +607,35 @@ def create_app():
601
  border: 1px solid #e9ecef;
602
  margin-top: 20px;
603
  }
 
604
  /* Logo */
605
- #logo-img img {
606
- max-height: 70px;
607
- width: auto;
608
- border-radius: 8px;
609
- }
610
  """
611
 
612
  with gr.Blocks(title="CCC Plus Quiz App", css=custom_css, theme=gr.themes.Soft()) as app:
613
- with gr.Row(elem_classes="quiz-header"):
614
- with gr.Column(scale=1):
615
- logo_img = gr.Image(
616
- value="nielit_logo.png" if os.path.exists("nielit_logo.png") else None,
617
- elem_id="logo-img",
618
- interactive=False,
619
- show_label=False
620
- )
621
- with gr.Column(scale=6):
622
- gr.HTML("""
623
- <div class="quiz-header-text">
624
- <h1>🖥️ CCC Plus Quiz App</h1>
625
- <p>Computer Concepts Plus - Interactive Quiz Platform</p>
626
- <p>NIELIT Chandigarh National Institute of Electronics & Information Technology</p>
627
- </div>
628
- """)
629
-
 
 
630
  with gr.Row():
631
  # Left Panel - Controls
632
  with gr.Column(scale=1, elem_classes="control-panel"):
@@ -778,5 +787,4 @@ if __name__ == "__main__":
778
  app.launch(share=True, show_error=True)
779
 
780
  # For production use:
781
- # exit(main())
782
-
 
251
  )
252
 
253
  # Header with candidate photo
254
+ try:
255
+ from reportlab.platypus import Image
256
+ header_data = []
257
+
258
+ if photo_path and os.path.exists(photo_path):
259
+ try:
260
+ # Create header table with photo
261
+ photo_img = Image(photo_path, width=60, height=60)
262
+ header_info = [
263
+ "CCC Plus - Computer Concepts Plus",
264
+ "Quiz Assessment Report",
265
+ f"Candidate: {self.user_name}",
266
+ datetime.now().strftime('%d %B %Y at %H:%M:%S')
267
+ ]
268
+
269
+ header_table = Table([
270
+ [photo_img, Paragraph("<br/>".join(header_info), styles['Normal'])]
271
+ ], colWidths=[80, 400])
272
+
273
+ header_table.setStyle(TableStyle([
274
+ ('ALIGN', (0, 0), (0, 0), 'CENTER'),
275
+ ('VALIGN', (0, 0), (-1, -1), 'TOP'),
276
+ ('FONTSIZE', (1, 0), (1, 0), 12),
277
+ ('BOTTOMPADDING', (0, 0), (-1, -1), 12),
278
+ ]))
279
+
280
+ story.append(header_table)
281
+
282
+ except Exception as e:
283
+ logger.warning(f"Could not add photo to PDF: {e}")
284
+ # Fallback to text header
285
+ story.append(Paragraph("CCC Plus - Computer Concepts Plus", title_style))
286
+ story.append(Paragraph("Quiz Assessment Report", subtitle_style))
287
+ else:
288
+ # Text-only header
289
  story.append(Paragraph("CCC Plus - Computer Concepts Plus", title_style))
290
  story.append(Paragraph("Quiz Assessment Report", subtitle_style))
291
+
292
+ except ImportError:
293
+ # If reportlab Image is not available, use text header
294
  story.append(Paragraph("CCC Plus - Computer Concepts Plus", title_style))
295
  story.append(Paragraph("Quiz Assessment Report", subtitle_style))
296
 
 
607
  border: 1px solid #e9ecef;
608
  margin-top: 20px;
609
  }
610
+
611
  /* Logo */
612
+ #logo-img img {
613
+ max-height: 70px;
614
+ width: auto;
615
+ border-radius: 8px;
616
+ }
617
  """
618
 
619
  with gr.Blocks(title="CCC Plus Quiz App", css=custom_css, theme=gr.themes.Soft()) as app:
620
+ with gr.Row(elem_classes="quiz-header"):
621
+ with gr.Column(scale=1):
622
+ # Check if logo exists before trying to load it
623
+ logo_path = "nielit_logo.png" if os.path.exists("nielit_logo.png") else None
624
+ logo_img = gr.Image(
625
+ value=logo_path,
626
+ elem_id="logo-img",
627
+ interactive=False,
628
+ show_label=False
629
+ )
630
+ with gr.Column(scale=6):
631
+ gr.HTML("""
632
+ <div class="quiz-header-text">
633
+ <h1>🖥️ CCC Plus Quiz App</h1>
634
+ <p>Computer Concepts Plus - Interactive Quiz Platform</p>
635
+ <p>NIELIT Chandigarh • National Institute of Electronics & Information Technology</p>
636
+ </div>
637
+ """)
638
+
639
  with gr.Row():
640
  # Left Panel - Controls
641
  with gr.Column(scale=1, elem_classes="control-panel"):
 
787
  app.launch(share=True, show_error=True)
788
 
789
  # For production use:
790
+ # exit(main())