Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from datasets import load_dataset
|
| 3 |
from datetime import datetime
|
| 4 |
import io
|
| 5 |
-
import
|
| 6 |
|
| 7 |
# Constants
|
| 8 |
SCORES_DATASET = "agents-course/unit4-students-scores"
|
|
@@ -31,13 +31,23 @@ def add_certificate_entry(username, name):
|
|
| 31 |
ds = ds.add_item(new_entry)
|
| 32 |
ds.push_to_hub(CERTIFICATES_DATASET)
|
| 33 |
|
| 34 |
-
# Function to generate certificate
|
| 35 |
def generate_certificate(name, score):
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return pdf_output
|
| 38 |
|
| 39 |
# Main function to handle certificate generation
|
| 40 |
-
def handle_certificate(name, profile: gr.OAuthProfile
|
| 41 |
if profile is None:
|
| 42 |
return "You must be logged in with your Hugging Face account.", None
|
| 43 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from datasets import load_dataset
|
| 3 |
from datetime import datetime
|
| 4 |
import io
|
| 5 |
+
from fpdf import FPDF
|
| 6 |
|
| 7 |
# Constants
|
| 8 |
SCORES_DATASET = "agents-course/unit4-students-scores"
|
|
|
|
| 31 |
ds = ds.add_item(new_entry)
|
| 32 |
ds.push_to_hub(CERTIFICATES_DATASET)
|
| 33 |
|
| 34 |
+
# Function to generate certificate PDF
|
| 35 |
def generate_certificate(name, score):
|
| 36 |
+
pdf = FPDF()
|
| 37 |
+
pdf.add_page()
|
| 38 |
+
pdf.set_font("Arial", size=24)
|
| 39 |
+
pdf.cell(200, 20, txt="Certificate of Excellence", ln=True, align="C")
|
| 40 |
+
pdf.set_font("Arial", size=16)
|
| 41 |
+
pdf.cell(200, 10, txt=f"Presented to {name}", ln=True, align="C")
|
| 42 |
+
pdf.cell(200, 10, txt=f"For passing Unit 4 with a score of {score}", ln=True, align="C")
|
| 43 |
+
pdf.cell(200, 10, txt=f"Date: {datetime.now().strftime('%Y-%m-%d')}", ln=True, align="C")
|
| 44 |
+
pdf_output = io.BytesIO()
|
| 45 |
+
pdf.output(pdf_output)
|
| 46 |
+
pdf_output.seek(0)
|
| 47 |
return pdf_output
|
| 48 |
|
| 49 |
# Main function to handle certificate generation
|
| 50 |
+
def handle_certificate(name, profile: gr.OAuthProfile):
|
| 51 |
if profile is None:
|
| 52 |
return "You must be logged in with your Hugging Face account.", None
|
| 53 |
|