ll7098ll commited on
Commit
9a8f27f
·
verified ·
1 Parent(s): 2abc70f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -36
app.py CHANGED
@@ -1,8 +1,12 @@
1
  import os
 
2
  import streamlit as st
3
  import google.generativeai as genai
 
 
 
4
 
5
- # Gemini API 설정
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
8
  # 모델 설정
@@ -15,51 +19,65 @@ generation_config = {
15
  }
16
 
17
  model = genai.GenerativeModel(
18
- model_name="gemini-1.5-flash-002",
19
  generation_config=generation_config,
20
  )
21
 
22
-
23
- def generate_evaluation(context):
24
  """
25
- 학습 목표를 입력받아 서술형 평가 문항과 평가 기준을 생성하는 함수
26
  """
27
-
28
- prompt = f"""평가 전문가, 학습 목표를 입력하면 아래와 같은 서술형 평가 문항 3개와 각각의 문항에 대한 평가 기준(상, 중, 하)을 작성해줘. 문항과 평가 기준은 초등학교 교육과정에 맞게 작성하도록 해.
29
- ## 서술형 평가 예시
30
- input: {context}
31
- output:
32
- 1. 평가 문항 1
33
- - 상: ...
34
- - 중: ...
35
- - 하: ...
36
- 2. 평가 문항 2
37
- - 상: ...
38
- - 중: ...
39
- - 하: ...
40
- 3. 평가 문항 3
41
- - 상: ...
42
- - 중: ...
43
- - 하: ...
44
  """
45
 
46
- response = model.generate_content([prompt])
47
- return response.text
48
 
 
 
 
 
 
 
 
 
49
 
50
- # Streamlit 제목
51
- st.title("📝 서술형 평가 문항 생성기")
52
- st.write("학습 목표를 입력하면 관련된 서술형 평가 문항과 평가 기준(상/중/하)을 생성해줍니다.")
53
 
54
- # 입력 텍스트 박스
55
- context = st.text_area(
56
- "학습 목표를 자유롭게 입력하세요.", height=70
 
 
 
 
57
  )
58
 
59
- # 평가 문항 생성 버튼
60
- if st.button("평가 문항 생성"):
61
- # 평가 문항 생성 함수 호출
62
- evaluation = generate_evaluation(context)
 
 
 
 
 
 
 
 
 
63
 
64
- # 생성된 평가 문항 출력
65
- st.text_area("생성된 평가 문항과 평가 기준", evaluation, height=400)
 
 
 
 
 
 
 
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
  # 모델 설정
 
19
  }
20
 
21
  model = genai.GenerativeModel(
22
+ model_name="gemini-1.5-pro-002",
23
  generation_config=generation_config,
24
  )
25
 
26
+ def generate_evaluation_questions(learning_goal):
 
27
  """
28
+ Generates 2-3 descriptive evaluation questions and grading criteria for the given learning goal.
29
  """
30
+ prompt = f"""교육평가 전문가로서 다음 학습 목표를 참고하여 서술형 평가 문항을 2~3개 작성하고, 각 평가 문항에 대한 평가기준을 상, 중, 하로 제시해줘.
31
+
32
+ ## 학습 목표
33
+ * {learning_goal}
34
+
35
+ ## 서술형 평가 문항 및 평가기준
 
 
 
 
 
 
 
 
 
 
 
36
  """
37
 
38
+ full_text = "" # 초기 빈 텍스트 출력
 
39
 
40
+ try:
41
+ response = model.generate_content([prompt], stream=True)
42
+ for chunk in response:
43
+ full_text += chunk.text
44
+ # Convert markdown to HTML for display
45
+ html_text = markdown.markdown(full_text, extensions=['tables'])
46
+ evaluation_output_area.markdown(html_text, unsafe_allow_html=True)
47
+ time.sleep(0.05)
48
 
49
+ except Exception as e:
50
+ st.error(f"Error: {str(e)}")
51
+ return ""
52
 
53
+ return full_text
54
+
55
+ # Streamlit Interface
56
+ colored_header(
57
+ label="서술형 평가 문항 생성",
58
+ description="학습 목표에 맞는 서술형 평가 문항과 평가 기준을 생성하세요!",
59
+ color_name="blue-70",
60
  )
61
 
62
+ add_vertical_space(1)
63
+
64
+ with st.sidebar.expander("입력 설정", expanded=True):
65
+ learning_goal = st.text_input("학습 목표")
66
+
67
+ generate_evaluation_button = st.button("서술형 평가 문항 생성")
68
+
69
+ # 출력 영역 정의
70
+ evaluation_output_area = st.empty()
71
+
72
+ if generate_evaluation_button:
73
+ evaluation_result = generate_evaluation_questions(learning_goal)
74
+ st.session_state.generated_evaluation = evaluation_result
75
 
76
+ # 복사 버튼 추가
77
+ if evaluation_result:
78
+ if st.button("평가 문항 복사"):
79
+ try:
80
+ st.experimental_set_query_params(copied_text=evaluation_result)
81
+ st.success("평가 문항이 복사되었습니다!")
82
+ except Exception as e:
83
+ st.error(f"복사 중 오류가 발생했습니다: {str(e)}")