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