Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,142 @@
|
|
1 |
import gradio as gr
|
2 |
-
import json
|
3 |
import random
|
4 |
-
import
|
|
|
|
|
|
|
5 |
|
6 |
-
# Define a list of topics
|
7 |
TOPICS = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
"Average Value": {
|
9 |
-
"formula": "
|
10 |
"functions": {
|
11 |
"easy": [
|
12 |
-
{"func": "x^2", "domain": [0, 2], "solution": "4
|
13 |
-
{"func": "sin(x)", "domain": [0, "π"], "solution": "2
|
14 |
-
{"func": "e^x", "domain": [0, 1], "solution": "(e-1)"},
|
15 |
-
{"func": "x", "domain": [1, 4], "solution": "5
|
16 |
-
{"func": "x^3", "domain": [0, 1], "solution": "1
|
17 |
],
|
18 |
"hard": [
|
19 |
-
{"func": "x
|
20 |
-
{"func": "ln(x)", "domain": [1, "e"], "solution": "1
|
21 |
-
{"func": "x^
|
22 |
-
{"func": "1
|
23 |
-
{"func": "sqrt
|
24 |
]
|
25 |
}
|
26 |
},
|
27 |
"Arc Length": {
|
28 |
-
"formula": "L =
|
29 |
"functions": {
|
30 |
"easy": [
|
31 |
-
{"func": "x^2", "domain": [0, 1], "solution": "approx
|
32 |
-
{"func": "x^
|
33 |
-
{"func": "2x+1", "domain": [0, 2], "solution": "sqrt
|
34 |
-
{"func": "x^3", "domain": [0, 1], "solution": "approx
|
35 |
-
{"func": "sin(x)", "domain": [0, "π/2"], "solution": "approx
|
36 |
],
|
37 |
"hard": [
|
38 |
-
{"func": "ln(x)", "domain": [1, 3], "solution": "approx
|
39 |
-
{"func": "e^x", "domain": [0, 1], "solution": "approx
|
40 |
-
{"func": "cosh(x)", "domain": [0, 1], "solution": "sinh(1)"},
|
41 |
-
{"func": "x^2 - ln(x)", "domain": [1, 2], "solution": "approx
|
42 |
-
{"func": "
|
43 |
]
|
44 |
}
|
45 |
},
|
46 |
"Surface Area": {
|
47 |
-
"formula": "S = 2
|
48 |
"functions": {
|
49 |
"easy": [
|
50 |
-
{"func": "x", "domain": [0, 3], "solution": "2
|
51 |
-
{"func": "x^2", "domain": [0, 1], "solution": "approx
|
52 |
-
{"func": "sqrt
|
53 |
-
{"func": "1", "domain": [0, 2], "solution": "2
|
54 |
-
{"func": "x
|
55 |
],
|
56 |
"hard": [
|
57 |
-
{"func": "x^3", "domain": [0, 1], "solution": "approx
|
58 |
-
{"func": "e^x", "domain": [0, 1], "solution": "approx
|
59 |
-
{"func": "sin(x)", "domain": [0, "π/2"], "solution": "approx
|
60 |
-
{"func": "1
|
61 |
-
{"func": "ln(x)", "domain": [1, 2], "solution": "approx
|
62 |
]
|
63 |
}
|
64 |
},
|
@@ -66,62 +144,138 @@ TOPICS = {
|
|
66 |
"formula": "Various types",
|
67 |
"functions": {
|
68 |
"easy": [
|
69 |
-
{"func": "dy
|
70 |
-
{"func": "dy
|
71 |
-
{"func": "dy
|
72 |
-
{"func": "dy
|
73 |
-
{"func": "dy
|
74 |
],
|
75 |
"hard": [
|
76 |
-
{"func": "y'' + 4y = 0", "domain": ["y(0)=1
|
77 |
-
{"func": "y'' - y = x", "domain": ["y(0)=0
|
78 |
-
{"func": "y' + y = e^x", "domain": ["y(0)=0"], "solution": "y = xe^x"},
|
79 |
-
{"func": "y'' + 2y' + y = 0", "domain": ["y(0)=1
|
80 |
-
{"func": "y'' - 2y' + y = x^2", "domain": ["y(0)=1
|
81 |
]
|
82 |
}
|
83 |
},
|
84 |
"Area and Volume": {
|
85 |
-
"formula": "A =
|
86 |
"functions": {
|
87 |
"easy": [
|
88 |
-
{"func": "f(x) = x^2
|
89 |
-
{"func": "f(x) = sin(x)
|
90 |
-
{"func": "f(x) = 4-x^2
|
91 |
-
{"func": "f(x) = sqrt
|
92 |
-
{"func": "f(x) = x
|
93 |
],
|
94 |
"hard": [
|
95 |
-
{"func": "Area between f(x) = x^2 and g(x) = x^3", "domain": [0, 1], "solution": "1
|
96 |
-
{"func": "Volume of solid bounded by z = 4-x^2-y^2 and z = 0", "domain": ["x^2+y^2
|
97 |
-
{"func": "Volume of solid formed by rotating region bounded by y = x^2
|
98 |
-
{"func": "Area between f(x) = sin(x) and g(x) = cos(x)", "domain": [0, "π/4"], "solution": "sqrt
|
99 |
-
{"func": "Volume of solid formed by rotating region bounded by y = e^x
|
100 |
]
|
101 |
}
|
102 |
},
|
103 |
"Parametric Curves and Equations": {
|
104 |
-
"formula": "x = x(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
"functions": {
|
106 |
"easy": [
|
107 |
-
{"func": "
|
108 |
-
{"func": "
|
109 |
-
{"func": "
|
110 |
-
{"func": "
|
111 |
-
{"func": "x
|
112 |
],
|
113 |
"hard": [
|
114 |
-
{"func": "
|
115 |
-
{"func": "
|
116 |
-
{"func": "
|
117 |
-
{"func": "
|
118 |
-
{"func": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
]
|
120 |
}
|
121 |
}
|
122 |
}
|
123 |
|
124 |
-
# Function to generate a
|
125 |
def generate_question(topic_name, difficulty):
|
126 |
topic_data = TOPICS[topic_name]
|
127 |
formula = topic_data["formula"]
|
@@ -142,7 +296,7 @@ def generate_question(topic_name, difficulty):
|
|
142 |
if difficulty == "easy":
|
143 |
question = f"Find the {topic_name.lower()} of {func} over the domain {domain_str}."
|
144 |
solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
|
145 |
-
solution_text += f"Step 2: Substitute f(x) = {func} and evaluate over {domain_str}\n\n"
|
146 |
solution_text += f"Step 3: Solve the resulting integral or calculation\n\n"
|
147 |
solution_text += f"Final Answer: {solution}"
|
148 |
else:
|
@@ -150,69 +304,99 @@ def generate_question(topic_name, difficulty):
|
|
150 |
solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
|
151 |
solution_text += f"Step 2: For {func}, substitute into the formula and evaluate over {domain_str}\n\n"
|
152 |
solution_text += f"Step 3: This requires advanced integration techniques or careful analysis\n\n"
|
153 |
-
solution_text += f"Step 4: After simplification and evaluation of the integral\n\n"
|
154 |
solution_text += f"Final Answer: {solution}"
|
155 |
|
156 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
-
#
|
159 |
-
def
|
160 |
-
|
161 |
-
|
162 |
|
163 |
-
for _ in range(count):
|
164 |
-
|
165 |
-
|
166 |
-
solutions.append(solution)
|
167 |
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
170 |
|
171 |
-
return
|
172 |
|
173 |
-
#
|
174 |
-
def
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
# Create the Gradio interface
|
180 |
-
with gr.Blocks(title="Calculus
|
181 |
-
gr.Markdown("# Calculus
|
182 |
-
gr.Markdown("
|
183 |
|
184 |
with gr.Row():
|
185 |
with gr.Column():
|
186 |
topic = gr.Dropdown(
|
187 |
choices=list(TOPICS.keys()),
|
188 |
label="Calculus Topic",
|
189 |
-
value="
|
190 |
)
|
191 |
difficulty = gr.Radio(
|
192 |
choices=["easy", "hard"],
|
193 |
-
label="Difficulty
|
194 |
value="easy"
|
195 |
)
|
196 |
count = gr.Slider(
|
197 |
minimum=1,
|
198 |
maximum=10,
|
199 |
-
value=3,
|
200 |
step=1,
|
|
|
201 |
label="Number of Questions"
|
202 |
)
|
203 |
generate_button = gr.Button("Generate Questions")
|
|
|
204 |
|
205 |
with gr.Column():
|
206 |
-
|
207 |
-
|
208 |
|
209 |
generate_button.click(
|
210 |
generate_calculus_questions,
|
211 |
inputs=[topic, difficulty, count],
|
212 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
)
|
214 |
|
215 |
-
gr.Markdown("### Created by
|
216 |
|
217 |
# Launch the app
|
218 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import random
|
3 |
+
import json
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
from datetime import datetime
|
7 |
|
8 |
+
# Define a comprehensive list of calculus topics based on James Stewart's textbook
|
9 |
TOPICS = {
|
10 |
+
"Limits and Continuity": {
|
11 |
+
"formula": "For a function $f(x)$, $\\lim_{x \\to a} f(x) = L$",
|
12 |
+
"functions": {
|
13 |
+
"easy": [
|
14 |
+
{"func": "$\\lim_{x \\to 2} (3x+4)$", "domain": ["$x \\to 2$"], "solution": "$10$"},
|
15 |
+
{"func": "$\\lim_{x \\to 0} \\frac{\\sin(x)}{x}$", "domain": ["$x \\to 0$"], "solution": "$1$"},
|
16 |
+
{"func": "$\\lim_{x \\to 3} (x^2-5x+2)$", "domain": ["$x \\to 3$"], "solution": "$-4$"},
|
17 |
+
{"func": "$\\lim_{x \\to 1} \\frac{x^2-1}{x-1}$", "domain": ["$x \\to 1$"], "solution": "$2$"},
|
18 |
+
{"func": "$\\lim_{x \\to \\infty} \\frac{2x^2+3x-5}{x^2}$", "domain": ["$x \\to \\infty$"], "solution": "$2$"}
|
19 |
+
],
|
20 |
+
"hard": [
|
21 |
+
{"func": "$\\lim_{x \\to 0} \\frac{1-\\cos(x)}{x^2}$", "domain": ["$x \\to 0$"], "solution": "$\\frac{1}{2}$"},
|
22 |
+
{"func": "$\\lim_{x \\to 0} (\\frac{1}{x} - \\frac{1}{\\sin(x)})$", "domain": ["$x \\to 0$"], "solution": "$0$"},
|
23 |
+
{"func": "$\\lim_{x \\to 0} \\frac{e^x-1-x}{x^2}$", "domain": ["$x \\to 0$"], "solution": "$\\frac{1}{2}$"},
|
24 |
+
{"func": "$\\lim_{x \\to \\infty} (1 + \\frac{1}{x})^x$", "domain": ["$x \\to \\infty$"], "solution": "$e$"},
|
25 |
+
{"func": "$\\lim_{x \\to 0^+} x^{\\alpha}\\ln(x)$ where $\\alpha > 0$", "domain": ["$x \\to 0^+$"], "solution": "$0$"}
|
26 |
+
]
|
27 |
+
}
|
28 |
+
},
|
29 |
+
"Derivatives and Differentiation": {
|
30 |
+
"formula": "$f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}$",
|
31 |
+
"functions": {
|
32 |
+
"easy": [
|
33 |
+
{"func": "$f(x) = x^3 - 4x^2 + 7x - 2$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 3x^2 - 8x + 7$"},
|
34 |
+
{"func": "$f(x) = \\sin(2x)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 2\\cos(2x)$"},
|
35 |
+
{"func": "$f(x) = e^{3x}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 3e^{3x}$"},
|
36 |
+
{"func": "$f(x) = \\ln(x^2 + 1)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{2x}{x^2+1}$"},
|
37 |
+
{"func": "$f(x) = x^2 e^x$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = x^2 e^x + 2x e^x$"}
|
38 |
+
],
|
39 |
+
"hard": [
|
40 |
+
{"func": "$f(x) = \\frac{\\sin(x)}{\\cos(x) + 2}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{\\cos(x)(\\cos(x) + 2) + \\sin^2(x)}{(\\cos(x) + 2)^2}$"},
|
41 |
+
{"func": "$f(x) = \\int_{0}^{x^2} \\sin(t^2) dt$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = 2x\\sin(x^4)$"},
|
42 |
+
{"func": "$f(x) = \\arctan(e^x)$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\frac{e^x}{1 + e^{2x}}$"},
|
43 |
+
{"func": "$f(x) = x^{\\sin(x)}$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = x^{\\sin(x)}(\\cos(x)\\ln(x) + \\frac{\\sin(x)}{x})$"},
|
44 |
+
{"func": "$f(x) = \\ln(\\sin(x))$", "domain": ["Find $f'(x)$"], "solution": "$f'(x) = \\cot(x)$"}
|
45 |
+
]
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"Applications of Derivatives": {
|
49 |
+
"formula": "Related Rates, Optimization, L'Hôpital's Rule",
|
50 |
+
"functions": {
|
51 |
+
"easy": [
|
52 |
+
{"func": "A particle moves according to $s(t) = t^3 - 6t^2 + 9t$. Find its velocity at $t = 2$", "domain": ["$t = 2$"], "solution": "$v(2) = -3$ units/sec"},
|
53 |
+
{"func": "Find the critical points of $f(x) = x^3 - 3x^2 - 9x + 5$", "domain": ["$x \\in \\mathbb{R}$"], "solution": "$x = -1$ and $x = 3$"},
|
54 |
+
{"func": "Find the absolute maximum and minimum of $f(x) = x^2 - 4x + 3$ on $[0, 3]$", "domain": ["$[0, 3]$"], "solution": "Maximum: $f(0) = 3$, Minimum: $f(2) = -1$"},
|
55 |
+
{"func": "Use L'Hôpital's Rule to evaluate $\\lim_{x \\to 0} \\frac{\\tan(3x)}{x}$", "domain": ["$x \\to 0$"], "solution": "$3$"},
|
56 |
+
{"func": "Find the equation of the tangent line to $f(x) = x^2 + 2x - 3$ at $x = 1$", "domain": ["$x = 1$"], "solution": "$y = 4x - 2$"}
|
57 |
+
],
|
58 |
+
"hard": [
|
59 |
+
{"func": "A ladder 10 feet long leans against a wall. If the bottom slides away at 2 ft/s, how fast is the top sliding down when it's 6 feet above ground?", "domain": ["Rate problem"], "solution": "$\\frac{3}{2}$ ft/s"},
|
60 |
+
{"func": "Find the dimensions of the rectangle with perimeter 100 m that has the maximum area", "domain": ["Optimization"], "solution": "25 m × 25 m square"},
|
61 |
+
{"func": "Use Newton's method to approximate a root of $f(x) = x^3 - 2x - 5$ starting with $x_1 = 2$", "domain": ["Newton's Method"], "solution": "$x \\approx 2.0946$ after 3 iterations"},
|
62 |
+
{"func": "Find the absolute extrema of $f(x) = xe^{-x^2}$ on $[0, \\infty)$", "domain": ["$[0, \\infty)$"], "solution": "Maximum: $f(\\frac{1}{\\sqrt{2}}) = \\frac{1}{\\sqrt{2e}}$, Minimum: $f(0) = f(\\infty) = 0$"},
|
63 |
+
{"func": "Use implicit differentiation to find $\\frac{dy}{dx}$ for $x^3 + y^3 = 6xy$", "domain": ["Implicit"], "solution": "$\\frac{dy}{dx} = \\frac{6y - 3x^2}{3y^2 - 6x}$"}
|
64 |
+
]
|
65 |
+
}
|
66 |
+
},
|
67 |
+
"Integration Techniques": {
|
68 |
+
"formula": "$\\int f(x) dx$ using various methods",
|
69 |
+
"functions": {
|
70 |
+
"easy": [
|
71 |
+
{"func": "$\\int x^3(x^2+1)^4 dx$", "domain": ["Use Substitution"], "solution": "$\\frac{1}{10}(x^2+1)^5 - \\frac{1}{6}(x^2+1)^3 + C$"},
|
72 |
+
{"func": "$\\int \\frac{1}{x^2-4} dx$", "domain": ["Use Partial Fractions"], "solution": "$\\frac{1}{4}\\ln|\\frac{x-2}{x+2}| + C$"},
|
73 |
+
{"func": "$\\int x\\sin(x) dx$", "domain": ["Use Integration by Parts"], "solution": "$\\sin(x) - x\\cos(x) + C$"},
|
74 |
+
{"func": "$\\int \\sec^2(3x) dx$", "domain": ["Trigonometric"], "solution": "$\\frac{1}{3}\\tan(3x) + C$"},
|
75 |
+
{"func": "$\\int \\frac{5}{3x+6} dx$", "domain": ["Substitution"], "solution": "$\\frac{5}{3}\\ln|3x+6| + C$"}
|
76 |
+
],
|
77 |
+
"hard": [
|
78 |
+
{"func": "$\\int \\frac{x^2}{\\sqrt{1-x^2}} dx$", "domain": ["Trigonometric Substitution"], "solution": "$-\\frac{x\\sqrt{1-x^2}}{2} - \\frac{\\arcsin(x)}{2} + C$"},
|
79 |
+
{"func": "$\\int \\frac{\\ln(x)}{x^2} dx$", "domain": ["Integration by Parts"], "solution": "$-\\frac{\\ln(x)}{x} - \\frac{1}{x} + C$"},
|
80 |
+
{"func": "$\\int e^x\\sin(x) dx$", "domain": ["Integration by Parts twice"], "solution": "$\\frac{e^x(\\sin(x)-\\cos(x))}{2} + C$"},
|
81 |
+
{"func": "$\\int \\frac{1}{x^2-x-6} dx$", "domain": ["Partial Fractions"], "solution": "$\\frac{1}{5}\\ln|\\frac{x+2}{x-3}| + C$"},
|
82 |
+
{"func": "$\\int \\frac{1}{\\sqrt{x^2-a^2}} dx$", "domain": ["$a > 0$"], "solution": "$\\ln|x + \\sqrt{x^2-a^2}| + C$"}
|
83 |
+
]
|
84 |
+
}
|
85 |
+
},
|
86 |
"Average Value": {
|
87 |
+
"formula": "$f_{avg} = \\frac{1}{b-a} \\int_{a}^{b} f(x) dx$",
|
88 |
"functions": {
|
89 |
"easy": [
|
90 |
+
{"func": "$x^2$", "domain": [0, 2], "solution": "$\\frac{4}{3}$"},
|
91 |
+
{"func": "$\\sin(x)$", "domain": [0, "π"], "solution": "$\\frac{2}{\\pi}$"},
|
92 |
+
{"func": "$e^x$", "domain": [0, 1], "solution": "$(e-1)$"},
|
93 |
+
{"func": "$x$", "domain": [1, 4], "solution": "$\\frac{5}{2}$"},
|
94 |
+
{"func": "$x^3$", "domain": [0, 1], "solution": "$\\frac{1}{4}$"}
|
95 |
],
|
96 |
"hard": [
|
97 |
+
{"func": "$x\\sin(x)$", "domain": [0, "π"], "solution": "$\\frac{\\pi}{2}$"},
|
98 |
+
{"func": "$\\ln(x)$", "domain": [1, "e"], "solution": "$1-\\frac{1}{e}$"},
|
99 |
+
{"func": "$x^2e^x$", "domain": [0, 1], "solution": "$2e-2$"},
|
100 |
+
{"func": "$\\frac{1}{1+x^2}$", "domain": [0, 1], "solution": "$\\frac{\\pi}{4}$"},
|
101 |
+
{"func": "$\\sqrt{x}$", "domain": [0, 4], "solution": "$\\frac{4}{3}$"}
|
102 |
]
|
103 |
}
|
104 |
},
|
105 |
"Arc Length": {
|
106 |
+
"formula": "$L = \\int_{a}^{b} \\sqrt{1 + (f'(x))^2} dx$",
|
107 |
"functions": {
|
108 |
"easy": [
|
109 |
+
{"func": "$x^2$", "domain": [0, 1], "solution": "$\\approx 1.4789$"},
|
110 |
+
{"func": "$x^{3/2}$", "domain": [0, 1], "solution": "$\\approx 1.1919$"},
|
111 |
+
{"func": "$2x+1$", "domain": [0, 2], "solution": "$2\\sqrt{5}$"},
|
112 |
+
{"func": "$x^3$", "domain": [0, 1], "solution": "$\\approx 1.0801$"},
|
113 |
+
{"func": "$\\sin(x)$", "domain": [0, "π/2"], "solution": "$\\approx 1.9118$"}
|
114 |
],
|
115 |
"hard": [
|
116 |
+
{"func": "$\\ln(x)$", "domain": [1, 3], "solution": "$\\approx 2.3861$"},
|
117 |
+
{"func": "$e^x$", "domain": [0, 1], "solution": "$\\approx 1.1752$"},
|
118 |
+
{"func": "$\\cosh(x)$", "domain": [0, 1], "solution": "$\\sinh(1)$"},
|
119 |
+
{"func": "$x^2 - \\ln(x)$", "domain": [1, 2], "solution": "$\\approx 3.1623$"},
|
120 |
+
{"func": "$x = \\cos(t)$, $y = \\sin(t)$ for $t\\in[0,\\pi]$", "domain": [0, "π"], "solution": "$\\pi$"}
|
121 |
]
|
122 |
}
|
123 |
},
|
124 |
"Surface Area": {
|
125 |
+
"formula": "$S = 2\\pi \\int_{a}^{b} f(x) \\sqrt{1 + (f'(x))^2} dx$",
|
126 |
"functions": {
|
127 |
"easy": [
|
128 |
+
{"func": "$x$", "domain": [0, 3], "solution": "$2\\pi \\cdot 4.5$"},
|
129 |
+
{"func": "$x^2$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 0.7169$"},
|
130 |
+
{"func": "$\\sqrt{x}$", "domain": [0, 4], "solution": "$\\approx 2\\pi \\cdot 4.5177$"},
|
131 |
+
{"func": "$1$", "domain": [0, 2], "solution": "$2\\pi \\cdot 2$"},
|
132 |
+
{"func": "$\\frac{x}{2}$", "domain": [0, 4], "solution": "$2\\pi \\cdot 4.1231$"}
|
133 |
],
|
134 |
"hard": [
|
135 |
+
{"func": "$x^3$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 0.6004$"},
|
136 |
+
{"func": "$e^x$", "domain": [0, 1], "solution": "$\\approx 2\\pi \\cdot 1.1793$"},
|
137 |
+
{"func": "$\\sin(x)$", "domain": [0, "π/2"], "solution": "$\\approx 2\\pi \\cdot 0.6366$"},
|
138 |
+
{"func": "$\\frac{1}{x}$", "domain": [1, 2], "solution": "$\\approx 2\\pi \\cdot 1.1478$"},
|
139 |
+
{"func": "$\\ln(x)$", "domain": [1, 2], "solution": "$\\approx 2\\pi \\cdot 0.5593$"}
|
140 |
]
|
141 |
}
|
142 |
},
|
|
|
144 |
"formula": "Various types",
|
145 |
"functions": {
|
146 |
"easy": [
|
147 |
+
{"func": "$\\frac{dy}{dx} = 2x$", "domain": ["$y(0)=1$"], "solution": "$y = x^2 + 1$"},
|
148 |
+
{"func": "$\\frac{dy}{dx} = y$", "domain": ["$y(0)=1$"], "solution": "$y = e^x$"},
|
149 |
+
{"func": "$\\frac{dy}{dx} = 3x^2$", "domain": ["$y(0)=2$"], "solution": "$y = x^3 + 2$"},
|
150 |
+
{"func": "$\\frac{dy}{dx} = -y$", "domain": ["$y(0)=4$"], "solution": "$y = 4e^{-x}$"},
|
151 |
+
{"func": "$\\frac{dy}{dx} = x+1$", "domain": ["$y(0)=-2$"], "solution": "$y = \\frac{x^2}{2} + x - 2$"}
|
152 |
],
|
153 |
"hard": [
|
154 |
+
{"func": "$y'' + 4y = 0$", "domain": ["$y(0)=1$, $y'(0)=0$"], "solution": "$y = \\cos(2x)$"},
|
155 |
+
{"func": "$y'' - y = x$", "domain": ["$y(0)=0$, $y'(0)=1$"], "solution": "$y = \\frac{e^x}{2} - \\frac{e^{-x}}{2} - x$"},
|
156 |
+
{"func": "$y' + y = e^x$", "domain": ["$y(0)=0$"], "solution": "$y = xe^x$"},
|
157 |
+
{"func": "$y'' + 2y' + y = 0$", "domain": ["$y(0)=1$, $y'(0)=-1$"], "solution": "$y = (1-x)e^{-x}$"},
|
158 |
+
{"func": "$y'' - 2y' + y = x^2$", "domain": ["$y(0)=1$, $y'(0)=1$"], "solution": "$y = \\frac{x^2}{2} + 2x + 1$"}
|
159 |
]
|
160 |
}
|
161 |
},
|
162 |
"Area and Volume": {
|
163 |
+
"formula": "$A = \\int_{a}^{b} f(x) dx$, $V = \\pi \\int_{a}^{b} [f(x)]^2 dx$",
|
164 |
"functions": {
|
165 |
"easy": [
|
166 |
+
{"func": "$f(x) = x^2$, find area under the curve", "domain": [0, 3], "solution": "$9$"},
|
167 |
+
{"func": "$f(x) = \\sin(x)$, find area under the curve", "domain": [0, "π"], "solution": "$2$"},
|
168 |
+
{"func": "$f(x) = 4-x^2$, find area under the curve", "domain": [-2, 2], "solution": "$\\frac{16}{3}$"},
|
169 |
+
{"func": "$f(x) = \\sqrt{x}$, find volume of revolution around x-axis", "domain": [0, 4], "solution": "$\\frac{16\\pi}{3}$"},
|
170 |
+
{"func": "$f(x) = x$, find volume of revolution around x-axis", "domain": [0, 2], "solution": "$\\frac{8\\pi}{3}$"}
|
171 |
],
|
172 |
"hard": [
|
173 |
+
{"func": "Area between $f(x) = x^2$ and $g(x) = x^3$", "domain": [0, 1], "solution": "$\\frac{1}{12}$"},
|
174 |
+
{"func": "Volume of solid bounded by $z = 4-x^2-y^2$ and $z = 0$", "domain": ["$x^2+y^2\\leq 4$"], "solution": "$8\\pi$"},
|
175 |
+
{"func": "Volume of solid formed by rotating region bounded by $y = x^2$, $y = 0$, $x = 2$ around y-axis", "domain": [0, 2], "solution": "$\\frac{8\\pi}{5}$"},
|
176 |
+
{"func": "Area between $f(x) = \\sin(x)$ and $g(x) = \\cos(x)$", "domain": [0, "π/4"], "solution": "$\\sqrt{2}-1$"},
|
177 |
+
{"func": "Volume of solid formed by rotating region bounded by $y = e^x$, $y = 0$, $x = 0$, $x = 1$ around x-axis", "domain": [0, 1], "solution": "$\\frac{\\pi(e^2-1)}{2}$"}
|
178 |
]
|
179 |
}
|
180 |
},
|
181 |
"Parametric Curves and Equations": {
|
182 |
+
"formula": "$x = x(t)$, $y = y(t)$, Arc length = $\\int_{a}^{b} \\sqrt{(\\frac{dx}{dt})^2 + (\\frac{dy}{dt})^2} dt$",
|
183 |
+
"functions": {
|
184 |
+
"easy": [
|
185 |
+
{"func": "$x = t$, $y = t^2$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = 2t$"},
|
186 |
+
{"func": "$x = \\cos(t)$, $y = \\sin(t)$, find the arc length", "domain": [0, "π/2"], "solution": "$\\frac{\\pi}{2}$"},
|
187 |
+
{"func": "$x = t^2$, $y = t^3$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\frac{3t}{2}$"},
|
188 |
+
{"func": "$x = 2t$, $y = t^2$, find the area under the curve", "domain": [0, 2], "solution": "$\\frac{4}{3}$"},
|
189 |
+
{"func": "$x = t$, $y = \\sin(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\cos(t)$"}
|
190 |
+
],
|
191 |
+
"hard": [
|
192 |
+
{"func": "$x = e^t\\cos(t)$, $y = e^t\\sin(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\tan(t) + 1$"},
|
193 |
+
{"func": "$x = t-\\sin(t)$, $y = 1-\\cos(t)$, find the arc length", "domain": [0, "2π"], "solution": "$8$"},
|
194 |
+
{"func": "$x = \\ln(\\sec(t))$, $y = \\tan(t)$, find $\\frac{dy}{dx}$", "domain": ["$t$"], "solution": "$\\frac{dy}{dx} = \\sec^2(t)$"},
|
195 |
+
{"func": "$x = \\cos^3(t)$, $y = \\sin^3(t)$, find the area enclosed", "domain": [0, "2π"], "solution": "$\\frac{3\\pi}{8}$"},
|
196 |
+
{"func": "$x = \\cos(t)+t\\sin(t)$, $y = \\sin(t)-t\\cos(t)$, find the arc length", "domain": [0, "2π"], "solution": "$2\\pi\\sqrt{1+4\\pi^2}$"}
|
197 |
+
]
|
198 |
+
}
|
199 |
+
},
|
200 |
+
"Infinite Sequences and Series": {
|
201 |
+
"formula": "$\\sum_{n=1}^{\\infty} a_n = a_1 + a_2 + a_3 + ...$",
|
202 |
+
"functions": {
|
203 |
+
"easy": [
|
204 |
+
{"func": "Determine if the sequence $a_n = \\frac{n+3}{2n+1}$ converges and find its limit", "domain": ["$n \\to \\infty$"], "solution": "Converges to $\\frac{1}{2}$"},
|
205 |
+
{"func": "Find the sum of the geometric series $\\sum_{n=0}^{\\infty} \\frac{1}{3^n}$", "domain": ["Geometric Series"], "solution": "$\\frac{3}{2}$"},
|
206 |
+
{"func": "Determine if the series $\\sum_{n=1}^{\\infty} \\frac{1}{n^2}$ converges", "domain": ["p-series"], "solution": "Converges (p-series with $p=2 > 1$)"},
|
207 |
+
{"func": "Find the first three non-zero terms in the Taylor series for $f(x) = e^x$ centered at $a = 0$", "domain": ["Taylor Series"], "solution": "$1 + x + \\frac{x^2}{2} + ...$"},
|
208 |
+
{"func": "Find the radius of convergence of the power series $\\sum_{n=1}^{\\infty} \\frac{x^n}{n}$", "domain": ["Power Series"], "solution": "$R = 1$"}
|
209 |
+
],
|
210 |
+
"hard": [
|
211 |
+
{"func": "Test the convergence of the alternating series $\\sum_{n=1}^{\\infty} (-1)^{n+1}\\frac{\\ln(n)}{n}$", "domain": ["Alternating Series"], "solution": "Converges by the Alternating Series Test"},
|
212 |
+
{"func": "Find the radius and interval of convergence for $\\sum_{n=1}^{\\infty} \\frac{n^2 x^n}{3^n}$", "domain": ["Power Series"], "solution": "$R = 3$, interval of convergence is $(-3, 3)$"},
|
213 |
+
{"func": "Determine if the series $\\sum_{n=2}^{\\infty} \\frac{1}{n\\ln(n)}$ converges", "domain": ["Integral Test"], "solution": "Diverges by the Integral Test"},
|
214 |
+
{"func": "Find the sum of the series $\\sum_{n=1}^{\\infty} \\frac{1}{n(n+1)}$", "domain": ["Telescoping Series"], "solution": "$1$"},
|
215 |
+
{"func": "Find the Taylor series of $f(x) = \\ln(1+x)$ and its radius of convergence", "domain": ["Taylor Series"], "solution": "$\\sum_{n=1}^{\\infty} \\frac{(-1)^{n+1}x^n}{n}$, $R = 1$"}
|
216 |
+
]
|
217 |
+
}
|
218 |
+
},
|
219 |
+
"Polar Coordinates": {
|
220 |
+
"formula": "$x = r\\cos(\\theta)$, $y = r\\sin(\\theta)$, Area = $\\frac{1}{2}\\int_{\\alpha}^{\\beta} r^2 d\\theta$",
|
221 |
"functions": {
|
222 |
"easy": [
|
223 |
+
{"func": "Convert the Cartesian point $(1, \\sqrt{3})$ to polar coordinates", "domain": ["Conversion"], "solution": "$r = 2$, $\\theta = \\frac{\\pi}{3}$"},
|
224 |
+
{"func": "Find the area enclosed by the circle $r = 3\\sin(\\theta)$", "domain": ["Polar Area"], "solution": "$\\frac{9\\pi}{2}$"},
|
225 |
+
{"func": "Convert the polar equation $r = 2$ to Cartesian form", "domain": ["Conversion"], "solution": "$x^2 + y^2 = 4$"},
|
226 |
+
{"func": "Find the area enclosed by $r = 2\\cos(\\theta)$", "domain": ["Polar Area"], "solution": "$2\\pi$"},
|
227 |
+
{"func": "Convert the Cartesian equation $x^2 + y^2 = 4y$ to polar form", "domain": ["Conversion"], "solution": "$r = 4\\sin(\\theta)$"}
|
228 |
],
|
229 |
"hard": [
|
230 |
+
{"func": "Find the area of the region enclosed by the lemniscate $r^2 = 4\\cos(2\\theta)$", "domain": ["Polar Area"], "solution": "$4$"},
|
231 |
+
{"func": "Find the area of the region inside $r = 1 + \\cos(\\theta)$ and outside $r = 1$", "domain": ["Polar Area"], "solution": "$\\frac{\\pi}{2}$"},
|
232 |
+
{"func": "Find the points of intersection of the polar curves $r = 1 + \\sin(\\theta)$ and $r = 1 - \\sin(\\theta)$", "domain": ["Polar Curves"], "solution": "$(0, 0)$ and $(1, \\frac{\\pi}{2})$, $(1, \\frac{3\\pi}{2})$"},
|
233 |
+
{"func": "Find the area of the region enclosed by the cardioid $r = 1 + \\cos(\\theta)$", "domain": ["Polar Area"], "solution": "$\\frac{3\\pi}{2}$"},
|
234 |
+
{"func": "Find the length of the spiral $r = \\theta$ for $0 \\leq \\theta \\leq 2\\pi$", "domain": ["Polar Arc Length"], "solution": "$\\frac{1}{2}\\sqrt{1+4\\pi^2} + \\frac{1}{2}\\ln(2\\pi + \\sqrt{1+4\\pi^2})$"}
|
235 |
+
]
|
236 |
+
}
|
237 |
+
},
|
238 |
+
"Vector Calculus": {
|
239 |
+
"formula": "$\\vec{r}(t) = x(t)\\vec{i} + y(t)\\vec{j} + z(t)\\vec{k}$, $\\vec{v}(t) = \\vec{r}'(t)$, $\\vec{a}(t) = \\vec{v}'(t)$",
|
240 |
+
"functions": {
|
241 |
+
"easy": [
|
242 |
+
{"func": "Find the derivative of the vector function $\\vec{r}(t) = t^2\\vec{i} + \\sin(t)\\vec{j} + e^t\\vec{k}$", "domain": ["Vector Function"], "solution": "$\\vec{r}'(t) = 2t\\vec{i} + \\cos(t)\\vec{j} + e^t\\vec{k}$"},
|
243 |
+
{"func": "Find the unit tangent vector of $\\vec{r}(t) = \\cos(t)\\vec{i} + \\sin(t)\\vec{j}$ at $t = 0$", "domain": ["$t = 0$"], "solution": "$\\vec{T}(0) = \\vec{j}$"},
|
244 |
+
{"func": "Calculate $\\nabla f$ where $f(x,y,z) = x^2y + yz^2$", "domain": ["Gradient"], "solution": "$\\nabla f = 2xy\\vec{i} + (x^2 + z^2)\\vec{j} + 2yz\\vec{k}$"},
|
245 |
+
{"func": "Find the divergence of the vector field $\\vec{F}(x,y,z) = x^2\\vec{i} + 2xy\\vec{j} + yz\\vec{k}$", "domain": ["Divergence"], "solution": "$\\nabla \\cdot \\vec{F} = 2x + 2x + z = 4x + z$"},
|
246 |
+
{"func": "Find the curl of $\\vec{F}(x,y,z) = y\\vec{i} + z\\vec{j} + x\\vec{k}$", "domain": ["Curl"], "solution": "$\\nabla \\times \\vec{F} = (1-0)\\vec{i} + (1-0)\\vec{j} + (1-0)\\vec{k} = \\vec{i} + \\vec{j} + \\vec{k}$"}
|
247 |
+
],
|
248 |
+
"hard": [
|
249 |
+
{"func": "Find the curvature of $\\vec{r}(t) = t\\vec{i} + t^2\\vec{j} + t^3\\vec{k}$ at $t = 1$", "domain": ["Curvature at $t = 1$"], "solution": "$\\kappa = \\frac{2\\sqrt{37}}{49\\sqrt{3}}$"},
|
250 |
+
{"func": "Verify Stokes' Theorem for $\\vec{F} = x^2\\vec{i} + xy\\vec{j} + z^2\\vec{k}$ on the hemisphere $z = \\sqrt{1-x^2-y^2}$, $z \\geq 0$", "domain": ["Stokes' Theorem"], "solution": "Both integrals equal $\\frac{\\pi}{2}$"},
|
251 |
+
{"func": "Use the Divergence Theorem to evaluate $\\iint_S \\vec{F} \\cdot \\vec{n} \\, dS$ where $\\vec{F}(x,y,z) = x\\vec{i} + y\\vec{j} + z\\vec{k}$ and $S$ is the sphere $x^2+y^2+z^2=4$", "domain": ["Divergence Theorem"], "solution": "$\\iint_S \\vec{F} \\cdot \\vec{n} \\, dS = \\iiint_V 3 \\, dV = 3 \\cdot \\frac{4}{3}\\pi \\cdot 4^{3/2} = 16\\pi$"},
|
252 |
+
{"func": "Find the potential function $f$ for the conservative vector field $\\vec{F} = (2x+y)\\vec{i} + (x+2z)\\vec{j} + (2y)\\vec{k}$", "domain": ["Potential Function"], "solution": "$f(x,y,z) = x^2 + xy + 2yz + C$"},
|
253 |
+
{"func": "Use Green's Theorem to evaluate $\\oint_C (y^2\\,dx + x^2\\,dy)$ where $C$ is the boundary of the region enclosed by $y = x^2$ and $y = 4$", "domain": ["Green's Theorem"], "solution": "$\\frac{256}{15}$"}
|
254 |
+
]
|
255 |
+
}
|
256 |
+
},
|
257 |
+
"Partial Derivatives and Multiple Integrals": {
|
258 |
+
"formula": "$\\frac{\\partial f}{\\partial x}$, $\\frac{\\partial f}{\\partial y}$, $\\iint_D f(x,y) \\, dA$, $\\iiint_E f(x,y,z) \\, dV$",
|
259 |
+
"functions": {
|
260 |
+
"easy": [
|
261 |
+
{"func": "Find $\\frac{\\partial z}{\\partial x}$ and $\\frac{\\partial z}{\\partial y}$ for $z = x^2 + 3xy - y^3$", "domain": ["Partial Derivatives"], "solution": "$\\frac{\\partial z}{\\partial x} = 2x + 3y$, $\\frac{\\partial z}{\\partial y} = 3x - 3y^2$"},
|
262 |
+
{"func": "Evaluate $\\iint_D (x + y) \\, dA$ where $D = \\{(x, y) | 0 \\leq x \\leq 1, 0 \\leq y \\leq 2\\}$", "domain": ["Double Integral"], "solution": "$3$"},
|
263 |
+
{"func": "Find all critical points of $f(x,y) = x^2 + y^2 - 4x - 6y + 12$", "domain": ["Critical Points"], "solution": "$(2, 3)$"},
|
264 |
+
{"func": "Convert the double integral $\\iint_D x^2y \\, dA$ to polar coordinates where $D$ is the disc $x^2 + y^2 \\leq 4$", "domain": ["Change to Polar"], "solution": "$\\int_0^{2\\pi} \\int_0^2 r^3 \\cos^2(\\theta)\\sin(\\theta) \\, dr \\, d\\theta$"},
|
265 |
+
{"func": "Evaluate $\\iint_D xy \\, dA$ where $D$ is the triangle with vertices $(0,0)$, $(1,0)$, and $(0,1)$", "domain": ["Double Integral"], "solution": "$\\frac{1}{24}$"}
|
266 |
+
],
|
267 |
+
"hard": [
|
268 |
+
{"func": "Find the absolute maximum and minimum values of $f(x,y) = 2x^2 + y^2 - 4x + 6y + 10$ on the closed disc $x^2 + y^2 \\leq 25$", "domain": ["Extrema on Region"], "solution": "Maximum: $135$ at $(5,0)$, Minimum: $1$ at $(1,-3)$"},
|
269 |
+
{"func": "Evaluate $\\iiint_E xy^2z^3 \\, dV$ where $E$ is the solid bounded by $x=0$, $y=0$, $z=0$, $x+y+z=1$", "domain": ["Triple Integral"], "solution": "$\\frac{1}{840}$"},
|
270 |
+
{"func": "Use Lagrange multipliers to find the maximum value of $f(x,y) = xy$ subject to the constraint $x^2 + y^2 = 8$", "domain": ["Lagrange Multipliers"], "solution": "$4$ at $(\\pm 2, \\pm 2)$"},
|
271 |
+
{"func": "Change the order of integration in $\\int_0^1 \\int_y^1 e^{xy} \\, dx \\, dy$", "domain": ["Change of Order"], "solution": "$\\int_0^1 \\int_0^x e^{xy} \\, dy \\, dx$"},
|
272 |
+
{"func": "Evaluate $\\iint_D \\frac{1}{1+x^2+y^2} \\, dA$ where $D = \\{(x,y) | x^2 + y^2 \\leq 4\\}$", "domain": ["Double Integral"], "solution": "$\\pi\\ln(5)$"}
|
273 |
]
|
274 |
}
|
275 |
}
|
276 |
}
|
277 |
|
278 |
+
# Function to generate a question for a given topic and difficulty
|
279 |
def generate_question(topic_name, difficulty):
|
280 |
topic_data = TOPICS[topic_name]
|
281 |
formula = topic_data["formula"]
|
|
|
296 |
if difficulty == "easy":
|
297 |
question = f"Find the {topic_name.lower()} of {func} over the domain {domain_str}."
|
298 |
solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
|
299 |
+
solution_text += f"Step 2: Substitute $f(x) = {func}$ and evaluate over {domain_str}\n\n"
|
300 |
solution_text += f"Step 3: Solve the resulting integral or calculation\n\n"
|
301 |
solution_text += f"Final Answer: {solution}"
|
302 |
else:
|
|
|
304 |
solution_text = f"Step 1: Apply the formula for {topic_name.lower()}: {formula}\n\n"
|
305 |
solution_text += f"Step 2: For {func}, substitute into the formula and evaluate over {domain_str}\n\n"
|
306 |
solution_text += f"Step 3: This requires advanced integration techniques or careful analysis\n\n"
|
|
|
307 |
solution_text += f"Final Answer: {solution}"
|
308 |
|
309 |
+
return {
|
310 |
+
"topic": topic_name,
|
311 |
+
"difficulty": difficulty,
|
312 |
+
"question": question,
|
313 |
+
"solution": solution_text
|
314 |
+
}
|
315 |
+
|
316 |
+
# Store the latest generated questions
|
317 |
+
latest_questions = []
|
318 |
|
319 |
+
# Generate questions function for Gradio
|
320 |
+
def generate_calculus_questions(topic, difficulty, count):
|
321 |
+
global latest_questions
|
322 |
+
latest_questions = []
|
323 |
|
324 |
+
for _ in range(int(count)):
|
325 |
+
question_data = generate_question(topic, difficulty)
|
326 |
+
latest_questions.append(question_data)
|
|
|
327 |
|
328 |
+
# Format the output for display
|
329 |
+
result = ""
|
330 |
+
for i, q in enumerate(latest_questions):
|
331 |
+
result += f"Question {i+1}: {q['question']}\n\n"
|
332 |
+
result += f"Solution {i+1}: {q['solution']}\n\n"
|
333 |
+
result += "-" * 40 + "\n\n"
|
334 |
|
335 |
+
return result
|
336 |
|
337 |
+
# Function to export questions to JSON
|
338 |
+
def export_to_json():
|
339 |
+
if not latest_questions:
|
340 |
+
return None
|
341 |
+
|
342 |
+
# Create a JSON file
|
343 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
344 |
+
json_data = {
|
345 |
+
"generated_at": timestamp,
|
346 |
+
"questions": latest_questions
|
347 |
+
}
|
348 |
+
|
349 |
+
# Create a temporary file
|
350 |
+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp_file:
|
351 |
+
json.dump(json_data, temp_file, indent=2)
|
352 |
+
temp_file_path = temp_file.name
|
353 |
+
|
354 |
+
return temp_file_path
|
355 |
|
356 |
# Create the Gradio interface
|
357 |
+
with gr.Blocks(title="Math Mento - Calculus Questions Generator") as demo:
|
358 |
+
gr.Markdown("# Math Mento - Calculus Questions Generator")
|
359 |
+
gr.Markdown("Generate LaTeX-formatted calculus practice questions with solutions based on James Stewart's calculus textbook")
|
360 |
|
361 |
with gr.Row():
|
362 |
with gr.Column():
|
363 |
topic = gr.Dropdown(
|
364 |
choices=list(TOPICS.keys()),
|
365 |
label="Calculus Topic",
|
366 |
+
value="Limits and Continuity"
|
367 |
)
|
368 |
difficulty = gr.Radio(
|
369 |
choices=["easy", "hard"],
|
370 |
+
label="Difficulty",
|
371 |
value="easy"
|
372 |
)
|
373 |
count = gr.Slider(
|
374 |
minimum=1,
|
375 |
maximum=10,
|
|
|
376 |
step=1,
|
377 |
+
value=3,
|
378 |
label="Number of Questions"
|
379 |
)
|
380 |
generate_button = gr.Button("Generate Questions")
|
381 |
+
export_button = gr.Button("Export to JSON")
|
382 |
|
383 |
with gr.Column():
|
384 |
+
output = gr.Markdown()
|
385 |
+
json_file = gr.File(label="Exported JSON")
|
386 |
|
387 |
generate_button.click(
|
388 |
generate_calculus_questions,
|
389 |
inputs=[topic, difficulty, count],
|
390 |
+
outputs=output
|
391 |
+
)
|
392 |
+
|
393 |
+
export_button.click(
|
394 |
+
export_to_json,
|
395 |
+
inputs=[],
|
396 |
+
outputs=json_file
|
397 |
)
|
398 |
|
399 |
+
gr.Markdown("### Created by Kamogelo Mosia | Math Mento © 2025")
|
400 |
|
401 |
# Launch the app
|
402 |
if __name__ == "__main__":
|