ymcmy commited on
Commit
a107121
·
verified ·
1 Parent(s): 7d8b04f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from weasyprint import HTML
3
+ from datetime import datetime
4
+ from utils import gen_html
5
+ import os
6
+
7
+ def generate_pdf(num_questions):
8
+ now = datetime.now()
9
+ filename = now.strftime("%Y_%m_%d_AMC.pdf")
10
+
11
+ allhtml = gen_html(num_questions)
12
+
13
+ HTML(string=allhtml).write_pdf(filename)
14
+
15
+ return filename
16
+
17
+ def lucky_button(num_questions):
18
+ pdf_file = generate_pdf(num_questions)
19
+ return pdf_file
20
+
21
+ interface = gr.Interface(
22
+ fn=lucky_button,
23
+ inputs=gr.inputs.Slider(minimum=1, maximum=20, step=1, default=5, label="Number of Questions"),
24
+ outputs="file",
25
+ title="Random AMC/AIME Problem PDF Generator",
26
+ description="Click the button to generate a random PDF of AMC/AIME problems. You can specify the number of questions to include in the PDF."
27
+ )
28
+
29
+ interface.launch()