ll7098ll commited on
Commit
bf63def
ยท
verified ยท
1 Parent(s): 5db5057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -42
app.py CHANGED
@@ -1,10 +1,12 @@
1
  import os
2
  import time
3
-
4
  import google.generativeai as genai
5
- import gradio as gr
 
 
6
 
7
- # Google Gemini API ํ‚ค ์„ค์ •
8
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
9
 
10
  # ๋ชจ๋ธ ์„ค์ •
@@ -21,43 +23,39 @@ model = genai.GenerativeModel(
21
  generation_config=generation_config,
22
  )
23
 
24
- # ํ”„๋กฌํ”„ํŠธ ์„ค์ •
25
- SYSTEM_PROMPT = """
26
- ๋‹น์‹ ์€ ๊ต์ˆ˜ํ•™์Šต ํ™œ๋™ ์„ค๊ณ„ ์ „๋ฌธ๊ฐ€, ๊ต๊ณผ๊ต์œก ๋‚ด์šฉ ์ „๋ฌธ๊ฐ€, ๊ต์œก๊ณตํ•™์ž์ž…๋‹ˆ๋‹ค.
27
- ์„ ์ƒ๋‹˜๋“ค์ด ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ™œ๋™์„ ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”..
28
- ๋‹ค์Œ์€ ํ™œ๋™ ์„ค๊ณ„์— ํ•„์š”ํ•œ ์ •๋ณด์ž…๋‹ˆ๋‹ค.
29
-
30
- **ํ™œ๋™ ๊ตฌ์„ฑ ์š”์†Œ:**
31
- 1. ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ
32
- 2. ํ™œ๋™ ๋ชฉํ‘œ
33
- 3. ํ™œ๋™ ๋‹จ๊ณ„๋ณ„ ์•ˆ๋‚ด
34
- - 1๋‹จ๊ณ„: 1๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
35
- - 2๋‹จ๊ณ„: 2๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
36
- - 3๋‹จ๊ณ„: 3๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
37
- - 4๋‹จ๊ณ„: 4๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด...
38
- 4. ํ™œ๋™ ์ค€๋น„๋ฌผ ๋ฐ ๊ธฐ๊ตฌ
39
- 5. ํ™œ๋™์„ ์œ„ํ•œ ์ž๋ฃŒ
40
- - ํ™œ๋™์— ํ•„์š”ํ•œ ์ž๋ฃŒ
41
- - ์ถ”๊ฐ€ ์ถ”์ฒœ ์ž๋ฃŒ
42
- 6. ํ™œ๋™์˜ ์œ ์˜์ 
43
- - ํ•™์ƒ ์ž…์žฅ ์œ ์˜์ 
44
- - ๊ต์‚ฌ ์ž…์žฅ ์œ ์˜์ 
45
- 7. ํ•™์ƒ์—๊ฒŒ ์ œ๊ณตํ•  ํ™œ๋™ ์•ˆ๋‚ด ์ž๋ฃŒ
46
- * ํ™œ๋™ ์•ˆ๋‚ด ์ž๋ฃŒ๋Š” ์ดˆ๋“ฑํ•™์ƒ์ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก ์ตœ๋Œ€ํ•œ ๊ตฌ์ฒด์ ์ด๊ณ , ๋‹จ๊ณ„์ , ๋ช…์‹œ์ ์œผ๋กœ ์•ˆ๋‚ดํ•ด์ฃผ์„ธ์š”.
47
- """
48
-
49
- def generate_curriculum(achievement_standard):
50
  """
51
  ํ™œ๋™ ์ปจ์…‰์„ ์ž…๋ ฅ๋ฐ›์•„ ํ™œ๋™์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
52
  ์•„์›ƒํ’‹์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
53
-
54
  Args:
55
  achievement_standard (str): ํ™œ๋™ ์ปจ์…‰
56
-
57
  Returns:
58
  str: ์ƒ์„ฑ๋œ ํ™œ๋™
59
  """
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  prompt = [
62
  SYSTEM_PROMPT,
63
  f"**ํ™œ๋™ ์ปจ์…‰:** {achievement_standard}",
@@ -72,17 +70,34 @@ def generate_curriculum(achievement_standard):
72
  yield collected_text # ์‹ค์‹œ๊ฐ„ ์ถœ๋ ฅ์„ ์œ„ํ•ด yield ์‚ฌ์šฉ
73
  time.sleep(0.03) # ์ถœ๋ ฅ ์†๋„ ์กฐ์ ˆ
74
 
75
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
76
- iface = gr.Interface(
77
- fn=generate_curriculum,
78
- inputs=gr.Textbox(lines=3, label="ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ ์ž…๋ ฅ"),
79
- outputs=gr.Textbox(lines=10, label="ํ•™์Šต ํ™œ๋™"),
80
- title="ํ•™์Šต ํ™œ๋™ ์„ค๊ณ„ ๋„์šฐ๋ฏธ",
81
  description="์„ ์ƒ๋‹˜์ด ํ™œ๋™์˜ ์ปจ์…‰์„ ์ž…๋ ฅํ•˜์‹œ๋ฉด ํ™œ๋™์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๊ณ„ํ•ด์ค๋‹ˆ๋‹ค.",
82
- examples=[
83
- ["๊ตญ๊ฒฝ, ์ง€ํ˜•, ์ž์›, ์ธ๊ตฌ์ •๋ณด, ๊ตญ๊ฐ€ ๊ฐ„ ๊ด€๊ณ„๊ฐ€ ํ‘œ์‹œ๋œ ์ง€๋„์™€ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ฃผ๊ณ , ๋‚˜๋ผ ๊ฐ„ ๊ตญ๊ฒฝ์„ ์„ ์ •ํ•˜๋Š” ํ™œ๋™์„ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ๊ฒŒ์ž„ ๋ชจํ˜•์„ ํ™œ์šฉํ•ด ํ•˜๊ณ  ์‹ถ์–ด."],
84
- ]
85
  )
86
 
87
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
88
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import time
3
+ import streamlit as st
4
  import google.generativeai as genai
5
+ from streamlit_extras.colored_header import colored_header
6
+ from streamlit_extras.add_vertical_space import add_vertical_space
7
+ import markdown
8
 
9
+ # Google Gemini API Key ์„ค์ •
10
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
11
 
12
  # ๋ชจ๋ธ ์„ค์ •
 
23
  generation_config=generation_config,
24
  )
