| 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.launch() |