Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
def generate_math_content(education_level, math_field, specific_topic, difficulty):
|
8 |
+
# ๋ฌธ์ ์ํ (์ค์ ๊ตฌํ์ ๋ ๋ง์ ๋ฌธ์ ์ถ๊ฐ ํ์)
|
9 |
+
problems = {
|
10 |
+
"์คํ๊ต": {
|
11 |
+
"๋์": {
|
12 |
+
"์ผ์ฐจ๋ฐฉ์ ์": [
|
13 |
+
{
|
14 |
+
"basic": "x + 5 = 12 ๋ฅผ ํ์ด๋ณด์ธ์.",
|
15 |
+
"medium": "2x + 7 = 15 ๋ฅผ ํ์ด๋ณด์ธ์.",
|
16 |
+
"advanced": "3x + 4 = 2x - 8 ์ ํ์ด๋ณด์ธ์."
|
17 |
+
}
|
18 |
+
]
|
19 |
+
},
|
20 |
+
"๊ธฐํ": {
|
21 |
+
"์ผ๊ฐํ": [
|
22 |
+
{
|
23 |
+
"basic": "๋ฐ๋ณ์ด 6cm, ๋์ด๊ฐ 4cm์ธ ์ผ๊ฐํ์ ๋์ด๋ฅผ ๊ตฌํ์ธ์.",
|
24 |
+
"medium": "์ธ ๋ณ์ ๊ธธ์ด๊ฐ 3, 4, 5์ธ ์ผ๊ฐํ์ ๋์ด๋ฅผ ๊ตฌํ์ธ์.",
|
25 |
+
"advanced": "๋ ๋ณ์ ๊ธธ์ด๊ฐ 5cm, 8cm์ด๊ณ ๊ทธ ์ฌ์ด๊ฐ์ด 60ยฐ์ธ ์ผ๊ฐํ์ ๋์ด๋ฅผ ๊ตฌํ์ธ์."
|
26 |
+
}
|
27 |
+
]
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
# ํด์ค ์์ฑ
|
32 |
+
def create_explanation():
|
33 |
+
explanations = {
|
34 |
+
"basic": "๊ธฐ๋ณธ ๊ฐ๋
์ ์ด์ฉํ ๋จ๊ณ๋ณ ํ์ด:\n1. ์ฃผ์ด์ง ์์ ํ์ธํฉ๋๋ค.\n2. ๊ธฐ๋ณธ ์ฐ์ฐ์ ์ํํฉ๋๋ค.\n3. ๊ฒฐ๊ณผ๋ฅผ ๊ฒ์ฆํฉ๋๋ค.",
|
35 |
+
"medium": "์ค๊ธ ๋์ด๋ ํ์ด ์ ๋ต:\n1. ๋ฌธ์ ๋ถ์\n2. ์ ์ฉํ ๊ณต์ ์ ํ\n3. ๊ณ์ฐ ์ํ\n4. ๊ฒฐ๊ณผ ๊ฒ์ฆ",
|
36 |
+
"advanced": "๊ณ ๊ธ ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ:\n1. ๋ฌธ์ ์ ์กฐ๊ฑด ๋ถ์\n2. ํด๊ฒฐ ์ ๋ต ์๋ฆฝ\n3. ๋จ๊ณ๋ณ ๊ณ์ฐ\n4. ๊ฒฐ๊ณผ์ ํ๋น์ฑ ๊ฒํ "
|
37 |
+
}
|
38 |
+
return explanations[difficulty]
|
39 |
+
# ์๊ฐํ ์์ฑ
|
40 |
+
def create_visualization():
|
41 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
42 |
+
if math_field == "๋์":
|
43 |
+
x = np.linspace(-10, 10, 100)
|
44 |
+
y = x + 5
|
45 |
+
ax.plot(x, y)
|
46 |
+
ax.grid(True)
|
47 |
+
ax.axhline(y=0, color='k')
|
48 |
+
ax.axvline(x=0, color='k')
|
49 |
+
plt.title("์ผ์ฐจ๋ฐฉ์ ์์ ๊ทธ๋ํ")
|
50 |
+
elif math_field == "๊ธฐํ":
|
51 |
+
points = np.array([[0, 0], [6, 0], [3, 4]])
|
52 |
+
triangle = plt.Polygon(points, fill=False)
|
53 |
+
ax.add_patch(triangle)
|
54 |
+
ax.set_xlim(-2, 8)
|
55 |
+
ax.set_ylim(-2, 6)
|
56 |
+
plt.title("์ผ๊ฐํ")
|
57 |
+
buf = io.BytesIO()
|
58 |
+
plt.savefig(buf, format='png')
|
59 |
+
buf.seek(0)
|
60 |
+
return Image.open(buf)
|
61 |
+
# ์ฐ์ต๋ฌธ์ ์์ฑ
|
62 |
+
practice_problems = [
|
63 |
+
"์ฐ์ต๋ฌธ์ 1: ๊ธฐ๋ณธ ๊ฐ๋
ํ์ธ",
|
64 |
+
"์ฐ์ต๋ฌธ์ 2: ์์ฉ๋ ฅ ํ
์คํธ",
|
65 |
+
"์ฐ์ต๋ฌธ์ 3: ์ฌํ ๋ฌธ์ "
|
66 |
+
]
|
67 |
+
# ์๊ฐ์ง๋จ ์ฒดํฌ๋ฆฌ์คํธ
|
68 |
+
checklist = [
|
69 |
+
"โก ํต์ฌ ๊ฐ๋
์ ์ดํดํ๋์?",
|
70 |
+
"โก ๋ฌธ์ ํด๊ฒฐ ๊ณผ์ ์ ์ค๋ช
ํ ์ ์๋์?",
|
71 |
+
"โก ๋น์ทํ ์ ํ์ ๋ฌธ์ ๋ฅผ ํ ์ ์๋์?",
|
72 |
+
"โก ์ค์ํ ์ ์ฉ ์ฌ๋ก๋ฅผ ์๊ฐํ ์ ์๋์?"
|
73 |
+
]
|
74 |
+
problem = problems.get(education_level, {}).get(math_field, {}).get(specific_topic, [{}])[0].get(difficulty, "๋ฌธ์ ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
75 |
+
explanation = create_explanation()
|
76 |
+
visualization = create_visualization()
|
77 |
+
return problem, explanation, visualization, "\n".join(practice_problems), "\n".join(checklist)
|
78 |
+
def create_interface():
|
79 |
+
with gr.Blocks() as demo:
|
80 |
+
with gr.Row():
|
81 |
+
with gr.Column():
|
82 |
+
education_level = gr.Dropdown(
|
83 |
+
choices=["์คํ๊ต", "๊ณ ๋ฑํ๊ต", "๋ํ๊ต"],
|
84 |
+
label="๊ต์ก๊ณผ์ ๋จ๊ณ",
|
85 |
+
value="์คํ๊ต"
|
86 |
+
)
|
87 |
+
math_field = gr.Dropdown(
|
88 |
+
choices=["๋์", "๊ธฐํ", "ํด์ํ"],
|
89 |
+
label="์ํ ์์ญ",
|
90 |
+
value="๋์"
|
91 |
+
)
|
92 |
+
specific_topic = gr.Dropdown(
|
93 |
+
choices=["์ผ์ฐจ๋ฐฉ์ ์", "์ผ๊ฐํ"],
|
94 |
+
label="์ธ๋ถ ์ฃผ์ ",
|
95 |
+
value="์ผ์ฐจ๋ฐฉ์ ์"
|
96 |
+
)
|
97 |
+
difficulty = gr.Dropdown(
|
98 |
+
choices=["basic", "medium", "advanced"],
|
99 |
+
label="๋์ด๋",
|
100 |
+
value="basic"
|
101 |
+
)
|
102 |
+
generate_btn = gr.Button("๋ฌธ์ ์์ฑ")
|
103 |
+
with gr.Column():
|
104 |
+
problem_output = gr.Textbox(label="์์ฑ๋ ๋ฌธ์ ")
|
105 |
+
explanation_output = gr.Textbox(label="์์ธ ํ์ด")
|
106 |
+
visualization_output = gr.Image(label="์๊ฐํ")
|
107 |
+
practice_output = gr.Textbox(label="์ฐ์ต๋ฌธ์ ")
|
108 |
+
checklist_output = gr.Textbox(label="์๊ฐ์ง๋จ ์ฒดํฌ๋ฆฌ์คํธ")
|
109 |
+
generate_btn.click(
|
110 |
+
generate_math_content,
|
111 |
+
inputs=[education_level, math_field, specific_topic, difficulty],
|
112 |
+
outputs=[problem_output, explanation_output, visualization_output, practice_output, checklist_output]
|
113 |
+
)
|
114 |
+
return demo
|
115 |
+
demo = create_interface()
|
116 |
+
|
117 |
+
if __name__ == '__main__':
|
118 |
+
demo.launch()
|