essaytest / app.py
ll7098ll's picture
Update app.py
dc2e4a1 verified
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_evaluation_questions(learning_goal):
"""
Generates 2-3 descriptive evaluation questions and grading criteria for the given learning goal.
"""
prompt = f"""교육평가 전문가로서 다음 학습 목표를 참고하여 초등학교 교육과정 수준에 맞는 서술형 평가 문항을 2~3개 작성하고, 각 평가 문항에 대한 평가기준을 상, 중, 하로 제시해줘.
각 문항은 학습 목표를 정확히 평가할 수 있는 질문으로 구성하고, 평가 기준은 다음과 같이 구체적으로 작성해:
- 상: 학생이 학습 목표를 완전히 이해하고, 깊이 있는 사고와 구체적인 예시를 통해 명확하게 설명할 수 있는 경우
- 중: 학생이 학습 목표를 대부분 이해하고, 기본적인 개념을 설명할 수 있으나 예시나 설명이 다소 부족한 경우
- 하: 학생이 학습 목표를 부분적으로만 이해하고, 기본적인 설명에도 어려움을 겪는 경우
## 학습 목표
* {learning_goal}
## 서술형 평가 문항 및 평가기준
"""
full_text = "" # 초기 빈 텍스트 출력
try:
response = model.generate_content([prompt], stream=True)
for chunk in response:
full_text += chunk.text
# Convert markdown to HTML for display
html_text = markdown.markdown(full_text, extensions=['tables'])
evaluation_output_area.markdown(html_text, unsafe_allow_html=True)
time.sleep(0.05)
except Exception as e:
st.error(f"Error: {str(e)}")
return ""
return full_text
# Streamlit Interface
colored_header(
label="서술형 평가 문항 생성",
description="학습 목표에 맞는 서술형 평가 문항과 평가 기준을 생성하세요!",
color_name="blue-70",
)
add_vertical_space(1)
with st.sidebar.expander("입력 설정", expanded=True):
learning_goal = st.text_input("학습 목표")
generate_evaluation_button = st.button("서술형 평가 문항 생성")
# 출력 영역 정의
evaluation_output_area = st.empty()
if generate_evaluation_button:
evaluation_result = generate_evaluation_questions(learning_goal)
st.session_state.generated_evaluation = evaluation_result
# 복사 버튼 추가
if evaluation_result:
if st.button("평가 문항 복사"):
try:
st.experimental_set_query_params(copied_text=evaluation_result)
st.success("평가 문항이 복사되었습니다!")
except Exception as e:
st.error(f"복사 중 오류가 발생했습니다: {str(e)}")