Update app.py
Browse files
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-
|
| 19 |
generation_config=generation_config,
|
| 20 |
)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def generate_evaluation(context):
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
"""
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
##
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
- 상: ...
|
| 34 |
-
- 중: ...
|
| 35 |
-
- 하: ...
|
| 36 |
-
2. 평가 문항 2
|
| 37 |
-
- 상: ...
|
| 38 |
-
- 중: ...
|
| 39 |
-
- 하: ...
|
| 40 |
-
3. 평가 문항 3
|
| 41 |
-
- 상: ...
|
| 42 |
-
- 중: ...
|
| 43 |
-
- 하: ...
|
| 44 |
"""
|
| 45 |
|
| 46 |
-
|
| 47 |
-
return response.text
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
st.
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)}")
|