25
 
26
+ def generate_lesson_plan(achievement_standard):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  """
28
  ํ™œ๋™ ์ปจ์…‰์„ ์ž…๋ ฅ๋ฐ›์•„ ํ™œ๋™์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
29
  ์•„์›ƒํ’‹์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
 
30
  Args:
31
  achievement_standard (str): ํ™œ๋™ ์ปจ์…‰
 
32
  Returns:
33
  str: ์ƒ์„ฑ๋œ ํ™œ๋™
34
  """
35
 
36
+ SYSTEM_PROMPT = """
37
+ ๋‹น์‹ ์€ ๊ต์ˆ˜ํ•™์Šต ํ™œ๋™ ์„ค๊ณ„ ์ „๋ฌธ๊ฐ€, ๊ต๊ณผ๊ต์œก ๋‚ด์šฉ ์ „๋ฌธ๊ฐ€, ๊ต์œก๊ณตํ•™์ž์ž…๋‹ˆ๋‹ค.
38
+ ์„ ์ƒ๋‹˜๋“ค์ด ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ™œ๋™์„ ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”..
39
+ ๋‹ค์Œ์€ ํ™œ๋™ ์„ค๊ณ„์— ํ•„์š”ํ•œ ์ •๋ณด์ž…๋‹ˆ๋‹ค.
40
+ **ํ™œ๋™ ๊ตฌ์„ฑ ์š”์†Œ:**
41
+ 1. ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ
42
+ 2. ํ™œ๋™ ๋ชฉํ‘œ
43
+ 3. ํ™œ๋™ ๋‹จ๊ณ„๋ณ„ ์•ˆ๋‚ด
44
+ - 1๋‹จ๊ณ„: 1๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
45
+ - 2๋‹จ๊ณ„: 2๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
46
+ - 3๋‹จ๊ณ„: 3๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด
47
+ - 4๋‹จ๊ณ„: 4๋‹จ๊ณ„ ํ™œ๋™ ์•ˆ๋‚ด...
48
+ 4. ํ™œ๋™ ์ค€๋น„๋ฌผ ๋ฐ ๊ธฐ๊ตฌ
49
+ 5. ํ™œ๋™์„ ์œ„ํ•œ ์ž๋ฃŒ
50
+ - ํ™œ๋™์— ํ•„์š”ํ•œ ์ž๋ฃŒ
51
+ - ์ถ”๊ฐ€ ์ถ”์ฒœ ์ž๋ฃŒ
52
+ 6. ํ™œ๋™์˜ ์œ ์˜์ 
53
+ - ํ•™์ƒ ์ž…์žฅ ์œ ์˜์ 
54
+ - ๊ต์‚ฌ ์ž…์žฅ ์œ ์˜์ 
55
+ 7. ํ•™์ƒ์—๊ฒŒ ์ œ๊ณตํ•  ํ™œ๋™ ์•ˆ๋‚ด ์ž๋ฃŒ
56
+ * ํ™œ๋™ ์•ˆ๋‚ด ์ž๋ฃŒ๋Š” ์ดˆ๋“ฑํ•™์ƒ์ด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก ์ตœ๋Œ€ํ•œ ๊ตฌ์ฒด์ ์ด๊ณ , ๋‹จ๊ณ„์ , ๋ช…์‹œ์ ์œผ๋กœ ์•ˆ๋‚ดํ•ด์ฃผ์„ธ์š”.
57
+ """
58
+
59
  prompt = [
60
  SYSTEM_PROMPT,
61
  f"**ํ™œ๋™ ์ปจ์…‰:** {achievement_standard}",
 
70
  yield collected_text # ์‹ค์‹œ๊ฐ„ ์ถœ๋ ฅ์„ ์œ„ํ•ด yield ์‚ฌ์šฉ
71
  time.sleep(0.03) # ์ถœ๋ ฅ ์†๋„ ์กฐ์ ˆ
72
 
73
+ # Streamlit Interface
74
+ colored_header(
75
+ label="ํ•™์Šต ํ™œ๋™ ์„ค๊ณ„ ๋„์šฐ๋ฏธ",
 
 
 
76
  description="์„ ์ƒ๋‹˜์ด ํ™œ๋™์˜ ์ปจ์…‰์„ ์ž…๋ ฅํ•˜์‹œ๋ฉด ํ™œ๋™์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๊ณ„ํ•ด์ค๋‹ˆ๋‹ค.",
77
+ color_name="red-70",
 
 
78
  )
79
 
80
+ add_vertical_space(1)
81
+
82
+ achievement_standard = st.text_area("ํ™œ๋™ ์ปจ์…‰ ๋ฐ ์†Œ๊ฐœ ์ž…๋ ฅ", height=100)
83
+
84
+ generate_button = st.button("ํ•™์Šต ํ™œ๋™ ์ƒ์„ฑ")
85
+
86
+ # ์ถœ๋ ฅ ์˜์—ญ ์ •์˜
87
+ output_area = st.empty()
88
+
89
+ if generate_button and achievement_standard:
90
+ output_text = ""
91
+ output_area.markdown(output_text)
92
+ try:
93
+ for partial_output in generate_lesson_plan(achievement_standard):
94
+ output_text = partial_output
95
+ output_area.markdown(output_text)
96
+ except Exception as e:
97
+ st.error(f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}")
98
+
99
+ # ๋ณต์‚ฌ ๋ฒ„ํŠผ ์ถ”๊ฐ€
100
+ if output_text:
101
+ if st.button("์ถœ๋ ฅ ๋‚ด์šฉ ๋ณต์‚ฌ"):
102
+ st.write(output_text)
103
+ st.success("์ถœ๋ ฅ ๋‚ด์šฉ์ด ๋ณต์‚ฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")