File size: 3,265 Bytes
1d355ad
fabb74d
bf63def
22032f3
bf63def
 
 
1d355ad
bf63def
22032f3
 
fabb74d
 
b05b815
 
1a23725
6c63571
fabb74d
 
 
 
13b59d8
fabb74d
 
 
bf63def
fabb74d
4c541d4
fabb74d
 
4c541d4
fabb74d
4c541d4
fabb74d
217a78d
bf63def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fabb74d
 
4c541d4
 
fabb74d
feb03cf
fabb74d
 
 
 
 
 
 
940b028
bf63def
 
 
4c541d4
bf63def
39688bd
03d0703
bf63def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import time
import streamlit as st
import google.generativeai as genai
from streamlit_extras.colored_header import colored_header
from streamlit_extras.add_vertical_space import add_vertical_space
import markdown

# Google Gemini API Key μ„€μ •
genai.configure(api_key=os.environ["GEMINI_API_KEY"])

# λͺ¨λΈ μ„€μ •
generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 40,
    "max_output_tokens": 8192,
    "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
    model_name="gemini-2.0-flash",
    generation_config=generation_config,
)

def generate_lesson_plan(achievement_standard):
    """
    ν™œλ™ 컨셉을 μž…λ ₯λ°›μ•„ ν™œλ™μ„ μƒμ„±ν•©λ‹ˆλ‹€.
    아웃풋을 μ‹€μ‹œκ°„μœΌλ‘œ 좜λ ₯ν•©λ‹ˆλ‹€.
    Args:
        achievement_standard (str): ν™œλ™ 컨셉
    Returns:
        str: μƒμ„±λœ ν™œλ™
    """

    SYSTEM_PROMPT = """
    당신은 κ΅μˆ˜ν•™μŠ΅ ν™œλ™ 섀계 μ „λ¬Έκ°€, ꡐ과ꡐ윑 λ‚΄μš© μ „λ¬Έκ°€, κ΅μœ‘κ³΅ν•™μžμž…λ‹ˆλ‹€.
    μ„ μƒλ‹˜λ“€μ΄ ν™œλ™ 컨셉 및 μ†Œκ°œλ₯Ό μž…λ ₯ν•˜λ©΄ ν™œλ™μ„ μžμ„Έν•˜κ²Œ μ„€λͺ…ν•΄μ£Όμ„Έμš”.. 
    λ‹€μŒμ€ ν™œλ™ 섀계에 ν•„μš”ν•œ μ •λ³΄μž…λ‹ˆλ‹€.
    **ν™œλ™ ꡬ성 μš”μ†Œ:**
    1. ν™œλ™ 컨셉 및 μ†Œκ°œ
    2. ν™œλ™ λͺ©ν‘œ
    3. ν™œλ™ 단계별 μ•ˆλ‚΄
      - 1단계: 1단계 ν™œλ™ μ•ˆλ‚΄
      - 2단계: 2단계 ν™œλ™ μ•ˆλ‚΄
      - 3단계: 3단계 ν™œλ™ μ•ˆλ‚΄
      - 4단계: 4단계 ν™œλ™ μ•ˆλ‚΄...
    4. ν™œλ™ μ€€λΉ„λ¬Ό 및 기ꡬ
    5. ν™œλ™μ„ μœ„ν•œ 자료
      - ν™œλ™μ— ν•„μš”ν•œ 자료
      - μΆ”κ°€ μΆ”μ²œ 자료
    6. ν™œλ™μ˜ 유의점
      - 학생 μž…μž₯ 유의점
      - ꡐ사 μž…μž₯ 유의점
    7. ν•™μƒμ—κ²Œ μ œκ³΅ν•  ν™œλ™ μ•ˆλ‚΄ 자료
    * ν™œλ™ μ•ˆλ‚΄ μžλ£ŒλŠ” μ΄ˆλ“±ν•™μƒμ΄ 이해할 수 μžˆλ„λ‘ μ΅œλŒ€ν•œ ꡬ체적이고, 단계적, λͺ…μ‹œμ μœΌλ‘œ μ•ˆλ‚΄ν•΄μ£Όμ„Έμš”.
    """

    prompt = [
        SYSTEM_PROMPT,
        f"**ν™œλ™ 컨셉:** {achievement_standard}",
        "**ν™œλ™:**", 
    ]

    response = model.generate_content(prompt, stream=True)
    collected_text = ""
    for token in response:
        chunk = token.text
        collected_text += chunk
        yield collected_text  # μ‹€μ‹œκ°„ 좜λ ₯을 μœ„ν•΄ yield μ‚¬μš©
        time.sleep(0.03)  # 좜λ ₯ 속도 쑰절

# Streamlit Interface
colored_header(
    label="ν•™μŠ΅ ν™œλ™ 섀계 λ„μš°λ―Έ",
    description="μ„ μƒλ‹˜μ΄ ν™œλ™μ˜ 컨셉을 μž…λ ₯ν•˜μ‹œλ©΄ ν™œλ™μ„ ꡬ체적으둜 μ„€κ³„ν•΄μ€λ‹ˆλ‹€.",
    color_name="red-70",
)

add_vertical_space(1)

achievement_standard = st.text_area("ν™œλ™ 컨셉 및 μ†Œκ°œ μž…λ ₯", height=100)

generate_button = st.button("ν•™μŠ΅ ν™œλ™ 생성")

# 좜λ ₯ μ˜μ—­ μ •μ˜
output_area = st.empty()

if generate_button and achievement_standard:
    output_text = ""
    output_area.markdown(output_text)
    try:
        for partial_output in generate_lesson_plan(achievement_standard):
            output_text = partial_output
            output_area.markdown(output_text)
    except Exception as e:
        st.error(f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}")

    # 볡사 λ²„νŠΌ μΆ”κ°€
    if output_text:
        if st.button("좜λ ₯ λ‚΄μš© 볡사"):
            st.write(output_text)
            st.success("좜λ ₯ λ‚΄μš©μ΄ λ³΅μ‚¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€!")