Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from streamlit_extras.add_vertical_space import add_vertical_space
|
|
| 7 |
import markdown
|
| 8 |
import pyperclip
|
| 9 |
|
| 10 |
-
# Google Gemini API 설정
|
| 11 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 12 |
|
| 13 |
# 모델 설정
|
|
@@ -27,16 +27,14 @@ model = genai.GenerativeModel(
|
|
| 27 |
def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
|
| 28 |
prompt = f"""
|
| 29 |
초등학교 {grade}학년 학생이 이해할 수 있는 수준의 설명문을 작성.
|
| 30 |
-
설명문의 주제는 {topic}이며, 주제를 중심으로 {structure} 구조에
|
| 31 |
전체 문단 수는 {num_paragraphs} 문단 내외, 문단 당 문장 수는 {sentences_per_paragraph} 문장 내외.
|
| 32 |
-
설명문은
|
| 33 |
-
문단마다, 문단의 첫 문장 또는 마지막 문장이 문단의 중심 문장이 되도록 할 것. (중심
|
| 34 |
-
초등학교 {grade}학년 수준에
|
| 35 |
"""
|
| 36 |
|
| 37 |
full_text = ""
|
| 38 |
-
text_area = st.empty()
|
| 39 |
-
|
| 40 |
try:
|
| 41 |
response = model.generate_content(prompt, stream=True)
|
| 42 |
for chunk in response:
|
|
@@ -49,7 +47,7 @@ def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, top
|
|
| 49 |
|
| 50 |
# Streamlit 인터페이스 설정
|
| 51 |
colored_header(
|
| 52 |
-
label="
|
| 53 |
description="주제를 입력하면 초등학생이 이해하기 쉬운 읽기 자료를 만들어줍니다.",
|
| 54 |
color_name="red-70",
|
| 55 |
)
|
|
@@ -64,15 +62,17 @@ with st.sidebar:
|
|
| 64 |
structure = st.selectbox("설명문 구조", ["정의와 예시", "비교와 대조", "분류", "분석", "인과", "순서"], index=0)
|
| 65 |
topic = st.text_area("✏️ 주제 및 내용을 입력하세요 ", height=200)
|
| 66 |
|
| 67 |
-
|
| 68 |
if st.button("읽기 자료 생성"):
|
| 69 |
generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic)
|
| 70 |
|
| 71 |
-
#
|
|
|
|
|
|
|
|
|
|
| 72 |
if "generated_curriculum" in st.session_state and st.session_state.generated_curriculum:
|
| 73 |
html_text = markdown.markdown(st.session_state.generated_curriculum, extensions=['tables'])
|
| 74 |
st.markdown(html_text, unsafe_allow_html=True)
|
| 75 |
|
| 76 |
if st.button("출력 내용 복사", key="copy_button"):
|
| 77 |
pyperclip.copy(st.session_state.generated_curriculum)
|
| 78 |
-
st.success("복사되었습니다!")
|
|
|
|
| 7 |
import markdown
|
| 8 |
import pyperclip
|
| 9 |
|
| 10 |
+
# Google Gemini API 값 설정
|
| 11 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 12 |
|
| 13 |
# 모델 설정
|
|
|
|
| 27 |
def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
|
| 28 |
prompt = f"""
|
| 29 |
초등학교 {grade}학년 학생이 이해할 수 있는 수준의 설명문을 작성.
|
| 30 |
+
설명문의 주제는 {topic}이며, 주제를 중심으로 {structure} 구조에 따른 설명문을 작성할 것.
|
| 31 |
전체 문단 수는 {num_paragraphs} 문단 내외, 문단 당 문장 수는 {sentences_per_paragraph} 문장 내외.
|
| 32 |
+
설명문은 줄까만으로 작성하고 문단 구분을 꿀 할 것. 지정된 문단 수와 문단 당 문장 수를 꿀 지키기.
|
| 33 |
+
문단마다, 문단의 첫 문장 또는 마지막 문장이 문단의 중심 문장이 되도록 할 것. (중심 문장이라는 문단의 내용을 모두 포함할 수 있는 문장)
|
| 34 |
+
초등학교 {grade}학년 수준에 어렵은 단어와 한자어, 학습 도구어는 마지막에 어희 목록과 어희의 뜻을 초등학교 {grade}학년 수준에 맞게 유의언으로 또는 뜻을 풀어 설명하는 부분 따로 추가할 것.
|
| 35 |
"""
|
| 36 |
|
| 37 |
full_text = ""
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
response = model.generate_content(prompt, stream=True)
|
| 40 |
for chunk in response:
|
|
|
|
| 47 |
|
| 48 |
# Streamlit 인터페이스 설정
|
| 49 |
colored_header(
|
| 50 |
+
label="📜 초등학생을 위한 읽기 자료 생성기",
|
| 51 |
description="주제를 입력하면 초등학생이 이해하기 쉬운 읽기 자료를 만들어줍니다.",
|
| 52 |
color_name="red-70",
|
| 53 |
)
|
|
|
|
| 62 |
structure = st.selectbox("설명문 구조", ["정의와 예시", "비교와 대조", "분류", "분석", "인과", "순서"], index=0)
|
| 63 |
topic = st.text_area("✏️ 주제 및 내용을 입력하세요 ", height=200)
|
| 64 |
|
|
|
|
| 65 |
if st.button("읽기 자료 생성"):
|
| 66 |
generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic)
|
| 67 |
|
| 68 |
+
# Streamlit UI에 대한 장소의 text_area 출력 설정
|
| 69 |
+
text_area = st.empty()
|
| 70 |
+
|
| 71 |
+
# 보상 버튼 추가 (이미 생성된 경우)
|
| 72 |
if "generated_curriculum" in st.session_state and st.session_state.generated_curriculum:
|
| 73 |
html_text = markdown.markdown(st.session_state.generated_curriculum, extensions=['tables'])
|
| 74 |
st.markdown(html_text, unsafe_allow_html=True)
|
| 75 |
|
| 76 |
if st.button("출력 내용 복사", key="copy_button"):
|
| 77 |
pyperclip.copy(st.session_state.generated_curriculum)
|
| 78 |
+
st.success("복사되었습니다!")
|